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