Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000,2002-2003,2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 9 | * This program is distributed in the hope that it would be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | #ifndef __XFS_ATTR_H__ |
| 19 | #define __XFS_ATTR_H__ |
| 20 | |
| 21 | /* |
| 22 | * xfs_attr.h |
| 23 | * |
| 24 | * Large attribute lists are structured around Btrees where all the data |
| 25 | * elements are in the leaf nodes. Attribute names are hashed into an int, |
| 26 | * then that int is used as the index into the Btree. Since the hashval |
| 27 | * of an attribute name may not be unique, we may have duplicate keys. |
| 28 | * The internal links in the Btree are logical block offsets into the file. |
| 29 | * |
| 30 | * Small attribute lists use a different format and are packed as tightly |
| 31 | * as possible so as to fit into the literal area of the inode. |
| 32 | */ |
| 33 | |
| 34 | /*======================================================================== |
| 35 | * External interfaces |
| 36 | *========================================================================*/ |
| 37 | |
| 38 | struct cred; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 39 | struct bhv_vnode; |
Tim Shimmin | 726801b | 2006-09-28 11:01:37 +1000 | [diff] [blame] | 40 | struct xfs_attr_list_context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 42 | typedef int (*attrset_t)(struct bhv_vnode *, char *, void *, size_t, int); |
| 43 | typedef int (*attrget_t)(struct bhv_vnode *, char *, void *, size_t, int); |
| 44 | typedef int (*attrremove_t)(struct bhv_vnode *, char *, int); |
| 45 | typedef int (*attrexists_t)(struct bhv_vnode *); |
| 46 | typedef int (*attrcapable_t)(struct bhv_vnode *, struct cred *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | typedef struct attrnames { |
| 49 | char * attr_name; |
| 50 | unsigned int attr_namelen; |
| 51 | unsigned int attr_flag; |
| 52 | attrget_t attr_get; |
| 53 | attrset_t attr_set; |
| 54 | attrremove_t attr_remove; |
| 55 | attrexists_t attr_exists; |
| 56 | attrcapable_t attr_capable; |
| 57 | } attrnames_t; |
| 58 | |
| 59 | #define ATTR_NAMECOUNT 4 |
| 60 | extern struct attrnames attr_user; |
| 61 | extern struct attrnames attr_secure; |
| 62 | extern struct attrnames attr_system; |
| 63 | extern struct attrnames attr_trusted; |
| 64 | extern struct attrnames *attr_namespaces[ATTR_NAMECOUNT]; |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | extern attrnames_t *attr_lookup_namespace(char *, attrnames_t **, int); |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 67 | extern int attr_generic_list(struct bhv_vnode *, void *, size_t, int, ssize_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #define ATTR_DONTFOLLOW 0x0001 /* -- unused, from IRIX -- */ |
| 70 | #define ATTR_ROOT 0x0002 /* use attrs in root (trusted) namespace */ |
| 71 | #define ATTR_TRUST 0x0004 /* -- unused, from IRIX -- */ |
| 72 | #define ATTR_SECURE 0x0008 /* use attrs in security namespace */ |
| 73 | #define ATTR_CREATE 0x0010 /* pure create: fail if attr already exists */ |
| 74 | #define ATTR_REPLACE 0x0020 /* pure set: fail if attr does not exist */ |
| 75 | #define ATTR_SYSTEM 0x0100 /* use attrs in system (pseudo) namespace */ |
| 76 | |
| 77 | #define ATTR_KERNACCESS 0x0400 /* [kernel] iaccess, inode held io-locked */ |
| 78 | #define ATTR_KERNOTIME 0x1000 /* [kernel] don't update inode timestamps */ |
| 79 | #define ATTR_KERNOVAL 0x2000 /* [kernel] get attr size only, not value */ |
| 80 | #define ATTR_KERNAMELS 0x4000 /* [kernel] list attr names (simple list) */ |
| 81 | |
| 82 | #define ATTR_KERNORMALS 0x0800 /* [kernel] normal attr list: user+secure */ |
| 83 | #define ATTR_KERNROOTLS 0x8000 /* [kernel] include root in the attr list */ |
| 84 | #define ATTR_KERNFULLS (ATTR_KERNORMALS|ATTR_KERNROOTLS) |
| 85 | |
| 86 | /* |
| 87 | * The maximum size (into the kernel or returned from the kernel) of an |
| 88 | * attribute value or the buffer used for an attr_list() call. Larger |
| 89 | * sizes will result in an ERANGE return code. |
| 90 | */ |
| 91 | #define ATTR_MAX_VALUELEN (64*1024) /* max length of a value */ |
| 92 | |
| 93 | /* |
| 94 | * Define how lists of attribute names are returned to the user from |
| 95 | * the attr_list() call. A large, 32bit aligned, buffer is passed in |
| 96 | * along with its size. We put an array of offsets at the top that each |
| 97 | * reference an attrlist_ent_t and pack the attrlist_ent_t's at the bottom. |
| 98 | */ |
| 99 | typedef struct attrlist { |
| 100 | __s32 al_count; /* number of entries in attrlist */ |
| 101 | __s32 al_more; /* T/F: more attrs (do call again) */ |
| 102 | __s32 al_offset[1]; /* byte offsets of attrs [var-sized] */ |
| 103 | } attrlist_t; |
| 104 | |
| 105 | /* |
| 106 | * Show the interesting info about one attribute. This is what the |
| 107 | * al_offset[i] entry points to. |
| 108 | */ |
| 109 | typedef struct attrlist_ent { /* data from attr_list() */ |
| 110 | __u32 a_valuelen; /* number bytes in value of attr */ |
| 111 | char a_name[1]; /* attr name (NULL terminated) */ |
| 112 | } attrlist_ent_t; |
| 113 | |
| 114 | /* |
| 115 | * Given a pointer to the (char*) buffer containing the attr_list() result, |
| 116 | * and an index, return a pointer to the indicated attribute in the buffer. |
| 117 | */ |
| 118 | #define ATTR_ENTRY(buffer, index) \ |
| 119 | ((attrlist_ent_t *) \ |
| 120 | &((char *)buffer)[ ((attrlist_t *)(buffer))->al_offset[index] ]) |
| 121 | |
| 122 | /* |
| 123 | * Multi-attribute operation vector. |
| 124 | */ |
| 125 | typedef struct attr_multiop { |
| 126 | int am_opcode; /* operation to perform (ATTR_OP_GET, etc.) */ |
| 127 | int am_error; /* [out arg] result of this sub-op (an errno) */ |
| 128 | char *am_attrname; /* attribute name to work with */ |
| 129 | char *am_attrvalue; /* [in/out arg] attribute value (raw bytes) */ |
| 130 | int am_length; /* [in/out arg] length of value */ |
| 131 | int am_flags; /* bitwise OR of attr API flags defined above */ |
| 132 | } attr_multiop_t; |
| 133 | |
| 134 | #define ATTR_OP_GET 1 /* return the indicated attr's value */ |
| 135 | #define ATTR_OP_SET 2 /* set/create the indicated attr/value pair */ |
| 136 | #define ATTR_OP_REMOVE 3 /* remove the indicated attr */ |
| 137 | |
| 138 | /* |
| 139 | * Kernel-internal version of the attrlist cursor. |
| 140 | */ |
| 141 | typedef struct attrlist_cursor_kern { |
| 142 | __u32 hashval; /* hash value of next entry to add */ |
| 143 | __u32 blkno; /* block containing entry (suggestion) */ |
| 144 | __u32 offset; /* offset in list of equal-hashvals */ |
| 145 | __u16 pad1; /* padding to match user-level */ |
| 146 | __u8 pad2; /* padding to match user-level */ |
| 147 | __u8 initted; /* T/F: cursor has been initialized */ |
| 148 | } attrlist_cursor_kern_t; |
| 149 | |
| 150 | |
| 151 | /*======================================================================== |
| 152 | * Function prototypes for the kernel. |
| 153 | *========================================================================*/ |
| 154 | |
| 155 | struct xfs_inode; |
| 156 | struct attrlist_cursor_kern; |
| 157 | struct xfs_da_args; |
| 158 | |
| 159 | /* |
| 160 | * Overall external interface routines. |
| 161 | */ |
Nathan Scott | 80cce77 | 2005-11-02 11:43:04 +1100 | [diff] [blame] | 162 | int xfs_attr_get(bhv_desc_t *, const char *, char *, int *, int, struct cred *); |
| 163 | int xfs_attr_set(bhv_desc_t *, const char *, char *, int, int, struct cred *); |
Tim Shimmin | 726801b | 2006-09-28 11:01:37 +1000 | [diff] [blame] | 164 | int xfs_attr_set_int(struct xfs_inode *, const char *, int, char *, int, int); |
Nathan Scott | 80cce77 | 2005-11-02 11:43:04 +1100 | [diff] [blame] | 165 | int xfs_attr_remove(bhv_desc_t *, const char *, int, struct cred *); |
Tim Shimmin | 726801b | 2006-09-28 11:01:37 +1000 | [diff] [blame] | 166 | int xfs_attr_remove_int(struct xfs_inode *, const char *, int, int); |
| 167 | int xfs_attr_list(bhv_desc_t *, char *, int, int, struct attrlist_cursor_kern *, struct cred *); |
| 168 | int xfs_attr_list_int(struct xfs_attr_list_context *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | int xfs_attr_inactive(struct xfs_inode *dp); |
| 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | int xfs_attr_shortform_getvalue(struct xfs_da_args *); |
Nathan Scott | 80cce77 | 2005-11-02 11:43:04 +1100 | [diff] [blame] | 172 | int xfs_attr_fetch(struct xfs_inode *, const char *, int, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | char *, int *, int, struct cred *); |
Tim Shimmin | 726801b | 2006-09-28 11:01:37 +1000 | [diff] [blame] | 174 | int xfs_attr_rmtval_get(struct xfs_da_args *args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | #endif /* __XFS_ATTR_H__ */ |