vnode.h revision 209962
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#include_next <sys/vnode.h>
43
44#ifdef	__cplusplus
45extern "C" {
46#endif
47
48#define	IS_DEVVP(vp)	\
49	((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
50
51#define	V_XATTRDIR	0x0000	/* attribute unnamed directory */
52
53#define	AV_SCANSTAMP_SZ	32		/* length of anti-virus scanstamp */
54
55/*
56 * Structure of all optional attributes.
57 */
58typedef struct xoptattr {
59	timestruc_t	xoa_createtime;	/* Create time of file */
60	uint8_t		xoa_archive;
61	uint8_t		xoa_system;
62	uint8_t		xoa_readonly;
63	uint8_t		xoa_hidden;
64	uint8_t		xoa_nounlink;
65	uint8_t		xoa_immutable;
66	uint8_t		xoa_appendonly;
67	uint8_t		xoa_nodump;
68	uint8_t		xoa_opaque;
69	uint8_t		xoa_av_quarantined;
70	uint8_t		xoa_av_modified;
71	uint8_t		xoa_av_scanstamp[AV_SCANSTAMP_SZ];
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 */
138typedef 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
213#define	XAT0_ALL_ATTRS	(XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \
214    XAT0_READONLY|XAT0_HIDDEN|XAT0_NOUNLINK|XAT0_IMMUTABLE|XAT0_APPENDONLY| \
215    XAT0_NODUMP|XAT0_OPAQUE|XAT0_AV_QUARANTINED| \
216    XAT0_AV_MODIFIED|XAT0_AV_SCANSTAMP)
217
218/* Support for XAT_* optional attributes */
219#define	XVA_MASK		0xffffffff	/* Used to mask off 32 bits */
220#define	XVA_SHFT		32		/* Used to shift index */
221
222/*
223 * Used to pry out the index and attribute bits from the XAT_* attributes
224 * defined below.  Note that we're masking things down to 32 bits then
225 * casting to uint32_t.
226 */
227#define	XVA_INDEX(attr)		((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK))
228#define	XVA_ATTRBIT(attr)	((uint32_t)((attr) & XVA_MASK))
229
230/*
231 * The following defines present a "flat namespace" so that consumers don't
232 * need to keep track of which element belongs to which bitmap entry.
233 *
234 * NOTE THAT THESE MUST NEVER BE OR-ed TOGETHER
235 */
236#define	XAT_CREATETIME		((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME)
237#define	XAT_ARCHIVE		((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE)
238#define	XAT_SYSTEM		((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM)
239#define	XAT_READONLY		((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY)
240#define	XAT_HIDDEN		((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN)
241#define	XAT_NOUNLINK		((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK)
242#define	XAT_IMMUTABLE		((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE)
243#define	XAT_APPENDONLY		((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY)
244#define	XAT_NODUMP		((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP)
245#define	XAT_OPAQUE		((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE)
246#define	XAT_AV_QUARANTINED	((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED)
247#define	XAT_AV_MODIFIED		((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED)
248#define	XAT_AV_SCANSTAMP	((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP)
249
250/*
251 * The returned attribute map array (xva_rtnattrmap[]) is located past the
252 * requested attribute map array (xva_reqattrmap[]).  Its location changes
253 * when the array sizes change.  We use a separate pointer in a known location
254 * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[].  This is
255 * set in xva_init()
256 */
257#define	XVA_RTNATTRMAP(xvap)	((xvap)->xva_rtnattrmapp)
258
259/*
260 * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap
261 * of requested attributes (xva_reqattrmap[]).
262 */
263#define	XVA_SET_REQ(xvap, attr)					\
264	ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);		\
265	ASSERT((xvap)->xva_magic == XVA_MAGIC);			\
266	(xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
267/*
268 * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap
269 * of requested attributes (xva_reqattrmap[]).
270 */
271#define	XVA_CLR_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/*
277 * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap
278 * of returned attributes (xva_rtnattrmap[]).
279 */
280#define	XVA_SET_RTN(xvap, attr)					\
281	ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);		\
282	ASSERT((xvap)->xva_magic == XVA_MAGIC);			\
283	(XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
284
285/*
286 * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[])
287 * to see of the corresponding attribute bit is set.  If so, returns non-zero.
288 */
289#define	XVA_ISSET_REQ(xvap, attr)					\
290	((((xvap)->xva_vattr.va_mask | AT_XVATTR) &&			\
291		((xvap)->xva_magic == XVA_MAGIC) &&			\
292		((xvap)->xva_mapsize > XVA_INDEX(attr))) ?		\
293	((xvap)->xva_reqattrmap[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) :	0)
294
295/*
296 * XVA_ISSET_RTN() checks the returned attribute bitmap (xva_rtnattrmap[])
297 * to see of the corresponding attribute bit is set.  If so, returns non-zero.
298 */
299#define	XVA_ISSET_RTN(xvap, attr)					\
300	((((xvap)->xva_vattr.va_mask | AT_XVATTR) &&			\
301		((xvap)->xva_magic == XVA_MAGIC) &&			\
302		((xvap)->xva_mapsize > XVA_INDEX(attr))) ?		\
303	((XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
304
305#define	MODEMASK	07777		/* mode bits plus permission bits */
306#define	PERMMASK	00777		/* permission bits */
307
308
309/*
310 * VOP_ACCESS flags
311 */
312#define	V_ACE_MASK	0x1	/* mask represents  NFSv4 ACE permissions */
313
314/*
315 * Flags for vnode operations.
316 */
317enum rm		{ RMFILE, RMDIRECTORY };	/* rm or rmdir (remove) */
318enum create	{ CRCREAT, CRMKNOD, CRMKDIR };	/* reason for create */
319
320/*
321 * Structure used on VOP_GETSECATTR and VOP_SETSECATTR operations
322 */
323
324typedef struct vsecattr {
325	uint_t		vsa_mask;	/* See below */
326	int		vsa_aclcnt;	/* ACL entry count */
327	void		*vsa_aclentp;	/* pointer to ACL entries */
328	int		vsa_dfaclcnt;	/* default ACL entry count */
329	void		*vsa_dfaclentp;	/* pointer to default ACL entries */
330	size_t		vsa_aclentsz;	/* ACE size in bytes of vsa_aclentp */
331	uint_t		vsa_aclflags;	/* ACE ACL flags */
332} vsecattr_t;
333
334/* vsa_mask values */
335#define	VSA_ACL			0x0001
336#define	VSA_ACLCNT		0x0002
337#define	VSA_DFACL		0x0004
338#define	VSA_DFACLCNT		0x0008
339#define	VSA_ACE			0x0010
340#define	VSA_ACECNT		0x0020
341#define	VSA_ACE_ALLTYPES	0x0040
342#define	VSA_ACE_ACLFLAGS	0x0080	/* get/set ACE ACL flags */
343
344/*
345 * Structure used by various vnode operations to determine
346 * the context (pid, host, identity) of a caller.
347 *
348 * The cc_caller_id is used to identify one or more callers who invoke
349 * operations, possibly on behalf of others.  For example, the NFS
350 * server could have it's own cc_caller_id which can be detected by
351 * vnode/vfs operations or (FEM) monitors on those operations.  New
352 * caller IDs are generated by fs_new_caller_id().
353 */
354typedef struct caller_context {
355	pid_t		cc_pid;		/* Process ID of the caller */
356	int		cc_sysid;	/* System ID, used for remote calls */
357	u_longlong_t	cc_caller_id;	/* Identifier for (set of) caller(s) */
358	ulong_t		cc_flags;
359} caller_context_t;
360
361/*
362 * Structure tags for function prototypes, defined elsewhere.
363 */
364struct taskq;
365
366/*
367 * Flags for VOP_LOOKUP
368 *
369 * Defined in file.h, but also possible, FIGNORECASE
370 *
371 */
372#define	LOOKUP_DIR		0x01	/* want parent dir vp */
373#define	LOOKUP_XATTR		0x02	/* lookup up extended attr dir */
374#define	CREATE_XATTR_DIR	0x04	/* Create extended attr dir */
375#define	LOOKUP_HAVE_SYSATTR_DIR	0x08	/* Already created virtual GFS dir */
376
377/*
378 * Flags for VOP_READDIR
379 */
380#define	V_RDDIR_ENTFLAGS	0x01	/* request dirent flags */
381
382/*
383 * Public vnode manipulation functions.
384 */
385#ifdef	_KERNEL
386
387void	vn_rele_async(struct vnode *vp, struct taskq *taskq);
388
389/*
390 * Extensible vnode attribute (xva) routines:
391 * xva_init() initializes an xvattr_t (zero struct, init mapsize, set AT_XATTR)
392 * xva_getxoptattr() returns a ponter to the xoptattr_t section of xvattr_t
393 */
394void		xva_init(xvattr_t *);
395xoptattr_t	*xva_getxoptattr(xvattr_t *);	/* Get ptr to xoptattr_t */
396
397#define	VN_RELE_ASYNC(vp, taskq)	{ \
398	vn_rele_async(vp, taskq); \
399}
400
401#endif	/* _KERNEL */
402
403/*
404 * Flags to VOP_SETATTR/VOP_GETATTR.
405 */
406#define	ATTR_UTIME	0x01	/* non-default utime(2) request */
407#define	ATTR_EXEC	0x02	/* invocation from exec(2) */
408#define	ATTR_COMM	0x04	/* yield common vp attributes */
409#define	ATTR_HINT	0x08	/* information returned will be `hint' */
410#define	ATTR_REAL	0x10	/* yield attributes of the real vp */
411#define	ATTR_NOACLCHECK	0x20	/* Don't check ACL when checking permissions */
412#define	ATTR_TRIGGER	0x40	/* Mount first if vnode is a trigger mount */
413
414#ifdef	__cplusplus
415}
416#endif
417
418#endif	/* _SYS_VNODE_H */
419