1e2421f0bSAllison Henderson // 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 * External interfaces 26e2421f0bSAllison Henderson *========================================================================*/ 27e2421f0bSAllison Henderson 28e2421f0bSAllison Henderson 29953aa9d1SChristoph Hellwig #define ATTR_DONTFOLLOW 0x0001 /* -- ignored, from IRIX -- */ 30e2421f0bSAllison Henderson #define ATTR_ROOT 0x0002 /* use attrs in root (trusted) namespace */ 31e2421f0bSAllison Henderson #define ATTR_TRUST 0x0004 /* -- unused, from IRIX -- */ 32e2421f0bSAllison Henderson #define ATTR_SECURE 0x0008 /* use attrs in security namespace */ 33e2421f0bSAllison Henderson #define ATTR_CREATE 0x0010 /* pure create: fail if attr already exists */ 34e2421f0bSAllison Henderson #define ATTR_REPLACE 0x0020 /* pure set: fail if attr does not exist */ 35e2421f0bSAllison Henderson 36e2421f0bSAllison Henderson #define XFS_ATTR_FLAGS \ 37e2421f0bSAllison Henderson { ATTR_DONTFOLLOW, "DONTFOLLOW" }, \ 38e2421f0bSAllison Henderson { ATTR_ROOT, "ROOT" }, \ 39e2421f0bSAllison Henderson { ATTR_TRUST, "TRUST" }, \ 40e2421f0bSAllison Henderson { ATTR_SECURE, "SECURE" }, \ 41e2421f0bSAllison Henderson { ATTR_CREATE, "CREATE" }, \ 421d733019SChristoph Hellwig { ATTR_REPLACE, "REPLACE" } 43e2421f0bSAllison Henderson 44e2421f0bSAllison Henderson /* 45e2421f0bSAllison Henderson * The maximum size (into the kernel or returned from the kernel) of an 46e2421f0bSAllison Henderson * attribute value or the buffer used for an attr_list() call. Larger 47e2421f0bSAllison Henderson * sizes will result in an ERANGE return code. 48e2421f0bSAllison Henderson */ 49e2421f0bSAllison Henderson #define ATTR_MAX_VALUELEN (64*1024) /* max length of a value */ 50e2421f0bSAllison Henderson 51e2421f0bSAllison Henderson /* 52e2421f0bSAllison Henderson * Define how lists of attribute names are returned to the user from 53e2421f0bSAllison Henderson * the attr_list() call. A large, 32bit aligned, buffer is passed in 54e2421f0bSAllison Henderson * along with its size. We put an array of offsets at the top that each 55e2421f0bSAllison Henderson * reference an attrlist_ent_t and pack the attrlist_ent_t's at the bottom. 56e2421f0bSAllison Henderson */ 57e2421f0bSAllison Henderson typedef struct attrlist { 58e2421f0bSAllison Henderson __s32 al_count; /* number of entries in attrlist */ 59e2421f0bSAllison Henderson __s32 al_more; /* T/F: more attrs (do call again) */ 60e2421f0bSAllison Henderson __s32 al_offset[1]; /* byte offsets of attrs [var-sized] */ 61e2421f0bSAllison Henderson } attrlist_t; 62e2421f0bSAllison Henderson 63e2421f0bSAllison Henderson /* 64e2421f0bSAllison Henderson * Show the interesting info about one attribute. This is what the 65e2421f0bSAllison Henderson * al_offset[i] entry points to. 66e2421f0bSAllison Henderson */ 67e2421f0bSAllison Henderson typedef struct attrlist_ent { /* data from attr_list() */ 68e2421f0bSAllison Henderson __u32 a_valuelen; /* number bytes in value of attr */ 69e2421f0bSAllison Henderson char a_name[1]; /* attr name (NULL terminated) */ 70e2421f0bSAllison Henderson } attrlist_ent_t; 71e2421f0bSAllison Henderson 72e2421f0bSAllison Henderson /* 73e2421f0bSAllison Henderson * Given a pointer to the (char*) buffer containing the attr_list() result, 74e2421f0bSAllison Henderson * and an index, return a pointer to the indicated attribute in the buffer. 75e2421f0bSAllison Henderson */ 76e2421f0bSAllison Henderson #define ATTR_ENTRY(buffer, index) \ 77e2421f0bSAllison Henderson ((attrlist_ent_t *) \ 78e2421f0bSAllison Henderson &((char *)buffer)[ ((attrlist_t *)(buffer))->al_offset[index] ]) 79e2421f0bSAllison Henderson 80e2421f0bSAllison Henderson /* 81e2421f0bSAllison Henderson * Kernel-internal version of the attrlist cursor. 82e2421f0bSAllison Henderson */ 83e2421f0bSAllison Henderson typedef struct attrlist_cursor_kern { 84e2421f0bSAllison Henderson __u32 hashval; /* hash value of next entry to add */ 85e2421f0bSAllison Henderson __u32 blkno; /* block containing entry (suggestion) */ 86e2421f0bSAllison Henderson __u32 offset; /* offset in list of equal-hashvals */ 87e2421f0bSAllison Henderson __u16 pad1; /* padding to match user-level */ 88e2421f0bSAllison Henderson __u8 pad2; /* padding to match user-level */ 89e2421f0bSAllison Henderson __u8 initted; /* T/F: cursor has been initialized */ 90e2421f0bSAllison Henderson } attrlist_cursor_kern_t; 91e2421f0bSAllison Henderson 92e2421f0bSAllison Henderson 93e2421f0bSAllison Henderson /*======================================================================== 94e2421f0bSAllison Henderson * Structure used to pass context around among the routines. 95e2421f0bSAllison Henderson *========================================================================*/ 96e2421f0bSAllison Henderson 97e2421f0bSAllison Henderson 98e2421f0bSAllison Henderson /* void; state communicated via *context */ 99e2421f0bSAllison Henderson typedef void (*put_listent_func_t)(struct xfs_attr_list_context *, int, 100e2421f0bSAllison Henderson unsigned char *, int, int); 101e2421f0bSAllison Henderson 102*a9c8c69bSChristoph Hellwig struct xfs_attr_list_context { 103e2421f0bSAllison Henderson struct xfs_trans *tp; 104e2421f0bSAllison Henderson struct xfs_inode *dp; /* inode */ 105e2421f0bSAllison Henderson struct attrlist_cursor_kern *cursor; /* position in list */ 106*a9c8c69bSChristoph Hellwig void *buffer; /* output buffer */ 1072c3b83d7SDarrick J. Wong 1082c3b83d7SDarrick J. Wong /* 1092c3b83d7SDarrick J. Wong * Abort attribute list iteration if non-zero. Can be used to pass 1102c3b83d7SDarrick J. Wong * error values to the xfs_attr_list caller. 1112c3b83d7SDarrick J. Wong */ 1122c3b83d7SDarrick J. Wong int seen_enough; 1135e813574SChristoph Hellwig bool allow_incomplete; 1142c3b83d7SDarrick J. Wong 115e2421f0bSAllison Henderson ssize_t count; /* num used entries */ 116e2421f0bSAllison Henderson int dupcnt; /* count dup hashvals seen */ 117e2421f0bSAllison Henderson int bufsize; /* total buffer size */ 118e2421f0bSAllison Henderson int firstu; /* first used byte in buffer */ 119e2421f0bSAllison Henderson int flags; /* from VOP call */ 120e2421f0bSAllison Henderson int resynch; /* T/F: resynch with cursor */ 121e2421f0bSAllison Henderson put_listent_func_t put_listent; /* list output fmt function */ 122e2421f0bSAllison Henderson int index; /* index into output buffer */ 123*a9c8c69bSChristoph Hellwig }; 124e2421f0bSAllison Henderson 125e2421f0bSAllison Henderson 126e2421f0bSAllison Henderson /*======================================================================== 127e2421f0bSAllison Henderson * Function prototypes for the kernel. 128e2421f0bSAllison Henderson *========================================================================*/ 129e2421f0bSAllison Henderson 130e2421f0bSAllison Henderson /* 131e2421f0bSAllison Henderson * Overall external interface routines. 132e2421f0bSAllison Henderson */ 133e2421f0bSAllison Henderson int xfs_attr_inactive(struct xfs_inode *dp); 134e2421f0bSAllison Henderson int xfs_attr_list_int_ilocked(struct xfs_attr_list_context *); 135e2421f0bSAllison Henderson int xfs_attr_list_int(struct xfs_attr_list_context *); 136e2421f0bSAllison Henderson int xfs_inode_hasattr(struct xfs_inode *ip); 137c36f533fSChristoph Hellwig int xfs_attr_get_ilocked(struct xfs_da_args *args); 138e5171d7eSChristoph Hellwig int xfs_attr_get(struct xfs_da_args *args); 139a2544622SChristoph Hellwig int xfs_attr_set(struct xfs_da_args *args); 140710d707dSDarrick J. Wong int xfs_attr_set_args(struct xfs_da_args *args); 141068f985aSAllison Henderson int xfs_attr_remove_args(struct xfs_da_args *args); 142e2421f0bSAllison Henderson int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize, 143e2421f0bSAllison Henderson int flags, struct attrlist_cursor_kern *cursor); 14465480536SDarrick J. Wong bool xfs_attr_namecheck(const void *name, size_t length); 145e2421f0bSAllison Henderson 146e2421f0bSAllison Henderson #endif /* __XFS_ATTR_H__ */ 147