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