xref: /linux/fs/xfs/libxfs/xfs_attr.h (revision 2ac131df03d4f06bb0d825335663cc5064421993)
1508578f2SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
2e2421f0bSAllison Henderson /*
3e2421f0bSAllison Henderson  * Copyright (c) 2000,2002-2003,2005 Silicon Graphics, Inc.
4e2421f0bSAllison Henderson  * All Rights Reserved.
5e2421f0bSAllison Henderson  */
6e2421f0bSAllison Henderson #ifndef __XFS_ATTR_H__
7e2421f0bSAllison Henderson #define	__XFS_ATTR_H__
8e2421f0bSAllison Henderson 
9e2421f0bSAllison Henderson struct xfs_inode;
10e2421f0bSAllison Henderson struct xfs_da_args;
11e2421f0bSAllison Henderson struct xfs_attr_list_context;
12e2421f0bSAllison Henderson 
13e2421f0bSAllison Henderson /*
14e2421f0bSAllison Henderson  * Large attribute lists are structured around Btrees where all the data
15e2421f0bSAllison Henderson  * elements are in the leaf nodes.  Attribute names are hashed into an int,
16e2421f0bSAllison Henderson  * then that int is used as the index into the Btree.  Since the hashval
17e2421f0bSAllison Henderson  * of an attribute name may not be unique, we may have duplicate keys.
18e2421f0bSAllison Henderson  * The internal links in the Btree are logical block offsets into the file.
19e2421f0bSAllison Henderson  *
20e2421f0bSAllison Henderson  * Small attribute lists use a different format and are packed as tightly
21e2421f0bSAllison Henderson  * as possible so as to fit into the literal area of the inode.
22e2421f0bSAllison Henderson  */
23e2421f0bSAllison Henderson 
24e2421f0bSAllison Henderson /*
25e2421f0bSAllison Henderson  * The maximum size (into the kernel or returned from the kernel) of an
26e2421f0bSAllison Henderson  * attribute value or the buffer used for an attr_list() call.  Larger
27e2421f0bSAllison Henderson  * sizes will result in an ERANGE return code.
28e2421f0bSAllison Henderson  */
29e2421f0bSAllison Henderson #define	ATTR_MAX_VALUELEN	(64*1024)	/* max length of a value */
30e2421f0bSAllison Henderson 
31e2421f0bSAllison Henderson /*
32e2421f0bSAllison Henderson  * Kernel-internal version of the attrlist cursor.
33e2421f0bSAllison Henderson  */
34e3a19cdeSChristoph Hellwig struct xfs_attrlist_cursor_kern {
35e2421f0bSAllison Henderson 	__u32	hashval;	/* hash value of next entry to add */
36e2421f0bSAllison Henderson 	__u32	blkno;		/* block containing entry (suggestion) */
37e2421f0bSAllison Henderson 	__u32	offset;		/* offset in list of equal-hashvals */
38e2421f0bSAllison Henderson 	__u16	pad1;		/* padding to match user-level */
39e2421f0bSAllison Henderson 	__u8	pad2;		/* padding to match user-level */
40e2421f0bSAllison Henderson 	__u8	initted;	/* T/F: cursor has been initialized */
41e3a19cdeSChristoph Hellwig };
42e2421f0bSAllison Henderson 
43e2421f0bSAllison Henderson 
44e2421f0bSAllison Henderson /*========================================================================
45e2421f0bSAllison Henderson  * Structure used to pass context around among the routines.
46e2421f0bSAllison Henderson  *========================================================================*/
47e2421f0bSAllison Henderson 
48e2421f0bSAllison Henderson 
49e2421f0bSAllison Henderson /* void; state communicated via *context */
50e2421f0bSAllison Henderson typedef void (*put_listent_func_t)(struct xfs_attr_list_context *, int,
51e2421f0bSAllison Henderson 			      unsigned char *, int, int);
52e2421f0bSAllison Henderson 
53a9c8c69bSChristoph Hellwig struct xfs_attr_list_context {
54e2421f0bSAllison Henderson 	struct xfs_trans	*tp;
55e2421f0bSAllison Henderson 	struct xfs_inode	*dp;		/* inode */
56e3a19cdeSChristoph Hellwig 	struct xfs_attrlist_cursor_kern cursor;	/* position in list */
57a9c8c69bSChristoph Hellwig 	void			*buffer;	/* output buffer */
582c3b83d7SDarrick J. Wong 
592c3b83d7SDarrick J. Wong 	/*
602c3b83d7SDarrick J. Wong 	 * Abort attribute list iteration if non-zero.  Can be used to pass
612c3b83d7SDarrick J. Wong 	 * error values to the xfs_attr_list caller.
622c3b83d7SDarrick J. Wong 	 */
632c3b83d7SDarrick J. Wong 	int			seen_enough;
645e813574SChristoph Hellwig 	bool			allow_incomplete;
652c3b83d7SDarrick J. Wong 
66e2421f0bSAllison Henderson 	ssize_t			count;		/* num used entries */
67e2421f0bSAllison Henderson 	int			dupcnt;		/* count dup hashvals seen */
68e2421f0bSAllison Henderson 	int			bufsize;	/* total buffer size */
69e2421f0bSAllison Henderson 	int			firstu;		/* first used byte in buffer */
70d5f0f49aSChristoph Hellwig 	unsigned int		attr_filter;	/* XFS_ATTR_{ROOT,SECURE} */
71e2421f0bSAllison Henderson 	int			resynch;	/* T/F: resynch with cursor */
72e2421f0bSAllison Henderson 	put_listent_func_t	put_listent;	/* list output fmt function */
73e2421f0bSAllison Henderson 	int			index;		/* index into output buffer */
74a9c8c69bSChristoph Hellwig };
75e2421f0bSAllison Henderson 
76e2421f0bSAllison Henderson 
77e2421f0bSAllison Henderson /*========================================================================
78e2421f0bSAllison Henderson  * Function prototypes for the kernel.
79e2421f0bSAllison Henderson  *========================================================================*/
80e2421f0bSAllison Henderson 
81e2421f0bSAllison Henderson /*
82e2421f0bSAllison Henderson  * Overall external interface routines.
83e2421f0bSAllison Henderson  */
84e2421f0bSAllison Henderson int xfs_attr_inactive(struct xfs_inode *dp);
8517e1dd83SChristoph Hellwig int xfs_attr_list_ilocked(struct xfs_attr_list_context *);
8617e1dd83SChristoph Hellwig int xfs_attr_list(struct xfs_attr_list_context *);
87e2421f0bSAllison Henderson int xfs_inode_hasattr(struct xfs_inode *ip);
88*2ac131dfSChristoph Hellwig bool xfs_attr_is_leaf(struct xfs_inode *ip);
89c36f533fSChristoph Hellwig int xfs_attr_get_ilocked(struct xfs_da_args *args);
90e5171d7eSChristoph Hellwig int xfs_attr_get(struct xfs_da_args *args);
91a2544622SChristoph Hellwig int xfs_attr_set(struct xfs_da_args *args);
92710d707dSDarrick J. Wong int xfs_attr_set_args(struct xfs_da_args *args);
9307120f1aSAllison Collins int xfs_has_attr(struct xfs_da_args *args);
94068f985aSAllison Henderson int xfs_attr_remove_args(struct xfs_da_args *args);
9565480536SDarrick J. Wong bool xfs_attr_namecheck(const void *name, size_t length);
96e2421f0bSAllison Henderson 
97e2421f0bSAllison Henderson #endif	/* __XFS_ATTR_H__ */
98