ZAP: Align za_name in zap_attribute_t to 8 bytes
[zfs.git] / include / sys / xvattr.h
bloba7994db894b9d3a6a5fd89073a24a4f268569d74
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
32 * All Rights Reserved
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
36 * contributors.
39 #ifndef _SYS_XVATTR_H
40 #define _SYS_XVATTR_H
42 #include <sys/vnode.h>
43 #include <sys/string.h>
45 #define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */
48 * Structure of all optional attributes.
50 typedef struct xoptattr {
51 inode_timespec_t xoa_createtime; /* Create time of file */
52 uint8_t xoa_archive;
53 uint8_t xoa_system;
54 uint8_t xoa_readonly;
55 uint8_t xoa_hidden;
56 uint8_t xoa_nounlink;
57 uint8_t xoa_immutable;
58 uint8_t xoa_appendonly;
59 uint8_t xoa_nodump;
60 uint8_t xoa_opaque;
61 uint8_t xoa_av_quarantined;
62 uint8_t xoa_av_modified;
63 uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ];
64 uint8_t xoa_reparse;
65 uint64_t xoa_generation;
66 uint8_t xoa_offline;
67 uint8_t xoa_sparse;
68 uint8_t xoa_projinherit;
69 uint64_t xoa_projid;
70 } xoptattr_t;
73 * The xvattr structure is really a variable length structure that
74 * is made up of:
75 * - The classic vattr_t (xva_vattr)
76 * - a 32 bit quantity (xva_mapsize) that specifies the size of the
77 * attribute bitmaps in 32 bit words.
78 * - A pointer to the returned attribute bitmap (needed because the
79 * previous element, the requested attribute bitmap) is variable length.
80 * - The requested attribute bitmap, which is an array of 32 bit words.
81 * Callers use the XVA_SET_REQ() macro to set the bits corresponding to
82 * the attributes that are being requested.
83 * - The returned attribute bitmap, which is an array of 32 bit words.
84 * File systems that support optional attributes use the XVA_SET_RTN()
85 * macro to set the bits corresponding to the attributes that are being
86 * returned.
87 * - The xoptattr_t structure which contains the attribute values
89 * xva_mapsize determines how many words in the attribute bitmaps.
90 * Immediately following the attribute bitmaps is the xoptattr_t.
91 * xva_getxoptattr() is used to get the pointer to the xoptattr_t
92 * section.
95 #define XVA_MAPSIZE 3 /* Size of attr bitmaps */
96 #define XVA_MAGIC 0x78766174 /* Magic # for verification */
99 * The xvattr structure is an extensible structure which permits optional
100 * attributes to be requested/returned. File systems may or may not support
101 * optional attributes. They do so at their own discretion but if they do
102 * support optional attributes, they must register the VFSFT_XVATTR feature
103 * so that the optional attributes can be set/retrieved.
105 * The fields of the xvattr structure are:
107 * xva_vattr - The first element of an xvattr is a legacy vattr structure
108 * which includes the common attributes. If AT_XVATTR is set in the va_mask
109 * then the entire structure is treated as an xvattr. If AT_XVATTR is not
110 * set, then only the xva_vattr structure can be used.
112 * xva_magic - 0x78766174 (hex for "xvat"). Magic number for verification.
114 * xva_mapsize - Size of requested and returned attribute bitmaps.
116 * xva_rtnattrmapp - Pointer to xva_rtnattrmap[]. We need this since the
117 * size of the array before it, xva_reqattrmap[], could change which means
118 * the location of xva_rtnattrmap[] could change. This will allow unbundled
119 * file systems to find the location of xva_rtnattrmap[] when the sizes change.
121 * xva_reqattrmap[] - Array of requested attributes. Attributes are
122 * represented by a specific bit in a specific element of the attribute
123 * map array. Callers set the bits corresponding to the attributes
124 * that the caller wants to get/set.
126 * xva_rtnattrmap[] - Array of attributes that the file system was able to
127 * process. Not all file systems support all optional attributes. This map
128 * informs the caller which attributes the underlying file system was able
129 * to set/get. (Same structure as the requested attributes array in terms
130 * of each attribute corresponding to specific bits and array elements.)
132 * xva_xoptattrs - Structure containing values of optional attributes.
133 * These values are only valid if the corresponding bits in xva_reqattrmap
134 * are set and the underlying file system supports those attributes.
136 typedef struct xvattr {
137 vattr_t xva_vattr; /* Embedded vattr structure */
138 uint32_t xva_magic; /* Magic Number */
139 uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */
140 uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */
141 uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */
142 uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */
143 xoptattr_t xva_xoptattrs; /* Optional attributes */
144 } xvattr_t;
147 * Attribute bits used in the extensible attribute's (xva's) attribute
148 * bitmaps. Note that the bitmaps are made up of a variable length number
149 * of 32-bit words. The convention is to use XAT{n}_{attrname} where "n"
150 * is the element in the bitmap (starting at 1). This convention is for
151 * the convenience of the maintainer to keep track of which element each
152 * attribute belongs to.
154 * NOTE THAT CONSUMERS MUST *NOT* USE THE XATn_* DEFINES DIRECTLY. CONSUMERS
155 * MUST USE THE XAT_* DEFINES.
157 #define XAT0_INDEX 0LL /* Index into bitmap for XAT0 attrs */
158 #define XAT0_CREATETIME 0x00000001 /* Create time of file */
159 #define XAT0_ARCHIVE 0x00000002 /* Archive */
160 #define XAT0_SYSTEM 0x00000004 /* System */
161 #define XAT0_READONLY 0x00000008 /* Readonly */
162 #define XAT0_HIDDEN 0x00000010 /* Hidden */
163 #define XAT0_NOUNLINK 0x00000020 /* Nounlink */
164 #define XAT0_IMMUTABLE 0x00000040 /* immutable */
165 #define XAT0_APPENDONLY 0x00000080 /* appendonly */
166 #define XAT0_NODUMP 0x00000100 /* nodump */
167 #define XAT0_OPAQUE 0x00000200 /* opaque */
168 #define XAT0_AV_QUARANTINED 0x00000400 /* anti-virus quarantine */
169 #define XAT0_AV_MODIFIED 0x00000800 /* anti-virus modified */
170 #define XAT0_AV_SCANSTAMP 0x00001000 /* anti-virus scanstamp */
171 #define XAT0_REPARSE 0x00002000 /* FS reparse point */
172 #define XAT0_GEN 0x00004000 /* object generation number */
173 #define XAT0_OFFLINE 0x00008000 /* offline */
174 #define XAT0_SPARSE 0x00010000 /* sparse */
175 #define XAT0_PROJINHERIT 0x00020000 /* Create with parent projid */
176 #define XAT0_PROJID 0x00040000 /* Project ID */
178 #define XAT0_ALL_ATTRS (XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \
179 XAT0_READONLY|XAT0_HIDDEN|XAT0_NOUNLINK|XAT0_IMMUTABLE|XAT0_APPENDONLY| \
180 XAT0_NODUMP|XAT0_OPAQUE|XAT0_AV_QUARANTINED| XAT0_AV_MODIFIED| \
181 XAT0_AV_SCANSTAMP|XAT0_REPARSE|XATO_GEN|XAT0_OFFLINE|XAT0_SPARSE| \
182 XAT0_PROJINHERIT | XAT0_PROJID)
184 /* Support for XAT_* optional attributes */
185 #define XVA_MASK 0xffffffff /* Used to mask off 32 bits */
186 #define XVA_SHFT 32 /* Used to shift index */
189 * Used to pry out the index and attribute bits from the XAT_* attributes
190 * defined below. Note that we're masking things down to 32 bits then
191 * casting to uint32_t.
193 #define XVA_INDEX(attr) ((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK))
194 #define XVA_ATTRBIT(attr) ((uint32_t)((attr) & XVA_MASK))
197 * The following defines present a "flat namespace" so that consumers don't
198 * need to keep track of which element belongs to which bitmap entry.
200 * NOTE THAT THESE MUST NEVER BE OR-ed TOGETHER
202 #define XAT_CREATETIME ((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME)
203 #define XAT_ARCHIVE ((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE)
204 #define XAT_SYSTEM ((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM)
205 #define XAT_READONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY)
206 #define XAT_HIDDEN ((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN)
207 #define XAT_NOUNLINK ((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK)
208 #define XAT_IMMUTABLE ((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE)
209 #define XAT_APPENDONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY)
210 #define XAT_NODUMP ((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP)
211 #define XAT_OPAQUE ((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE)
212 #define XAT_AV_QUARANTINED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED)
213 #define XAT_AV_MODIFIED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED)
214 #define XAT_AV_SCANSTAMP ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP)
215 #define XAT_REPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_REPARSE)
216 #define XAT_GEN ((XAT0_INDEX << XVA_SHFT) | XAT0_GEN)
217 #define XAT_OFFLINE ((XAT0_INDEX << XVA_SHFT) | XAT0_OFFLINE)
218 #define XAT_SPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_SPARSE)
219 #define XAT_PROJINHERIT ((XAT0_INDEX << XVA_SHFT) | XAT0_PROJINHERIT)
220 #define XAT_PROJID ((XAT0_INDEX << XVA_SHFT) | XAT0_PROJID)
223 * The returned attribute map array (xva_rtnattrmap[]) is located past the
224 * requested attribute map array (xva_reqattrmap[]). Its location changes
225 * when the array sizes change. We use a separate pointer in a known location
226 * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[]. This is
227 * set in xva_init()
229 #define XVA_RTNATTRMAP(xvap) ((xvap)->xva_rtnattrmapp)
232 * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap
233 * of requested attributes (xva_reqattrmap[]).
235 #define XVA_SET_REQ(xvap, attr) \
236 ASSERT((xvap)->xva_vattr.va_mask & AT_XVATTR); \
237 ASSERT((xvap)->xva_magic == XVA_MAGIC); \
238 (xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
240 * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap
241 * of requested attributes (xva_reqattrmap[]).
243 #define XVA_CLR_REQ(xvap, attr) \
244 ASSERT((xvap)->xva_vattr.va_mask & AT_XVATTR); \
245 ASSERT((xvap)->xva_magic == XVA_MAGIC); \
246 (xvap)->xva_reqattrmap[XVA_INDEX(attr)] &= ~XVA_ATTRBIT(attr)
249 * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap
250 * of returned attributes (xva_rtnattrmap[]).
252 #define XVA_SET_RTN(xvap, attr) \
253 ASSERT((xvap)->xva_vattr.va_mask & AT_XVATTR); \
254 ASSERT((xvap)->xva_magic == XVA_MAGIC); \
255 (XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
258 * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[])
259 * to see of the corresponding attribute bit is set. If so, returns non-zero.
261 #define XVA_ISSET_REQ(xvap, attr) \
262 ((((xvap)->xva_vattr.va_mask & AT_XVATTR) && \
263 ((xvap)->xva_magic == XVA_MAGIC) && \
264 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \
265 ((xvap)->xva_reqattrmap[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
268 * XVA_ISSET_RTN() checks the returned attribute bitmap (xva_rtnattrmap[])
269 * to see of the corresponding attribute bit is set. If so, returns non-zero.
271 #define XVA_ISSET_RTN(xvap, attr) \
272 ((((xvap)->xva_vattr.va_mask & AT_XVATTR) && \
273 ((xvap)->xva_magic == XVA_MAGIC) && \
274 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \
275 ((XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
278 * Zero out the structure, set the size of the requested/returned bitmaps,
279 * set AT_XVATTR in the embedded vattr_t's va_mask, and set up the pointer
280 * to the returned attributes array.
282 static inline void
283 xva_init(xvattr_t *xvap)
285 memset(xvap, 0, sizeof (xvattr_t));
286 xvap->xva_mapsize = XVA_MAPSIZE;
287 xvap->xva_magic = XVA_MAGIC;
288 xvap->xva_vattr.va_mask = ATTR_XVATTR;
289 xvap->xva_rtnattrmapp = &(xvap->xva_rtnattrmap)[0];
293 * If AT_XVATTR is set, returns a pointer to the embedded xoptattr_t
294 * structure. Otherwise, returns NULL.
296 static inline xoptattr_t *
297 xva_getxoptattr(xvattr_t *xvap)
299 xoptattr_t *xoap = NULL;
300 if (xvap->xva_vattr.va_mask & AT_XVATTR)
301 xoap = &xvap->xva_xoptattrs;
302 return (xoap);
305 #define MODEMASK 07777 /* mode bits plus permission bits */
306 #define PERMMASK 00777 /* permission bits */
309 * VOP_ACCESS flags
311 #define V_ACE_MASK 0x1 /* mask represents NFSv4 ACE permissions */
312 #define V_APPEND 0x2 /* want to do append only check */
315 * Structure used on VOP_GETSECATTR and VOP_SETSECATTR operations
318 typedef struct vsecattr {
319 uint_t vsa_mask; /* See below */
320 int vsa_aclcnt; /* ACL entry count */
321 void *vsa_aclentp; /* pointer to ACL entries */
322 int vsa_dfaclcnt; /* default ACL entry count */
323 void *vsa_dfaclentp; /* pointer to default ACL entries */
324 size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */
325 uint_t vsa_aclflags; /* ACE ACL flags */
326 } vsecattr_t;
328 /* vsa_mask values */
329 #define VSA_ACL 0x0001
330 #define VSA_ACLCNT 0x0002
331 #define VSA_DFACL 0x0004
332 #define VSA_DFACLCNT 0x0008
333 #define VSA_ACE 0x0010
334 #define VSA_ACECNT 0x0020
335 #define VSA_ACE_ALLTYPES 0x0040
336 #define VSA_ACE_ACLFLAGS 0x0080 /* get/set ACE ACL flags */
338 #endif /* _SYS_XVATTR_H */