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