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