]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / cddl / contrib / opensolaris / uts / common / sys / vnode.h
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_VNODE_H
40 #define _SYS_VNODE_H
41
42 #include_next <sys/vnode.h>
43
44 #define IS_DEVVP(vp)    \
45         ((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
46
47 #define V_XATTRDIR      0x0000  /* attribute unnamed directory */
48
49 #define AV_SCANSTAMP_SZ 32              /* length of anti-virus scanstamp */
50
51 /*
52  * Structure of all optional attributes.
53  */
54 typedef struct xoptattr {
55         timestruc_t     xoa_createtime; /* Create time of file */
56         uint8_t         xoa_archive;
57         uint8_t         xoa_system;
58         uint8_t         xoa_readonly;
59         uint8_t         xoa_hidden;
60         uint8_t         xoa_nounlink;
61         uint8_t         xoa_immutable;
62         uint8_t         xoa_appendonly;
63         uint8_t         xoa_nodump;
64         uint8_t         xoa_opaque;
65         uint8_t         xoa_av_quarantined;
66         uint8_t         xoa_av_modified;
67         uint8_t         xoa_av_scanstamp[AV_SCANSTAMP_SZ];
68         uint8_t         xoa_reparse;
69         uint64_t        xoa_generation;
70         uint8_t         xoa_offline;
71         uint8_t         xoa_sparse;
72 } xoptattr_t;
73
74 /*
75  * The xvattr structure is really a variable length structure that
76  * is made up of:
77  * - The classic vattr_t (xva_vattr)
78  * - a 32 bit quantity (xva_mapsize) that specifies the size of the
79  *   attribute bitmaps in 32 bit words.
80  * - A pointer to the returned attribute bitmap (needed because the
81  *   previous element, the requested attribute bitmap) is variable lenth.
82  * - The requested attribute bitmap, which is an array of 32 bit words.
83  *   Callers use the XVA_SET_REQ() macro to set the bits corresponding to
84  *   the attributes that are being requested.
85  * - The returned attribute bitmap, which is an array of 32 bit words.
86  *   File systems that support optional attributes use the XVA_SET_RTN()
87  *   macro to set the bits corresponding to the attributes that are being
88  *   returned.
89  * - The xoptattr_t structure which contains the attribute values
90  *
91  * xva_mapsize determines how many words in the attribute bitmaps.
92  * Immediately following the attribute bitmaps is the xoptattr_t.
93  * xva_getxoptattr() is used to get the pointer to the xoptattr_t
94  * section.
95  */
96
97 #define XVA_MAPSIZE     3               /* Size of attr bitmaps */
98 #define XVA_MAGIC       0x78766174      /* Magic # for verification */
99
100 /*
101  * The xvattr structure is an extensible structure which permits optional
102  * attributes to be requested/returned.  File systems may or may not support
103  * optional attributes.  They do so at their own discretion but if they do
104  * support optional attributes, they must register the VFSFT_XVATTR feature
105  * so that the optional attributes can be set/retrived.
106  *
107  * The fields of the xvattr structure are:
108  *
109  * xva_vattr - The first element of an xvattr is a legacy vattr structure
110  * which includes the common attributes.  If AT_XVATTR is set in the va_mask
111  * then the entire structure is treated as an xvattr.  If AT_XVATTR is not
112  * set, then only the xva_vattr structure can be used.
113  *
114  * xva_magic - 0x78766174 (hex for "xvat"). Magic number for verification.
115  *
116  * xva_mapsize - Size of requested and returned attribute bitmaps.
117  *
118  * xva_rtnattrmapp - Pointer to xva_rtnattrmap[].  We need this since the
119  * size of the array before it, xva_reqattrmap[], could change which means
120  * the location of xva_rtnattrmap[] could change.  This will allow unbundled
121  * file systems to find the location of xva_rtnattrmap[] when the sizes change.
122  *
123  * xva_reqattrmap[] - Array of requested attributes.  Attributes are
124  * represented by a specific bit in a specific element of the attribute
125  * map array.  Callers set the bits corresponding to the attributes
126  * that the caller wants to get/set.
127  *
128  * xva_rtnattrmap[] - Array of attributes that the file system was able to
129  * process.  Not all file systems support all optional attributes.  This map
130  * informs the caller which attributes the underlying file system was able
131  * to set/get.  (Same structure as the requested attributes array in terms
132  * of each attribute  corresponding to specific bits and array elements.)
133  *
134  * xva_xoptattrs - Structure containing values of optional attributes.
135  * These values are only valid if the corresponding bits in xva_reqattrmap
136  * are set and the underlying file system supports those attributes.
137  */
138 typedef struct xvattr {
139         vattr_t         xva_vattr;      /* Embedded vattr structure */
140         uint32_t        xva_magic;      /* Magic Number */
141         uint32_t        xva_mapsize;    /* Size of attr bitmap (32-bit words) */
142         uint32_t        *xva_rtnattrmapp;       /* Ptr to xva_rtnattrmap[] */
143         uint32_t        xva_reqattrmap[XVA_MAPSIZE];    /* Requested attrs */
144         uint32_t        xva_rtnattrmap[XVA_MAPSIZE];    /* Returned attrs */
145         xoptattr_t      xva_xoptattrs;  /* Optional attributes */
146 } xvattr_t;
147
148 /*
149  * Attributes of interest to the caller of setattr or getattr.
150  */
151 #define AT_TYPE         0x00001
152 #define AT_MODE         0x00002
153 #define AT_UID          0x00004
154 #define AT_GID          0x00008
155 #define AT_FSID         0x00010
156 #define AT_NODEID       0x00020
157 #define AT_NLINK        0x00040
158 #define AT_SIZE         0x00080
159 #define AT_ATIME        0x00100
160 #define AT_MTIME        0x00200
161 #define AT_CTIME        0x00400
162 #define AT_RDEV         0x00800
163 #define AT_BLKSIZE      0x01000
164 #define AT_NBLOCKS      0x02000
165 /*                      0x04000 */      /* unused */
166 #define AT_SEQ          0x08000
167 /*
168  * If AT_XVATTR is set then there are additional bits to process in
169  * the xvattr_t's attribute bitmap.  If this is not set then the bitmap
170  * MUST be ignored.  Note that this bit must be set/cleared explicitly.
171  * That is, setting AT_ALL will NOT set AT_XVATTR.
172  */
173 #define AT_XVATTR       0x10000
174
175 #define AT_ALL          (AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\
176                         AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\
177                         AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
178
179 #define AT_STAT         (AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\
180                         AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV|AT_TYPE)
181
182 #define AT_TIMES        (AT_ATIME|AT_MTIME|AT_CTIME)
183
184 #define AT_NOSET        (AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
185                         AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
186
187 /*
188  * Attribute bits used in the extensible attribute's (xva's) attribute
189  * bitmaps.  Note that the bitmaps are made up of a variable length number
190  * of 32-bit words.  The convention is to use XAT{n}_{attrname} where "n"
191  * is the element in the bitmap (starting at 1).  This convention is for
192  * the convenience of the maintainer to keep track of which element each
193  * attribute belongs to.
194  *
195  * NOTE THAT CONSUMERS MUST *NOT* USE THE XATn_* DEFINES DIRECTLY.  CONSUMERS
196  * MUST USE THE XAT_* DEFINES.
197  */
198 #define XAT0_INDEX      0LL             /* Index into bitmap for XAT0 attrs */
199 #define XAT0_CREATETIME 0x00000001      /* Create time of file */
200 #define XAT0_ARCHIVE    0x00000002      /* Archive */
201 #define XAT0_SYSTEM     0x00000004      /* System */
202 #define XAT0_READONLY   0x00000008      /* Readonly */
203 #define XAT0_HIDDEN     0x00000010      /* Hidden */
204 #define XAT0_NOUNLINK   0x00000020      /* Nounlink */
205 #define XAT0_IMMUTABLE  0x00000040      /* immutable */
206 #define XAT0_APPENDONLY 0x00000080      /* appendonly */
207 #define XAT0_NODUMP     0x00000100      /* nodump */
208 #define XAT0_OPAQUE     0x00000200      /* opaque */
209 #define XAT0_AV_QUARANTINED     0x00000400      /* anti-virus quarantine */
210 #define XAT0_AV_MODIFIED        0x00000800      /* anti-virus modified */
211 #define XAT0_AV_SCANSTAMP       0x00001000      /* anti-virus scanstamp */
212 #define XAT0_REPARSE    0x00002000      /* FS reparse point */
213 #define XAT0_GEN        0x00004000      /* object generation number */
214 #define XAT0_OFFLINE    0x00008000      /* offline */
215 #define XAT0_SPARSE     0x00010000      /* sparse */
216
217 #define XAT0_ALL_ATTRS  (XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \
218     XAT0_READONLY|XAT0_HIDDEN|XAT0_NOUNLINK|XAT0_IMMUTABLE|XAT0_APPENDONLY| \
219     XAT0_NODUMP|XAT0_OPAQUE|XAT0_AV_QUARANTINED|  XAT0_AV_MODIFIED| \
220     XAT0_AV_SCANSTAMP|XAT0_REPARSE|XATO_GEN|XAT0_OFFLINE|XAT0_SPARSE)
221
222 /* Support for XAT_* optional attributes */
223 #define XVA_MASK                0xffffffff      /* Used to mask off 32 bits */
224 #define XVA_SHFT                32              /* Used to shift index */
225
226 /*
227  * Used to pry out the index and attribute bits from the XAT_* attributes
228  * defined below.  Note that we're masking things down to 32 bits then
229  * casting to uint32_t.
230  */
231 #define XVA_INDEX(attr)         ((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK))
232 #define XVA_ATTRBIT(attr)       ((uint32_t)((attr) & XVA_MASK))
233
234 /*
235  * The following defines present a "flat namespace" so that consumers don't
236  * need to keep track of which element belongs to which bitmap entry.
237  *
238  * NOTE THAT THESE MUST NEVER BE OR-ed TOGETHER
239  */
240 #define XAT_CREATETIME          ((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME)
241 #define XAT_ARCHIVE             ((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE)
242 #define XAT_SYSTEM              ((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM)
243 #define XAT_READONLY            ((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY)
244 #define XAT_HIDDEN              ((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN)
245 #define XAT_NOUNLINK            ((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK)
246 #define XAT_IMMUTABLE           ((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE)
247 #define XAT_APPENDONLY          ((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY)
248 #define XAT_NODUMP              ((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP)
249 #define XAT_OPAQUE              ((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE)
250 #define XAT_AV_QUARANTINED      ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED)
251 #define XAT_AV_MODIFIED         ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED)
252 #define XAT_AV_SCANSTAMP        ((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP)
253 #define XAT_REPARSE             ((XAT0_INDEX << XVA_SHFT) | XAT0_REPARSE)
254 #define XAT_GEN                 ((XAT0_INDEX << XVA_SHFT) | XAT0_GEN)
255 #define XAT_OFFLINE             ((XAT0_INDEX << XVA_SHFT) | XAT0_OFFLINE)
256 #define XAT_SPARSE              ((XAT0_INDEX << XVA_SHFT) | XAT0_SPARSE)
257
258 /*
259  * The returned attribute map array (xva_rtnattrmap[]) is located past the
260  * requested attribute map array (xva_reqattrmap[]).  Its location changes
261  * when the array sizes change.  We use a separate pointer in a known location
262  * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[].  This is
263  * set in xva_init()
264  */
265 #define XVA_RTNATTRMAP(xvap)    ((xvap)->xva_rtnattrmapp)
266
267 /*
268  * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap
269  * of requested attributes (xva_reqattrmap[]).
270  */
271 #define XVA_SET_REQ(xvap, attr)                                 \
272         ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);          \
273         ASSERT((xvap)->xva_magic == XVA_MAGIC);                 \
274         (xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
275 /*
276  * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap
277  * of requested attributes (xva_reqattrmap[]).
278  */
279 #define XVA_CLR_REQ(xvap, attr)                                 \
280         ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);          \
281         ASSERT((xvap)->xva_magic == XVA_MAGIC);                 \
282         (xvap)->xva_reqattrmap[XVA_INDEX(attr)] &= ~XVA_ATTRBIT(attr)
283
284 /*
285  * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap
286  * of returned attributes (xva_rtnattrmap[]).
287  */
288 #define XVA_SET_RTN(xvap, attr)                                 \
289         ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);          \
290         ASSERT((xvap)->xva_magic == XVA_MAGIC);                 \
291         (XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
292
293 /*
294  * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[])
295  * to see of the corresponding attribute bit is set.  If so, returns non-zero.
296  */
297 #define XVA_ISSET_REQ(xvap, attr)                                       \
298         ((((xvap)->xva_vattr.va_mask | AT_XVATTR) &&                    \
299                 ((xvap)->xva_magic == XVA_MAGIC) &&                     \
300                 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ?              \
301         ((xvap)->xva_reqattrmap[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
302
303 /*
304  * XVA_ISSET_RTN() checks the returned attribute bitmap (xva_rtnattrmap[])
305  * to see of the corresponding attribute bit is set.  If so, returns non-zero.
306  */
307 #define XVA_ISSET_RTN(xvap, attr)                                       \
308         ((((xvap)->xva_vattr.va_mask | AT_XVATTR) &&                    \
309                 ((xvap)->xva_magic == XVA_MAGIC) &&                     \
310                 ((xvap)->xva_mapsize > XVA_INDEX(attr))) ?              \
311         ((XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
312
313 #define MODEMASK        07777           /* mode bits plus permission bits */
314 #define PERMMASK        00777           /* permission bits */
315
316 /*
317  * VOP_ACCESS flags
318  */
319 #define V_ACE_MASK      0x1     /* mask represents  NFSv4 ACE permissions */
320
321 /*
322  * Flags for vnode operations.
323  */
324 enum rm         { RMFILE, RMDIRECTORY };        /* rm or rmdir (remove) */
325 enum create     { CRCREAT, CRMKNOD, CRMKDIR };  /* reason for create */
326
327 /*
328  * Structure used on VOP_GETSECATTR and VOP_SETSECATTR operations
329  */
330
331 typedef struct vsecattr {
332         uint_t          vsa_mask;       /* See below */
333         int             vsa_aclcnt;     /* ACL entry count */
334         void            *vsa_aclentp;   /* pointer to ACL entries */
335         int             vsa_dfaclcnt;   /* default ACL entry count */
336         void            *vsa_dfaclentp; /* pointer to default ACL entries */
337         size_t          vsa_aclentsz;   /* ACE size in bytes of vsa_aclentp */
338         uint_t          vsa_aclflags;   /* ACE ACL flags */
339 } vsecattr_t;
340
341 /* vsa_mask values */
342 #define VSA_ACL                 0x0001
343 #define VSA_ACLCNT              0x0002
344 #define VSA_DFACL               0x0004
345 #define VSA_DFACLCNT            0x0008
346 #define VSA_ACE                 0x0010
347 #define VSA_ACECNT              0x0020
348 #define VSA_ACE_ALLTYPES        0x0040
349 #define VSA_ACE_ACLFLAGS        0x0080  /* get/set ACE ACL flags */
350
351 /*
352  * Structure used by various vnode operations to determine
353  * the context (pid, host, identity) of a caller.
354  *
355  * The cc_caller_id is used to identify one or more callers who invoke
356  * operations, possibly on behalf of others.  For example, the NFS
357  * server could have it's own cc_caller_id which can be detected by
358  * vnode/vfs operations or (FEM) monitors on those operations.  New
359  * caller IDs are generated by fs_new_caller_id().
360  */
361 typedef struct caller_context {
362         pid_t           cc_pid;         /* Process ID of the caller */
363         int             cc_sysid;       /* System ID, used for remote calls */
364         u_longlong_t    cc_caller_id;   /* Identifier for (set of) caller(s) */
365         ulong_t         cc_flags;
366 } caller_context_t;
367
368 struct taskq;
369
370 /*
371  * Flags for VOP_LOOKUP
372  *
373  * Defined in file.h, but also possible, FIGNORECASE and FSEARCH
374  *
375  */
376 #define LOOKUP_DIR              0x01    /* want parent dir vp */
377 #define LOOKUP_XATTR            0x02    /* lookup up extended attr dir */
378 #define CREATE_XATTR_DIR        0x04    /* Create extended attr dir */
379 #define LOOKUP_HAVE_SYSATTR_DIR 0x08    /* Already created virtual GFS dir */
380
381 /*
382  * Flags for VOP_READDIR
383  */
384 #define V_RDDIR_ENTFLAGS        0x01    /* request dirent flags */
385 #define V_RDDIR_ACCFILTER       0x02    /* filter out inaccessible dirents */
386
387 /*
388  * Public vnode manipulation functions.
389  */
390 #ifdef  _KERNEL
391
392 void    vn_rele_async(struct vnode *vp, struct taskq *taskq);
393
394 /*
395  * Extensible vnode attribute (xva) routines:
396  * xva_init() initializes an xvattr_t (zero struct, init mapsize, set AT_XATTR)
397  * xva_getxoptattr() returns a ponter to the xoptattr_t section of xvattr_t
398  */
399 void            xva_init(xvattr_t *);
400 xoptattr_t      *xva_getxoptattr(xvattr_t *);   /* Get ptr to xoptattr_t */
401
402 #define VN_RELE_ASYNC(vp, taskq)        { \
403         vn_rele_async(vp, taskq); \
404 }
405
406 #endif  /* _KERNEL */
407
408 /*
409  * Flags to VOP_SETATTR/VOP_GETATTR.
410  */
411 #define ATTR_UTIME      0x01    /* non-default utime(2) request */
412 #define ATTR_EXEC       0x02    /* invocation from exec(2) */
413 #define ATTR_COMM       0x04    /* yield common vp attributes */
414 #define ATTR_HINT       0x08    /* information returned will be `hint' */
415 #define ATTR_REAL       0x10    /* yield attributes of the real vp */
416 #define ATTR_NOACLCHECK 0x20    /* Don't check ACL when checking permissions */
417 #define ATTR_TRIGGER    0x40    /* Mount first if vnode is a trigger mount */
418
419 #ifdef  __cplusplus
420 }
421 #endif
422
423 #endif  /* _SYS_VNODE_H */