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