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 http://www.opensolaris.org/os/licensing.
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]
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
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
42 #include <sys/vnode.h>
44 #define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */
47 * Structure of all optional attributes.
49 typedef struct xoptattr {
50 timestruc_t xoa_createtime; /* Create time of file */
56 uint8_t xoa_immutable;
57 uint8_t xoa_appendonly;
60 uint8_t xoa_av_quarantined;
61 uint8_t xoa_av_modified;
62 uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ];
64 uint64_t xoa_generation;
70 * The xvattr structure is really a variable length structure that
72 * - The classic vattr_t (xva_vattr)
73 * - a 32 bit quantity (xva_mapsize) that specifies the size of the
74 * attribute bitmaps in 32 bit words.
75 * - A pointer to the returned attribute bitmap (needed because the
76 * previous element, the requested attribute bitmap) is variable lenth.
77 * - The requested attribute bitmap, which is an array of 32 bit words.
78 * Callers use the XVA_SET_REQ() macro to set the bits corresponding to
79 * the attributes that are being requested.
80 * - The returned attribute bitmap, which is an array of 32 bit words.
81 * File systems that support optional attributes use the XVA_SET_RTN()
82 * macro to set the bits corresponding to the attributes that are being
84 * - The xoptattr_t structure which contains the attribute values
86 * xva_mapsize determines how many words in the attribute bitmaps.
87 * Immediately following the attribute bitmaps is the xoptattr_t.
88 * xva_getxoptattr() is used to get the pointer to the xoptattr_t
92 #define XVA_MAPSIZE 3 /* Size of attr bitmaps */
93 #define XVA_MAGIC 0x78766174 /* Magic # for verification */
96 * The xvattr structure is an extensible structure which permits optional
97 * attributes to be requested/returned. File systems may or may not support
98 * optional attributes. They do so at their own discretion but if they do
99 * support optional attributes, they must register the VFSFT_XVATTR feature
100 * so that the optional attributes can be set/retrived.
102 * The fields of the xvattr structure are:
104 * xva_vattr - The first element of an xvattr is a legacy vattr structure
105 * which includes the common attributes. If AT_XVATTR is set in the va_mask
106 * then the entire structure is treated as an xvattr. If AT_XVATTR is not
107 * set, then only the xva_vattr structure can be used.
109 * xva_magic - 0x78766174 (hex for "xvat"). Magic number for verification.
111 * xva_mapsize - Size of requested and returned attribute bitmaps.
113 * xva_rtnattrmapp - Pointer to xva_rtnattrmap[]. We need this since the
114 * size of the array before it, xva_reqattrmap[], could change which means
115 * the location of xva_rtnattrmap[] could change. This will allow unbundled
116 * file systems to find the location of xva_rtnattrmap[] when the sizes change.
118 * xva_reqattrmap[] - Array of requested attributes. Attributes are
119 * represented by a specific bit in a specific element of the attribute
120 * map array. Callers set the bits corresponding to the attributes
121 * that the caller wants to get/set.
123 * xva_rtnattrmap[] - Array of attributes that the file system was able to
124 * process. Not all file systems support all optional attributes. This map
125 * informs the caller which attributes the underlying file system was able
126 * to set/get. (Same structure as the requested attributes array in terms
127 * of each attribute corresponding to specific bits and array elements.)
129 * xva_xoptattrs - Structure containing values of optional attributes.
130 * These values are only valid if the corresponding bits in xva_reqattrmap
131 * are set and the underlying file system supports those attributes.
133 typedef struct xvattr {
134 vattr_t xva_vattr; /* Embedded vattr structure */
135 uint32_t xva_magic; /* Magic Number */
136 uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */
137 uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */
138 uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */
139 uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */
140 xoptattr_t xva_xoptattrs; /* Optional attributes */
144 * Attribute bits used in the extensible attribute's (xva's) attribute
145 * bitmaps. Note that the bitmaps are made up of a variable length number
146 * of 32-bit words. The convention is to use XAT{n}_{attrname} where "n"
147 * is the element in the bitmap (starting at 1). This convention is for
148 * the convenience of the maintainer to keep track of which element each
149 * attribute belongs to.
151 * NOTE THAT CONSUMERS MUST *NOT* USE THE XATn_* DEFINES DIRECTLY. CONSUMERS
152 * MUST USE THE XAT_* DEFINES.
154 #define XAT0_INDEX 0LL /* Index into bitmap for XAT0 attrs */
155 #define XAT0_CREATETIME 0x00000001 /* Create time of file */
156 #define XAT0_ARCHIVE 0x00000002 /* Archive */
157 #define XAT0_SYSTEM 0x00000004 /* System */
158 #define XAT0_READONLY 0x00000008 /* Readonly */
159 #define XAT0_HIDDEN 0x00000010 /* Hidden */
160 #define XAT0_NOUNLINK 0x00000020 /* Nounlink */
161 #define XAT0_IMMUTABLE 0x00000040 /* immutable */
162 #define XAT0_APPENDONLY 0x00000080 /* appendonly */
163 #define XAT0_NODUMP 0x00000100 /* nodump */
164 #define XAT0_OPAQUE 0x00000200 /* opaque */
165 #define XAT0_AV_QUARANTINED 0x00000400 /* anti-virus quarantine */
166 #define XAT0_AV_MODIFIED 0x00000800 /* anti-virus modified */
167 #define XAT0_AV_SCANSTAMP 0x00001000 /* anti-virus scanstamp */
168 #define XAT0_REPARSE 0x00002000 /* FS reparse point */
169 #define XAT0_GEN 0x00004000 /* object generation number */
170 #define XAT0_OFFLINE 0x00008000 /* offline */
171 #define XAT0_SPARSE 0x00010000 /* sparse */
173 #define XAT0_ALL_ATTRS (XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \
174 XAT0_READONLY|XAT0_HIDDEN|XAT0_NOUNLINK|XAT0_IMMUTABLE|XAT0_APPENDONLY| \
175 XAT0_NODUMP|XAT0_OPAQUE|XAT0_AV_QUARANTINED| XAT0_AV_MODIFIED| \
176 XAT0_AV_SCANSTAMP|XAT0_REPARSE|XATO_GEN|XAT0_OFFLINE|XAT0_SPARSE)
178 /* Support for XAT_* optional attributes */
179 #define XVA_MASK 0xffffffff /* Used to mask off 32 bits */
180 #define XVA_SHFT 32 /* Used to shift index */
183 * Used to pry out the index and attribute bits from the XAT_* attributes
184 * defined below. Note that we're masking things down to 32 bits then
185 * casting to uint32_t.
187 #define XVA_INDEX(attr) ((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK))
188 #define XVA_ATTRBIT(attr) ((uint32_t)((attr) & XVA_MASK))
191 * The following defines present a "flat namespace" so that consumers don't
192 * need to keep track of which element belongs to which bitmap entry.
194 * NOTE THAT THESE MUST NEVER BE OR-ed TOGETHER
196 #define XAT_CREATETIME ((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME)
197 #define XAT_ARCHIVE ((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE)
198 #define XAT_SYSTEM ((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM)
199 #define XAT_READONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY)
200 #define XAT_HIDDEN ((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN)
201 #define XAT_NOUNLINK ((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK)
202 #define XAT_IMMUTABLE ((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE)
203 #define XAT_APPENDONLY ((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY)
204 #define XAT_NODUMP ((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP)
205 #define XAT_OPAQUE ((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE)
206 #define XAT_AV_QUARANTINED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED)
207 #define XAT_AV_MODIFIED ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED)
208 #define XAT_AV_SCANSTAMP ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP)
209 #define XAT_REPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_REPARSE)
210 #define XAT_GEN ((XAT0_INDEX << XVA_SHFT) | XAT0_GEN)
211 #define XAT_OFFLINE ((XAT0_INDEX << XVA_SHFT) | XAT0_OFFLINE)
212 #define XAT_SPARSE ((XAT0_INDEX << XVA_SHFT) | XAT0_SPARSE)
215 * The returned attribute map array (xva_rtnattrmap[]) is located past the
216 * requested attribute map array (xva_reqattrmap[]). Its location changes
217 * when the array sizes change. We use a separate pointer in a known location
218 * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[]. This is
221 #define XVA_RTNATTRMAP(xvap) ((xvap)->xva_rtnattrmapp)
224 * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap
225 * of requested attributes (xva_reqattrmap[]).
227 #define XVA_SET_REQ(xvap, attr) \
228 ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \
229 ASSERT((xvap)->xva_magic == XVA_MAGIC); \
230 (xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
232 * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap
233 * of requested attributes (xva_reqattrmap[]).
235 #define XVA_CLR_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)
241 * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap
242 * of returned attributes (xva_rtnattrmap[]).
244 #define XVA_SET_RTN(xvap, attr) \
245 ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR); \
246 ASSERT((xvap)->xva_magic == XVA_MAGIC); \
247 (XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
250 * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[])
251 * to see of the corresponding attribute bit is set. If so, returns non-zero.
253 #define XVA_ISSET_REQ(xvap, attr) \
254 ((((xvap)->xva_vattr.va_mask | AT_XVATTR) && \
255 ((xvap)->xva_magic == XVA_MAGIC) && \
256 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \
257 ((xvap)->xva_reqattrmap[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
260 * XVA_ISSET_RTN() checks the returned attribute bitmap (xva_rtnattrmap[])
261 * to see of the corresponding attribute bit is set. If so, returns non-zero.
263 #define XVA_ISSET_RTN(xvap, attr) \
264 ((((xvap)->xva_vattr.va_mask | AT_XVATTR) && \
265 ((xvap)->xva_magic == XVA_MAGIC) && \
266 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ? \
267 ((XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
270 * Zero out the structure, set the size of the requested/returned bitmaps,
271 * set AT_XVATTR in the embedded vattr_t's va_mask, and set up the pointer
272 * to the returned attributes array.
275 xva_init(xvattr_t *xvap)
277 bzero(xvap, sizeof (xvattr_t));
278 xvap->xva_mapsize = XVA_MAPSIZE;
279 xvap->xva_magic = XVA_MAGIC;
280 xvap->xva_vattr.va_mask = ATTR_XVATTR;
281 xvap->xva_rtnattrmapp = &(xvap->xva_rtnattrmap)[0];
285 * If AT_XVATTR is set, returns a pointer to the embedded xoptattr_t
286 * structure. Otherwise, returns NULL.
288 static inline xoptattr_t *
289 xva_getxoptattr(xvattr_t *xvap)
291 xoptattr_t *xoap = NULL;
292 if (xvap->xva_vattr.va_mask & AT_XVATTR)
293 xoap = &xvap->xva_xoptattrs;
297 #define MODEMASK 07777 /* mode bits plus permission bits */
298 #define PERMMASK 00777 /* permission bits */
303 #define V_ACE_MASK 0x1 /* mask represents NFSv4 ACE permissions */
304 #define V_APPEND 0x2 /* want to do append only check */
307 * Structure used on VOP_GETSECATTR and VOP_SETSECATTR operations
310 typedef struct vsecattr {
311 uint_t vsa_mask; /* See below */
312 int vsa_aclcnt; /* ACL entry count */
313 void *vsa_aclentp; /* pointer to ACL entries */
314 int vsa_dfaclcnt; /* default ACL entry count */
315 void *vsa_dfaclentp; /* pointer to default ACL entries */
316 size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */
317 uint_t vsa_aclflags; /* ACE ACL flags */
320 /* vsa_mask values */
321 #define VSA_ACL 0x0001
322 #define VSA_ACLCNT 0x0002
323 #define VSA_DFACL 0x0004
324 #define VSA_DFACLCNT 0x0008
325 #define VSA_ACE 0x0010
326 #define VSA_ACECNT 0x0020
327 #define VSA_ACE_ALLTYPES 0x0040
328 #define VSA_ACE_ACLFLAGS 0x0080 /* get/set ACE ACL flags */
330 #endif /* _SYS_XVATTR_H */