1*8329232eSGordon Ross /*
2*8329232eSGordon Ross  * CDDL HEADER START
3*8329232eSGordon Ross  *
4*8329232eSGordon Ross  * The contents of this file are subject to the terms of the
5*8329232eSGordon Ross  * Common Development and Distribution License (the "License").
6*8329232eSGordon Ross  * You may not use this file except in compliance with the License.
7*8329232eSGordon Ross  *
8*8329232eSGordon Ross  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*8329232eSGordon Ross  * or http://www.opensolaris.org/os/licensing.
10*8329232eSGordon Ross  * See the License for the specific language governing permissions
11*8329232eSGordon Ross  * and limitations under the License.
12*8329232eSGordon Ross  *
13*8329232eSGordon Ross  * When distributing Covered Code, include this CDDL HEADER in each
14*8329232eSGordon Ross  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*8329232eSGordon Ross  * If applicable, add the following below this CDDL HEADER, with the
16*8329232eSGordon Ross  * fields enclosed by brackets "[]" replaced with your own identifying
17*8329232eSGordon Ross  * information: Portions Copyright [yyyy] [name of copyright owner]
18*8329232eSGordon Ross  *
19*8329232eSGordon Ross  * CDDL HEADER END
20*8329232eSGordon Ross  */
21*8329232eSGordon Ross 
22*8329232eSGordon Ross /*
23*8329232eSGordon Ross  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
24*8329232eSGordon Ross  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
25*8329232eSGordon Ross  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
26*8329232eSGordon Ross  */
27*8329232eSGordon Ross 
28*8329232eSGordon Ross /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
29*8329232eSGordon Ross /*	  All Rights Reserved	*/
30*8329232eSGordon Ross 
31*8329232eSGordon Ross /*
32*8329232eSGordon Ross  * University Copyright- Copyright (c) 1982, 1986, 1988
33*8329232eSGordon Ross  * The Regents of the University of California
34*8329232eSGordon Ross  * All Rights Reserved
35*8329232eSGordon Ross  *
36*8329232eSGordon Ross  * University Acknowledgment- Portions of this document are derived from
37*8329232eSGordon Ross  * software developed by the University of California, Berkeley, and its
38*8329232eSGordon Ross  * contributors.
39*8329232eSGordon Ross  */
40*8329232eSGordon Ross 
41*8329232eSGordon Ross #ifndef _SYS_VNODE_H
42*8329232eSGordon Ross #define	_SYS_VNODE_H
43*8329232eSGordon Ross 
44*8329232eSGordon Ross #include <sys/types.h>
45*8329232eSGordon Ross #include <sys/t_lock.h>
46*8329232eSGordon Ross #include <sys/time_impl.h>
47*8329232eSGordon Ross #include <sys/cred.h>
48*8329232eSGordon Ross #include <sys/uio.h>
49*8329232eSGordon Ross #include <sys/resource.h>
50*8329232eSGordon Ross #include <vm/seg_enum.h>
51*8329232eSGordon Ross #include <sys/kstat.h>
52*8329232eSGordon Ross #include <sys/kmem.h>
53*8329232eSGordon Ross #include <sys/list.h>
54*8329232eSGordon Ross #include <sys/avl.h>
55*8329232eSGordon Ross #ifdef	_KERNEL
56*8329232eSGordon Ross #include <sys/rwstlock.h>
57*8329232eSGordon Ross #include <sys/buf.h>
58*8329232eSGordon Ross #endif	/* _KERNEL */
59*8329232eSGordon Ross 
60*8329232eSGordon Ross #ifdef	__cplusplus
61*8329232eSGordon Ross extern "C" {
62*8329232eSGordon Ross #endif
63*8329232eSGordon Ross 
64*8329232eSGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL)
65*8329232eSGordon Ross 
66*8329232eSGordon Ross /*
67*8329232eSGordon Ross  * Statistics for all vnode operations.
68*8329232eSGordon Ross  * All operations record number of ops (since boot/mount/zero'ed).
69*8329232eSGordon Ross  * Certain I/O operations (read, write, readdir) also record number
70*8329232eSGordon Ross  * of bytes transferred.
71*8329232eSGordon Ross  * This appears in two places in the system: one is embedded in each
72*8329232eSGordon Ross  * vfs_t.  There is also an array of vopstats_t structures allocated
73*8329232eSGordon Ross  * on a per-fstype basis.
74*8329232eSGordon Ross  */
75*8329232eSGordon Ross 
76*8329232eSGordon Ross #define	VOPSTATS_STR	"vopstats_"	/* Initial string for vopstat kstats */
77*8329232eSGordon Ross 
78*8329232eSGordon Ross typedef struct vopstats {
79*8329232eSGordon Ross 	kstat_named_t	nopen;		/* VOP_OPEN */
80*8329232eSGordon Ross 	kstat_named_t	nclose;		/* VOP_CLOSE */
81*8329232eSGordon Ross 	kstat_named_t	nread;		/* VOP_READ */
82*8329232eSGordon Ross 	kstat_named_t	read_bytes;
83*8329232eSGordon Ross 	kstat_named_t	nwrite;		/* VOP_WRITE */
84*8329232eSGordon Ross 	kstat_named_t	write_bytes;
85*8329232eSGordon Ross 	kstat_named_t	nioctl;		/* VOP_IOCTL */
86*8329232eSGordon Ross 	kstat_named_t	nsetfl;		/* VOP_SETFL */
87*8329232eSGordon Ross 	kstat_named_t	ngetattr;	/* VOP_GETATTR */
88*8329232eSGordon Ross 	kstat_named_t	nsetattr;	/* VOP_SETATTR */
89*8329232eSGordon Ross 	kstat_named_t	naccess;	/* VOP_ACCESS */
90*8329232eSGordon Ross 	kstat_named_t	nlookup;	/* VOP_LOOKUP */
91*8329232eSGordon Ross 	kstat_named_t	ncreate;	/* VOP_CREATE */
92*8329232eSGordon Ross 	kstat_named_t	nremove;	/* VOP_REMOVE */
93*8329232eSGordon Ross 	kstat_named_t	nlink;		/* VOP_LINK */
94*8329232eSGordon Ross 	kstat_named_t	nrename;	/* VOP_RENAME */
95*8329232eSGordon Ross 	kstat_named_t	nmkdir;		/* VOP_MKDIR */
96*8329232eSGordon Ross 	kstat_named_t	nrmdir;		/* VOP_RMDIR */
97*8329232eSGordon Ross 	kstat_named_t	nreaddir;	/* VOP_READDIR */
98*8329232eSGordon Ross 	kstat_named_t	readdir_bytes;
99*8329232eSGordon Ross 	kstat_named_t	nsymlink;	/* VOP_SYMLINK */
100*8329232eSGordon Ross 	kstat_named_t	nreadlink;	/* VOP_READLINK */
101*8329232eSGordon Ross 	kstat_named_t	nfsync;		/* VOP_FSYNC */
102*8329232eSGordon Ross 	kstat_named_t	ninactive;	/* VOP_INACTIVE */
103*8329232eSGordon Ross 	kstat_named_t	nfid;		/* VOP_FID */
104*8329232eSGordon Ross 	kstat_named_t	nrwlock;	/* VOP_RWLOCK */
105*8329232eSGordon Ross 	kstat_named_t	nrwunlock;	/* VOP_RWUNLOCK */
106*8329232eSGordon Ross 	kstat_named_t	nseek;		/* VOP_SEEK */
107*8329232eSGordon Ross 	kstat_named_t	ncmp;		/* VOP_CMP */
108*8329232eSGordon Ross 	kstat_named_t	nfrlock;	/* VOP_FRLOCK */
109*8329232eSGordon Ross 	kstat_named_t	nspace;		/* VOP_SPACE */
110*8329232eSGordon Ross 	kstat_named_t	nrealvp;	/* VOP_REALVP */
111*8329232eSGordon Ross 	kstat_named_t	ngetpage;	/* VOP_GETPAGE */
112*8329232eSGordon Ross 	kstat_named_t	nputpage;	/* VOP_PUTPAGE */
113*8329232eSGordon Ross 	kstat_named_t	nmap;		/* VOP_MAP */
114*8329232eSGordon Ross 	kstat_named_t	naddmap;	/* VOP_ADDMAP */
115*8329232eSGordon Ross 	kstat_named_t	ndelmap;	/* VOP_DELMAP */
116*8329232eSGordon Ross 	kstat_named_t	npoll;		/* VOP_POLL */
117*8329232eSGordon Ross 	kstat_named_t	ndump;		/* VOP_DUMP */
118*8329232eSGordon Ross 	kstat_named_t	npathconf;	/* VOP_PATHCONF */
119*8329232eSGordon Ross 	kstat_named_t	npageio;	/* VOP_PAGEIO */
120*8329232eSGordon Ross 	kstat_named_t	ndumpctl;	/* VOP_DUMPCTL */
121*8329232eSGordon Ross 	kstat_named_t	ndispose;	/* VOP_DISPOSE */
122*8329232eSGordon Ross 	kstat_named_t	nsetsecattr;	/* VOP_SETSECATTR */
123*8329232eSGordon Ross 	kstat_named_t	ngetsecattr;	/* VOP_GETSECATTR */
124*8329232eSGordon Ross 	kstat_named_t	nshrlock;	/* VOP_SHRLOCK */
125*8329232eSGordon Ross 	kstat_named_t	nvnevent;	/* VOP_VNEVENT */
126*8329232eSGordon Ross 	kstat_named_t	nreqzcbuf;	/* VOP_REQZCBUF */
127*8329232eSGordon Ross 	kstat_named_t	nretzcbuf;	/* VOP_RETZCBUF */
128*8329232eSGordon Ross } vopstats_t;
129*8329232eSGordon Ross #endif // defined(_KERNEL) || defined(_FAKE_KERNEL)
130*8329232eSGordon Ross 
131*8329232eSGordon Ross /*
132*8329232eSGordon Ross  * The vnode is the focus of all file activity in UNIX.
133*8329232eSGordon Ross  * A vnode is allocated for each active file, each current
134*8329232eSGordon Ross  * directory, each mounted-on file, and the root.
135*8329232eSGordon Ross  *
136*8329232eSGordon Ross  * Each vnode is usually associated with a file-system-specific node (for
137*8329232eSGordon Ross  * UFS, this is the in-memory inode).  Generally, a vnode and an fs-node
138*8329232eSGordon Ross  * should be created and destroyed together as a pair.
139*8329232eSGordon Ross  *
140*8329232eSGordon Ross  * If a vnode is reused for a new file, it should be reinitialized by calling
141*8329232eSGordon Ross  * either vn_reinit() or vn_recycle().
142*8329232eSGordon Ross  *
143*8329232eSGordon Ross  * vn_reinit() resets the entire vnode as if it was returned by vn_alloc().
144*8329232eSGordon Ross  * The caller is responsible for setting up the entire vnode after calling
145*8329232eSGordon Ross  * vn_reinit().  This is important when using kmem caching where the vnode is
146*8329232eSGordon Ross  * allocated by a constructor, for instance.
147*8329232eSGordon Ross  *
148*8329232eSGordon Ross  * vn_recycle() is used when the file system keeps some state around in both
149*8329232eSGordon Ross  * the vnode and the associated FS-node.  In UFS, for example, the inode of
150*8329232eSGordon Ross  * a deleted file can be reused immediately.  The v_data, v_vfsp, v_op, etc.
151*8329232eSGordon Ross  * remains the same but certain fields related to the previous instance need
152*8329232eSGordon Ross  * to be reset.  In particular:
153*8329232eSGordon Ross  *	v_femhead
154*8329232eSGordon Ross  *	v_path
155*8329232eSGordon Ross  *	v_rdcnt, v_wrcnt
156*8329232eSGordon Ross  *	v_mmap_read, v_mmap_write
157*8329232eSGordon Ross  */
158*8329232eSGordon Ross 
159*8329232eSGordon Ross /*
160*8329232eSGordon Ross  * vnode types.  VNON means no type.  These values are unrelated to
161*8329232eSGordon Ross  * values in on-disk inodes.
162*8329232eSGordon Ross  */
163*8329232eSGordon Ross typedef enum vtype {
164*8329232eSGordon Ross 	VNON	= 0,
165*8329232eSGordon Ross 	VREG	= 1,
166*8329232eSGordon Ross 	VDIR	= 2,
167*8329232eSGordon Ross 	VBLK	= 3,
168*8329232eSGordon Ross 	VCHR	= 4,
169*8329232eSGordon Ross 	VLNK	= 5,
170*8329232eSGordon Ross 	VFIFO	= 6,
171*8329232eSGordon Ross 	VDOOR	= 7,
172*8329232eSGordon Ross 	VPROC	= 8,
173*8329232eSGordon Ross 	VSOCK	= 9,
174*8329232eSGordon Ross 	VPORT	= 10,
175*8329232eSGordon Ross 	VBAD	= 11
176*8329232eSGordon Ross } vtype_t;
177*8329232eSGordon Ross 
178*8329232eSGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL)
179*8329232eSGordon Ross 
180*8329232eSGordon Ross /*
181*8329232eSGordon Ross  * VSD - Vnode Specific Data
182*8329232eSGordon Ross  * Used to associate additional private data with a vnode.
183*8329232eSGordon Ross  */
184*8329232eSGordon Ross struct vsd_node {
185*8329232eSGordon Ross 	list_node_t vs_nodes;		/* list of all VSD nodes */
186*8329232eSGordon Ross 	uint_t vs_nkeys;		/* entries in value array */
187*8329232eSGordon Ross 	void **vs_value;		/* array of value/key */
188*8329232eSGordon Ross };
189*8329232eSGordon Ross 
190*8329232eSGordon Ross /*
191*8329232eSGordon Ross  * Many of the fields in the vnode are read-only once they are initialized
192*8329232eSGordon Ross  * at vnode creation time.  Other fields are protected by locks.
193*8329232eSGordon Ross  *
194*8329232eSGordon Ross  * IMPORTANT: vnodes should be created ONLY by calls to vn_alloc().  They
195*8329232eSGordon Ross  * may not be embedded into the file-system specific node (inode).  The
196*8329232eSGordon Ross  * size of vnodes may change.
197*8329232eSGordon Ross  *
198*8329232eSGordon Ross  * The v_lock protects:
199*8329232eSGordon Ross  *   v_flag
200*8329232eSGordon Ross  *   v_stream
201*8329232eSGordon Ross  *   v_count
202*8329232eSGordon Ross  *   v_shrlocks
203*8329232eSGordon Ross  *   v_path
204*8329232eSGordon Ross  *   v_vsd
205*8329232eSGordon Ross  *   v_xattrdir
206*8329232eSGordon Ross  *
207*8329232eSGordon Ross  * A special lock (implemented by vn_vfswlock in vnode.c) protects:
208*8329232eSGordon Ross  *   v_vfsmountedhere
209*8329232eSGordon Ross  *
210*8329232eSGordon Ross  * The global flock_lock mutex (in flock.c) protects:
211*8329232eSGordon Ross  *   v_filocks
212*8329232eSGordon Ross  *
213*8329232eSGordon Ross  * IMPORTANT NOTE:
214*8329232eSGordon Ross  *
215*8329232eSGordon Ross  *   The following vnode fields are considered public and may safely be
216*8329232eSGordon Ross  *   accessed by file systems or other consumers:
217*8329232eSGordon Ross  *
218*8329232eSGordon Ross  *     v_lock
219*8329232eSGordon Ross  *     v_flag
220*8329232eSGordon Ross  *     v_count
221*8329232eSGordon Ross  *     v_data
222*8329232eSGordon Ross  *     v_vfsp
223*8329232eSGordon Ross  *     v_stream
224*8329232eSGordon Ross  *     v_type
225*8329232eSGordon Ross  *     v_rdev
226*8329232eSGordon Ross  *
228*8329232eSGordon Ross  * In particular, file systems should not access other fields; they may
229*8329232eSGordon Ross  * change or even be removed.  The functionality which was once provided
230*8329232eSGordon Ross  * by these fields is available through vn_* functions.
231*8329232eSGordon Ross  */
232*8329232eSGordon Ross 
233*8329232eSGordon Ross struct fem_head;	/* from fem.h */
234*8329232eSGordon Ross 
235*8329232eSGordon Ross typedef struct vnode {
236*8329232eSGordon Ross 	kmutex_t	v_lock;		/* protects vnode fields */
237*8329232eSGordon Ross 	uint_t		v_flag;		/* vnode flags (see below) */
238*8329232eSGordon Ross 	uint_t		v_count;	/* reference count */
239*8329232eSGordon Ross 	void		*v_data;	/* private data for fs */
240*8329232eSGordon Ross 	struct vfs	*v_vfsp;	/* ptr to containing VFS */
241*8329232eSGordon Ross 	struct stdata	*v_stream;	/* associated stream */
242*8329232eSGordon Ross 	enum vtype	v_type;		/* vnode type */
243*8329232eSGordon Ross 	dev_t		v_rdev;		/* device (VCHR, VBLK) */
244*8329232eSGordon Ross 
245*8329232eSGordon Ross 	/* PRIVATE FIELDS BELOW - DO NOT USE */
246*8329232eSGordon Ross 
247*8329232eSGordon Ross 	struct vfs	*v_vfsmountedhere; /* ptr to vfs mounted here */
248*8329232eSGordon Ross 	struct vnodeops	*v_op;		/* vnode operations */
249*8329232eSGordon Ross 	krwlock_t	v_nbllock;	/* sync for NBMAND locks */
250*8329232eSGordon Ross 	char		*v_path;	/* cached path */
251*8329232eSGordon Ross 	uint_t		v_rdcnt;	/* open for read count  (VREG only) */
252*8329232eSGordon Ross 	uint_t		v_wrcnt;	/* open for write count (VREG only) */
253*8329232eSGordon Ross 	struct vnode	*v_xattrdir;	/* unnamed extended attr dir (GFS) */
254*8329232eSGordon Ross 
255*8329232eSGordon Ross 	/* Private to the fake vnode impl. */
256*8329232eSGordon Ross 
257*8329232eSGordon Ross 	int		v_fd;
258*8329232eSGordon Ross 	dev_t		v_st_dev;
259*8329232eSGordon Ross 	ino_t		v_st_ino;
260*8329232eSGordon Ross 	avl_node_t	v_avl_node;
261*8329232eSGordon Ross 	int		v_vfsrlocks;
262*8329232eSGordon Ross } vnode_t;
263*8329232eSGordon Ross 
264*8329232eSGordon Ross #define	IS_DEVVP(vp)	\
265*8329232eSGordon Ross 	((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
266*8329232eSGordon Ross 
267*8329232eSGordon Ross #define	VNODE_ALIGN	16
268*8329232eSGordon Ross 
269*8329232eSGordon Ross /*
270*8329232eSGordon Ross  * vnode flags.
271*8329232eSGordon Ross  */
272*8329232eSGordon Ross #define	VROOT		0x01	/* root of its file system */
273*8329232eSGordon Ross #define	VNOCACHE	0x02	/* don't keep cache pages on vnode */
274*8329232eSGordon Ross #define	VNOMAP		0x04	/* file cannot be mapped/faulted */
275*8329232eSGordon Ross #define	VDUP		0x08	/* file should be dup'ed rather then opened */
276*8329232eSGordon Ross #define	VNOSWAP		0x10	/* file cannot be used as virtual swap device */
277*8329232eSGordon Ross #define	VNOMOUNT	0x20	/* file cannot be covered by mount */
278*8329232eSGordon Ross #define	VISSWAP		0x40	/* vnode is being used for swap */
279*8329232eSGordon Ross #define	VSWAPLIKE	0x80	/* vnode acts like swap (but may not be) */
280*8329232eSGordon Ross 
281*8329232eSGordon Ross #define	IS_SWAPVP(vp)	(((vp)->v_flag & (VISSWAP | VSWAPLIKE)) != 0)
282*8329232eSGordon Ross 
283*8329232eSGordon Ross #else // defined(_KERNEL) || defined(_FAKE_KERNEL)
284*8329232eSGordon Ross typedef struct vnode vnode_t;
285*8329232eSGordon Ross #endif // defined(_KERNEL) || defined(_FAKE_KERNEL)
286*8329232eSGordon Ross 
287*8329232eSGordon Ross #if defined(_KERNEL)
288*8329232eSGordon Ross typedef struct vn_vfslocks_entry {
289*8329232eSGordon Ross 	rwstlock_t ve_lock;
290*8329232eSGordon Ross 	void *ve_vpvfs;
291*8329232eSGordon Ross 	struct vn_vfslocks_entry *ve_next;
292*8329232eSGordon Ross 	uint32_t ve_refcnt;
293*8329232eSGordon Ross 	char pad[64 - sizeof (rwstlock_t) - 2 * sizeof (void *) - \
294*8329232eSGordon Ross 	    sizeof (uint32_t)];
295*8329232eSGordon Ross } vn_vfslocks_entry_t;
296*8329232eSGordon Ross #endif	/* _KERNEL */
297*8329232eSGordon Ross 
298*8329232eSGordon Ross /*
299*8329232eSGordon Ross  * The following two flags are used to lock the v_vfsmountedhere field
300*8329232eSGordon Ross  */
301*8329232eSGordon Ross #define	VVFSLOCK	0x100
302*8329232eSGordon Ross #define	VVFSWAIT	0x200
303*8329232eSGordon Ross 
304*8329232eSGordon Ross /*
305*8329232eSGordon Ross  * Used to serialize VM operations on a vnode
306*8329232eSGordon Ross  */
307*8329232eSGordon Ross #define	VVMLOCK		0x400
308*8329232eSGordon Ross 
309*8329232eSGordon Ross /*
310*8329232eSGordon Ross  * Tell vn_open() not to fail a directory open for writing but
311*8329232eSGordon Ross  * to go ahead and call VOP_OPEN() to let the filesystem check.
312*8329232eSGordon Ross  */
313*8329232eSGordon Ross #define	VDIROPEN	0x800
314*8329232eSGordon Ross 
315*8329232eSGordon Ross /*
316*8329232eSGordon Ross  * Flag to let the VM system know that this file is most likely a binary
317*8329232eSGordon Ross  * or shared library since it has been mmap()ed EXEC at some time.
318*8329232eSGordon Ross  */
319*8329232eSGordon Ross #define	VVMEXEC		0x1000
320*8329232eSGordon Ross 
321*8329232eSGordon Ross #define	VPXFS		0x2000  /* clustering: global fs proxy vnode */
322*8329232eSGordon Ross 
323*8329232eSGordon Ross #define	IS_PXFSVP(vp)	((vp)->v_flag & VPXFS)
324*8329232eSGordon Ross 
325*8329232eSGordon Ross #define	V_XATTRDIR	0x4000	/* attribute unnamed directory */
326*8329232eSGordon Ross 
327*8329232eSGordon Ross #define	IS_XATTRDIR(vp)	((vp)->v_flag & V_XATTRDIR)
328*8329232eSGordon Ross 
329*8329232eSGordon Ross #define	V_LOCALITY	0x8000	/* whether locality aware */
330*8329232eSGordon Ross 
331*8329232eSGordon Ross /*
332*8329232eSGordon Ross  * Flag that indicates the VM should maintain the v_pages list with all modified
333*8329232eSGordon Ross  * pages on one end and unmodified pages at the other. This makes finding dirty
334*8329232eSGordon Ross  * pages to write back to disk much faster at the expense of taking a minor
335*8329232eSGordon Ross  * fault on the first store instruction which touches a writable page.
336*8329232eSGordon Ross  */
337*8329232eSGordon Ross #define	VMODSORT	(0x10000)
338*8329232eSGordon Ross #define	IS_VMODSORT(vp) \
339*8329232eSGordon Ross 	(pvn_vmodsort_supported != 0 && ((vp)->v_flag  & VMODSORT) != 0)
340*8329232eSGordon Ross 
341*8329232eSGordon Ross #define	VISSWAPFS	0x20000	/* vnode is being used for swapfs */
342*8329232eSGordon Ross 
343*8329232eSGordon Ross /*
344*8329232eSGordon Ross  * The mdb memstat command assumes that IS_SWAPFSVP only uses the
345*8329232eSGordon Ross  * vnode's v_flag field.  If this changes, cache the additional
346*8329232eSGordon Ross  * fields in mdb; see vn_get in mdb/common/modules/genunix/memory.c
347*8329232eSGordon Ross  */
348*8329232eSGordon Ross #define	IS_SWAPFSVP(vp)	(((vp)->v_flag & VISSWAPFS) != 0)
349*8329232eSGordon Ross 
350*8329232eSGordon Ross #define	V_SYSATTR	0x40000	/* vnode is a GFS system attribute */
351*8329232eSGordon Ross 
352*8329232eSGordon Ross /*
353*8329232eSGordon Ross  * Vnode attributes.  A bit-mask is supplied as part of the
354*8329232eSGordon Ross  * structure to indicate the attributes the caller wants to
355*8329232eSGordon Ross  * set (setattr) or extract (getattr).
356*8329232eSGordon Ross  */
357*8329232eSGordon Ross 
358*8329232eSGordon Ross /*
359*8329232eSGordon Ross  * Note that va_nodeid and va_nblocks are 64bit data type.
360*8329232eSGordon Ross  * We support large files over NFSV3. With Solaris client and
361*8329232eSGordon Ross  * Server that generates 64bit ino's and sizes these fields
362*8329232eSGordon Ross  * will overflow if they are 32 bit sizes.
363*8329232eSGordon Ross  */
364*8329232eSGordon Ross 
365*8329232eSGordon Ross typedef struct vattr {
366*8329232eSGordon Ross 	uint_t		va_mask;	/* bit-mask of attributes */
367*8329232eSGordon Ross 	vtype_t		va_type;	/* vnode type (for create) */
368*8329232eSGordon Ross 	mode_t		va_mode;	/* file access mode */
369*8329232eSGordon Ross 	uid_t		va_uid;		/* owner user id */
370*8329232eSGordon Ross 	gid_t		va_gid;		/* owner group id */
371*8329232eSGordon Ross 	dev_t		va_fsid;	/* file system id (dev for now) */
372*8329232eSGordon Ross 	u_longlong_t	va_nodeid;	/* node id */
373*8329232eSGordon Ross 	nlink_t		va_nlink;	/* number of references to file */
374*8329232eSGordon Ross 	u_offset_t	va_size;	/* file size in bytes */
375*8329232eSGordon Ross 	timestruc_t	va_atime;	/* time of last access */
376*8329232eSGordon Ross 	timestruc_t	va_mtime;	/* time of last modification */
377*8329232eSGordon Ross 	timestruc_t	va_ctime;	/* time of last status change */
378*8329232eSGordon Ross 	dev_t		va_rdev;	/* device the file represents */
379*8329232eSGordon Ross 	uint_t		va_blksize;	/* fundamental block size */
380*8329232eSGordon Ross 	u_longlong_t	va_nblocks;	/* # of blocks allocated */
381*8329232eSGordon Ross 	uint_t		va_seq;		/* sequence number */
382*8329232eSGordon Ross } vattr_t;
383*8329232eSGordon Ross 
384*8329232eSGordon Ross #define	AV_SCANSTAMP_SZ	32		/* length of anti-virus scanstamp */
385*8329232eSGordon Ross 
386*8329232eSGordon Ross /*
387*8329232eSGordon Ross  * Structure of all optional attributes.
388*8329232eSGordon Ross  */
389*8329232eSGordon Ross typedef struct xoptattr {
390*8329232eSGordon Ross 	timestruc_t	xoa_createtime;	/* Create time of file */
391*8329232eSGordon Ross 	uint8_t		xoa_archive;
392*8329232eSGordon Ross 	uint8_t		xoa_system;
393*8329232eSGordon Ross 	uint8_t		xoa_readonly;
394*8329232eSGordon Ross 	uint8_t		xoa_hidden;
395*8329232eSGordon Ross 	uint8_t		xoa_nounlink;
396*8329232eSGordon Ross 	uint8_t		xoa_immutable;
397*8329232eSGordon Ross 	uint8_t		xoa_appendonly;
398*8329232eSGordon Ross 	uint8_t		xoa_nodump;
399*8329232eSGordon Ross 	uint8_t		xoa_opaque;
400*8329232eSGordon Ross 	uint8_t		xoa_av_quarantined;
401*8329232eSGordon Ross 	uint8_t		xoa_av_modified;
402*8329232eSGordon Ross 	uint8_t		xoa_av_scanstamp[AV_SCANSTAMP_SZ];
403*8329232eSGordon Ross 	uint8_t		xoa_reparse;
404*8329232eSGordon Ross 	uint64_t	xoa_generation;
405*8329232eSGordon Ross 	uint8_t		xoa_offline;
406*8329232eSGordon Ross 	uint8_t		xoa_sparse;
407*8329232eSGordon Ross } xoptattr_t;
408*8329232eSGordon Ross 
409*8329232eSGordon Ross /*
410*8329232eSGordon Ross  * The xvattr structure is really a variable length structure that
411*8329232eSGordon Ross  * is made up of:
412*8329232eSGordon Ross  * - The classic vattr_t (xva_vattr)
413*8329232eSGordon Ross  * - a 32 bit quantity (xva_mapsize) that specifies the size of the
414*8329232eSGordon Ross  *   attribute bitmaps in 32 bit words.
415*8329232eSGordon Ross  * - A pointer to the returned attribute bitmap (needed because the
416*8329232eSGordon Ross  *   previous element, the requested attribute bitmap) is variable lenth.
417*8329232eSGordon Ross  * - The requested attribute bitmap, which is an array of 32 bit words.
418*8329232eSGordon Ross  *   Callers use the XVA_SET_REQ() macro to set the bits corresponding to
419*8329232eSGordon Ross  *   the attributes that are being requested.
420*8329232eSGordon Ross  * - The returned attribute bitmap, which is an array of 32 bit words.
421*8329232eSGordon Ross  *   File systems that support optional attributes use the XVA_SET_RTN()
422*8329232eSGordon Ross  *   macro to set the bits corresponding to the attributes that are being
423*8329232eSGordon Ross  *   returned.
424*8329232eSGordon Ross  * - The xoptattr_t structure which contains the attribute values
425*8329232eSGordon Ross  *
426*8329232eSGordon Ross  * xva_mapsize determines how many words in the attribute bitmaps.
427*8329232eSGordon Ross  * Immediately following the attribute bitmaps is the xoptattr_t.
428*8329232eSGordon Ross  * xva_getxoptattr() is used to get the pointer to the xoptattr_t
429*8329232eSGordon Ross  * section.
430*8329232eSGordon Ross  */
431*8329232eSGordon Ross 
432*8329232eSGordon Ross #define	XVA_MAPSIZE	3		/* Size of attr bitmaps */
433*8329232eSGordon Ross #define	XVA_MAGIC	0x78766174	/* Magic # for verification */
434*8329232eSGordon Ross 
435*8329232eSGordon Ross /*
436*8329232eSGordon Ross  * The xvattr structure is an extensible structure which permits optional
437*8329232eSGordon Ross  * attributes to be requested/returned.  File systems may or may not support
438*8329232eSGordon Ross  * optional attributes.  They do so at their own discretion but if they do
439*8329232eSGordon Ross  * support optional attributes, they must register the VFSFT_XVATTR feature
440*8329232eSGordon Ross  * so that the optional attributes can be set/retrived.
441*8329232eSGordon Ross  *
442*8329232eSGordon Ross  * The fields of the xvattr structure are:
443*8329232eSGordon Ross  *
444*8329232eSGordon Ross  * xva_vattr - The first element of an xvattr is a legacy vattr structure
445*8329232eSGordon Ross  * which includes the common attributes.  If AT_XVATTR is set in the va_mask
446*8329232eSGordon Ross  * then the entire structure is treated as an xvattr.  If AT_XVATTR is not
447*8329232eSGordon Ross  * set, then only the xva_vattr structure can be used.
448*8329232eSGordon Ross  *
449*8329232eSGordon Ross  * xva_magic - 0x78766174 (hex for "xvat"). Magic number for verification.
450*8329232eSGordon Ross  *
451*8329232eSGordon Ross  * xva_mapsize - Size of requested and returned attribute bitmaps.
452*8329232eSGordon Ross  *
453*8329232eSGordon Ross  * xva_rtnattrmapp - Pointer to xva_rtnattrmap[].  We need this since the
454*8329232eSGordon Ross  * size of the array before it, xva_reqattrmap[], could change which means
455*8329232eSGordon Ross  * the location of xva_rtnattrmap[] could change.  This will allow unbundled
456*8329232eSGordon Ross  * file systems to find the location of xva_rtnattrmap[] when the sizes change.
457*8329232eSGordon Ross  *
458*8329232eSGordon Ross  * xva_reqattrmap[] - Array of requested attributes.  Attributes are
459*8329232eSGordon Ross  * represented by a specific bit in a specific element of the attribute
460*8329232eSGordon Ross  * map array.  Callers set the bits corresponding to the attributes
461*8329232eSGordon Ross  * that the caller wants to get/set.
462*8329232eSGordon Ross  *
463*8329232eSGordon Ross  * xva_rtnattrmap[] - Array of attributes that the file system was able to
464*8329232eSGordon Ross  * process.  Not all file systems support all optional attributes.  This map
465*8329232eSGordon Ross  * informs the caller which attributes the underlying file system was able
466*8329232eSGordon Ross  * to set/get.  (Same structure as the requested attributes array in terms
467*8329232eSGordon Ross  * of each attribute  corresponding to specific bits and array elements.)
468*8329232eSGordon Ross  *
469*8329232eSGordon Ross  * xva_xoptattrs - Structure containing values of optional attributes.
470*8329232eSGordon Ross  * These values are only valid if the corresponding bits in xva_reqattrmap
471*8329232eSGordon Ross  * are set and the underlying file system supports those attributes.
472*8329232eSGordon Ross  */
473*8329232eSGordon Ross typedef struct xvattr {
474*8329232eSGordon Ross 	vattr_t		xva_vattr;	/* Embedded vattr structure */
475*8329232eSGordon Ross 	uint32_t	xva_magic;	/* Magic Number */
476*8329232eSGordon Ross 	uint32_t	xva_mapsize;	/* Size of attr bitmap (32-bit words) */
477*8329232eSGordon Ross 	uint32_t	*xva_rtnattrmapp;	/* Ptr to xva_rtnattrmap[] */
478*8329232eSGordon Ross 	uint32_t	xva_reqattrmap[XVA_MAPSIZE];	/* Requested attrs */
479*8329232eSGordon Ross 	uint32_t	xva_rtnattrmap[XVA_MAPSIZE];	/* Returned attrs */
480*8329232eSGordon Ross 	xoptattr_t	xva_xoptattrs;	/* Optional attributes */
481*8329232eSGordon Ross } xvattr_t;
482*8329232eSGordon Ross 
483*8329232eSGordon Ross #ifdef _SYSCALL32
484*8329232eSGordon Ross /*
485*8329232eSGordon Ross  * For bigtypes time_t changed to 64 bit on the 64-bit kernel.
486*8329232eSGordon Ross  * Define an old version for user/kernel interface
487*8329232eSGordon Ross  */
488*8329232eSGordon Ross 
489*8329232eSGordon Ross #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
490*8329232eSGordon Ross #pragma pack(4)
491*8329232eSGordon Ross #endif
492*8329232eSGordon Ross 
493*8329232eSGordon Ross typedef struct vattr32 {
494*8329232eSGordon Ross 	uint32_t	va_mask;	/* bit-mask of attributes */
495*8329232eSGordon Ross 	vtype_t		va_type;	/* vnode type (for create) */
496*8329232eSGordon Ross 	mode32_t	va_mode;	/* file access mode */
497*8329232eSGordon Ross 	uid32_t		va_uid;		/* owner user id */
498*8329232eSGordon Ross 	gid32_t		va_gid;		/* owner group id */
499*8329232eSGordon Ross 	dev32_t		va_fsid;	/* file system id (dev for now) */
500*8329232eSGordon Ross 	u_longlong_t	va_nodeid;	/* node id */
501*8329232eSGordon Ross 	nlink_t		va_nlink;	/* number of references to file */
502*8329232eSGordon Ross 	u_offset_t	va_size;	/* file size in bytes */
503*8329232eSGordon Ross 	timestruc32_t	va_atime;	/* time of last access */
504*8329232eSGordon Ross 	timestruc32_t	va_mtime;	/* time of last modification */
505*8329232eSGordon Ross 	timestruc32_t	va_ctime;	/* time of last status change */
506*8329232eSGordon Ross 	dev32_t		va_rdev;	/* device the file represents */
507*8329232eSGordon Ross 	uint32_t	va_blksize;	/* fundamental block size */
508*8329232eSGordon Ross 	u_longlong_t	va_nblocks;	/* # of blocks allocated */
509*8329232eSGordon Ross 	uint32_t	va_seq;		/* sequence number */
510*8329232eSGordon Ross } vattr32_t;
511*8329232eSGordon Ross 
512*8329232eSGordon Ross #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
513*8329232eSGordon Ross #pragma pack()
514*8329232eSGordon Ross #endif
515*8329232eSGordon Ross 
516*8329232eSGordon Ross #else  /* not _SYSCALL32 */
517*8329232eSGordon Ross #define	vattr32		vattr
518*8329232eSGordon Ross typedef vattr_t		vattr32_t;
519*8329232eSGordon Ross #endif /* _SYSCALL32 */
520*8329232eSGordon Ross 
521*8329232eSGordon Ross /*
522*8329232eSGordon Ross  * Attributes of interest to the caller of setattr or getattr.
523*8329232eSGordon Ross  */
524*8329232eSGordon Ross #define	AT_TYPE		0x00001
525*8329232eSGordon Ross #define	AT_MODE		0x00002
526*8329232eSGordon Ross #define	AT_UID		0x00004
527*8329232eSGordon Ross #define	AT_GID		0x00008
528*8329232eSGordon Ross #define	AT_FSID		0x00010
529*8329232eSGordon Ross #define	AT_NODEID	0x00020
530*8329232eSGordon Ross #define	AT_NLINK	0x00040
531*8329232eSGordon Ross #define	AT_SIZE		0x00080
532*8329232eSGordon Ross #define	AT_ATIME	0x00100
533*8329232eSGordon Ross #define	AT_MTIME	0x00200
534*8329232eSGordon Ross #define	AT_CTIME	0x00400
535*8329232eSGordon Ross #define	AT_RDEV		0x00800
536*8329232eSGordon Ross #define	AT_BLKSIZE	0x01000
537*8329232eSGordon Ross #define	AT_NBLOCKS	0x02000
538*8329232eSGordon Ross /*			0x04000 */	/* unused */
539*8329232eSGordon Ross #define	AT_SEQ		0x08000
540*8329232eSGordon Ross /*
541*8329232eSGordon Ross  * If AT_XVATTR is set then there are additional bits to process in
542*8329232eSGordon Ross  * the xvattr_t's attribute bitmap.  If this is not set then the bitmap
543*8329232eSGordon Ross  * MUST be ignored.  Note that this bit must be set/cleared explicitly.
544*8329232eSGordon Ross  * That is, setting AT_ALL will NOT set AT_XVATTR.
545*8329232eSGordon Ross  */
546*8329232eSGordon Ross #define	AT_XVATTR	0x10000
547*8329232eSGordon Ross 
548*8329232eSGordon Ross #define	AT_ALL		(AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\
550*8329232eSGordon Ross 			AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
551*8329232eSGordon Ross 
552*8329232eSGordon Ross #define	AT_STAT		(AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\
554*8329232eSGordon Ross 
555*8329232eSGordon Ross #define	AT_TIMES	(AT_ATIME|AT_MTIME|AT_CTIME)
556*8329232eSGordon Ross 
557*8329232eSGordon Ross #define	AT_NOSET	(AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
558*8329232eSGordon Ross 			AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
559*8329232eSGordon Ross 
560*8329232eSGordon Ross /*
561*8329232eSGordon Ross  * Attribute bits used in the extensible attribute's (xva's) attribute
562*8329232eSGordon Ross  * bitmaps.  Note that the bitmaps are made up of a variable length number
563*8329232eSGordon Ross  * of 32-bit words.  The convention is to use XAT{n}_{attrname} where "n"
564*8329232eSGordon Ross  * is the element in the bitmap (starting at 1).  This convention is for
565*8329232eSGordon Ross  * the convenience of the maintainer to keep track of which element each
566*8329232eSGordon Ross  * attribute belongs to.
567*8329232eSGordon Ross  *
569*8329232eSGordon Ross  * MUST USE THE XAT_* DEFINES.
570*8329232eSGordon Ross  */
571*8329232eSGordon Ross #define	XAT0_INDEX	0LL		/* Index into bitmap for XAT0 attrs */
572*8329232eSGordon Ross #define	XAT0_CREATETIME	0x00000001	/* Create time of file */
573*8329232eSGordon Ross #define	XAT0_ARCHIVE	0x00000002	/* Archive */
574*8329232eSGordon Ross #define	XAT0_SYSTEM	0x00000004	/* System */
575*8329232eSGordon Ross #define	XAT0_READONLY	0x00000008	/* Readonly */
576*8329232eSGordon Ross #define	XAT0_HIDDEN	0x00000010	/* Hidden */
577*8329232eSGordon Ross #define	XAT0_NOUNLINK	0x00000020	/* Nounlink */
578*8329232eSGordon Ross #define	XAT0_IMMUTABLE	0x00000040	/* immutable */
579*8329232eSGordon Ross #define	XAT0_APPENDONLY	0x00000080	/* appendonly */
580*8329232eSGordon Ross #define	XAT0_NODUMP	0x00000100	/* nodump */
581*8329232eSGordon Ross #define	XAT0_OPAQUE	0x00000200	/* opaque */
582*8329232eSGordon Ross #define	XAT0_AV_QUARANTINED	0x00000400	/* anti-virus quarantine */
583*8329232eSGordon Ross #define	XAT0_AV_MODIFIED	0x00000800	/* anti-virus modified */
584*8329232eSGordon Ross #define	XAT0_AV_SCANSTAMP	0x00001000	/* anti-virus scanstamp */
585*8329232eSGordon Ross #define	XAT0_REPARSE	0x00002000	/* FS reparse point */
586*8329232eSGordon Ross #define	XAT0_GEN	0x00004000	/* object generation number */
587*8329232eSGordon Ross #define	XAT0_OFFLINE	0x00008000	/* offline */
588*8329232eSGordon Ross #define	XAT0_SPARSE	0x00010000	/* sparse */
589*8329232eSGordon Ross 
590*8329232eSGordon Ross #define	XAT0_ALL_ATTRS	(XAT0_CREATETIME|XAT0_ARCHIVE|XAT0_SYSTEM| \
594*8329232eSGordon Ross 
595*8329232eSGordon Ross /* Support for XAT_* optional attributes */
596*8329232eSGordon Ross #define	XVA_MASK		0xffffffff	/* Used to mask off 32 bits */
597*8329232eSGordon Ross #define	XVA_SHFT		32		/* Used to shift index */
598*8329232eSGordon Ross 
599*8329232eSGordon Ross /*
600*8329232eSGordon Ross  * Used to pry out the index and attribute bits from the XAT_* attributes
601*8329232eSGordon Ross  * defined below.  Note that we're masking things down to 32 bits then
602*8329232eSGordon Ross  * casting to uint32_t.
603*8329232eSGordon Ross  */
604*8329232eSGordon Ross #define	XVA_INDEX(attr)		((uint32_t)(((attr) >> XVA_SHFT) & XVA_MASK))
605*8329232eSGordon Ross #define	XVA_ATTRBIT(attr)	((uint32_t)((attr) & XVA_MASK))
606*8329232eSGordon Ross 
607*8329232eSGordon Ross /*
608*8329232eSGordon Ross  * The following defines present a "flat namespace" so that consumers don't
609*8329232eSGordon Ross  * need to keep track of which element belongs to which bitmap entry.
610*8329232eSGordon Ross  *
612*8329232eSGordon Ross  */
613*8329232eSGordon Ross #define	XAT_CREATETIME		((XAT0_INDEX << XVA_SHFT) | XAT0_CREATETIME)
614*8329232eSGordon Ross #define	XAT_ARCHIVE		((XAT0_INDEX << XVA_SHFT) | XAT0_ARCHIVE)
615*8329232eSGordon Ross #define	XAT_SYSTEM		((XAT0_INDEX << XVA_SHFT) | XAT0_SYSTEM)
616*8329232eSGordon Ross #define	XAT_READONLY		((XAT0_INDEX << XVA_SHFT) | XAT0_READONLY)
617*8329232eSGordon Ross #define	XAT_HIDDEN		((XAT0_INDEX << XVA_SHFT) | XAT0_HIDDEN)
618*8329232eSGordon Ross #define	XAT_NOUNLINK		((XAT0_INDEX << XVA_SHFT) | XAT0_NOUNLINK)
619*8329232eSGordon Ross #define	XAT_IMMUTABLE		((XAT0_INDEX << XVA_SHFT) | XAT0_IMMUTABLE)
620*8329232eSGordon Ross #define	XAT_APPENDONLY		((XAT0_INDEX << XVA_SHFT) | XAT0_APPENDONLY)
621*8329232eSGordon Ross #define	XAT_NODUMP		((XAT0_INDEX << XVA_SHFT) | XAT0_NODUMP)
622*8329232eSGordon Ross #define	XAT_OPAQUE		((XAT0_INDEX << XVA_SHFT) | XAT0_OPAQUE)
623*8329232eSGordon Ross #define	XAT_AV_QUARANTINED	((XAT0_INDEX << XVA_SHFT) | XAT0_AV_QUARANTINED)
624*8329232eSGordon Ross #define	XAT_AV_MODIFIED		((XAT0_INDEX << XVA_SHFT) | XAT0_AV_MODIFIED)
625*8329232eSGordon Ross #define	XAT_AV_SCANSTAMP	((XAT0_INDEX << XVA_SHFT) | XAT0_AV_SCANSTAMP)
626*8329232eSGordon Ross #define	XAT_REPARSE		((XAT0_INDEX << XVA_SHFT) | XAT0_REPARSE)
627*8329232eSGordon Ross #define	XAT_GEN			((XAT0_INDEX << XVA_SHFT) | XAT0_GEN)
628*8329232eSGordon Ross #define	XAT_OFFLINE		((XAT0_INDEX << XVA_SHFT) | XAT0_OFFLINE)
629*8329232eSGordon Ross #define	XAT_SPARSE		((XAT0_INDEX << XVA_SHFT) | XAT0_SPARSE)
630*8329232eSGordon Ross 
631*8329232eSGordon Ross /*
632*8329232eSGordon Ross  * The returned attribute map array (xva_rtnattrmap[]) is located past the
633*8329232eSGordon Ross  * requested attribute map array (xva_reqattrmap[]).  Its location changes
634*8329232eSGordon Ross  * when the array sizes change.  We use a separate pointer in a known location
635*8329232eSGordon Ross  * (xva_rtnattrmapp) to hold the location of xva_rtnattrmap[].  This is
636*8329232eSGordon Ross  * set in xva_init()
637*8329232eSGordon Ross  */
638*8329232eSGordon Ross #define	XVA_RTNATTRMAP(xvap)	((xvap)->xva_rtnattrmapp)
639*8329232eSGordon Ross 
640*8329232eSGordon Ross /*
641*8329232eSGordon Ross  * XVA_SET_REQ() sets an attribute bit in the proper element in the bitmap
642*8329232eSGordon Ross  * of requested attributes (xva_reqattrmap[]).
643*8329232eSGordon Ross  */
644*8329232eSGordon Ross #define	XVA_SET_REQ(xvap, attr)					\
645*8329232eSGordon Ross 	ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);		\
646*8329232eSGordon Ross 	ASSERT((xvap)->xva_magic == XVA_MAGIC);			\
647*8329232eSGordon Ross 	(xvap)->xva_reqattrmap[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
648*8329232eSGordon Ross /*
649*8329232eSGordon Ross  * XVA_CLR_REQ() clears an attribute bit in the proper element in the bitmap
650*8329232eSGordon Ross  * of requested attributes (xva_reqattrmap[]).
651*8329232eSGordon Ross  */
652*8329232eSGordon Ross #define	XVA_CLR_REQ(xvap, attr)					\
653*8329232eSGordon Ross 	ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);		\
654*8329232eSGordon Ross 	ASSERT((xvap)->xva_magic == XVA_MAGIC);			\
655*8329232eSGordon Ross 	(xvap)->xva_reqattrmap[XVA_INDEX(attr)] &= ~XVA_ATTRBIT(attr)
656*8329232eSGordon Ross 
657*8329232eSGordon Ross /*
658*8329232eSGordon Ross  * XVA_SET_RTN() sets an attribute bit in the proper element in the bitmap
659*8329232eSGordon Ross  * of returned attributes (xva_rtnattrmap[]).
660*8329232eSGordon Ross  */
661*8329232eSGordon Ross #define	XVA_SET_RTN(xvap, attr)					\
662*8329232eSGordon Ross 	ASSERT((xvap)->xva_vattr.va_mask | AT_XVATTR);		\
663*8329232eSGordon Ross 	ASSERT((xvap)->xva_magic == XVA_MAGIC);			\
664*8329232eSGordon Ross 	(XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] |= XVA_ATTRBIT(attr)
665*8329232eSGordon Ross 
666*8329232eSGordon Ross /*
667*8329232eSGordon Ross  * XVA_ISSET_REQ() checks the requested attribute bitmap (xva_reqattrmap[])
668*8329232eSGordon Ross  * to see of the corresponding attribute bit is set.  If so, returns non-zero.
669*8329232eSGordon Ross  */
670*8329232eSGordon Ross #define	XVA_ISSET_REQ(xvap, attr)					\
671*8329232eSGordon Ross 	((((xvap)->xva_vattr.va_mask | AT_XVATTR) &&			\
672*8329232eSGordon Ross 		((xvap)->xva_magic == XVA_MAGIC) &&			\
673*8329232eSGordon Ross 		((xvap)->xva_mapsize > XVA_INDEX(attr))) ?		\
674*8329232eSGordon Ross 	((xvap)->xva_reqattrmap[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) :	0)
675*8329232eSGordon Ross 
676*8329232eSGordon Ross /*
677*8329232eSGordon Ross  * XVA_ISSET_RTN() checks the returned attribute bitmap (xva_rtnattrmap[])
678*8329232eSGordon Ross  * to see of the corresponding attribute bit is set.  If so, returns non-zero.
679*8329232eSGordon Ross  */
680*8329232eSGordon Ross #define	XVA_ISSET_RTN(xvap, attr)					\
681*8329232eSGordon Ross 	((((xvap)->xva_vattr.va_mask | AT_XVATTR) &&			\
682*8329232eSGordon Ross 		((xvap)->xva_magic == XVA_MAGIC) &&			\
683*8329232eSGordon Ross 		((xvap)->xva_mapsize > XVA_INDEX(attr))) ?		\
684*8329232eSGordon Ross 	((XVA_RTNATTRMAP(xvap))[XVA_INDEX(attr)] & XVA_ATTRBIT(attr)) : 0)
685*8329232eSGordon Ross 
686*8329232eSGordon Ross /*
687*8329232eSGordon Ross  *  Modes.  Some values same as S_xxx entries from stat.h for convenience.
688*8329232eSGordon Ross  */
689*8329232eSGordon Ross #define	VSUID		04000		/* set user id on execution */
690*8329232eSGordon Ross #define	VSGID		02000		/* set group id on execution */
691*8329232eSGordon Ross #define	VSVTX		01000		/* save swapped text even after use */
692*8329232eSGordon Ross 
693*8329232eSGordon Ross /*
694*8329232eSGordon Ross  * Permissions.
695*8329232eSGordon Ross  */
696*8329232eSGordon Ross #define	VREAD		00400
697*8329232eSGordon Ross #define	VWRITE		00200
698*8329232eSGordon Ross #define	VEXEC		00100
699*8329232eSGordon Ross 
700*8329232eSGordon Ross #define	MODEMASK	07777		/* mode bits plus permission bits */
701*8329232eSGordon Ross #define	PERMMASK	00777		/* permission bits */
702*8329232eSGordon Ross 
703*8329232eSGordon Ross /*
704*8329232eSGordon Ross  * VOP_ACCESS flags
705*8329232eSGordon Ross  */
706*8329232eSGordon Ross #define	V_ACE_MASK	0x1	/* mask represents  NFSv4 ACE permissions */
707*8329232eSGordon Ross #define	V_APPEND	0x2	/* want to do append only check */
708*8329232eSGordon Ross 
709*8329232eSGordon Ross /*
710*8329232eSGordon Ross  * Check whether mandatory file locking is enabled.
711*8329232eSGordon Ross  */
712*8329232eSGordon Ross 
713*8329232eSGordon Ross #define	MANDMODE(mode)		(((mode) & (VSGID|(VEXEC>>3))) == VSGID)
714*8329232eSGordon Ross #define	MANDLOCK(vp, mode)	((vp)->v_type == VREG && MANDMODE(mode))
715*8329232eSGordon Ross 
716*8329232eSGordon Ross /*
717*8329232eSGordon Ross  * Flags for vnode operations.
718*8329232eSGordon Ross  */
719*8329232eSGordon Ross enum rm		{ RMFILE, RMDIRECTORY };	/* rm or rmdir (remove) */
720*8329232eSGordon Ross enum symfollow	{ NO_FOLLOW, FOLLOW };		/* follow symlinks (or not) */
721*8329232eSGordon Ross enum vcexcl	{ NONEXCL, EXCL };		/* (non)excl create */
722*8329232eSGordon Ross enum create	{ CRCREAT, CRMKNOD, CRMKDIR };	/* reason for create */
723*8329232eSGordon Ross 
724*8329232eSGordon Ross typedef enum rm		rm_t;
725*8329232eSGordon Ross typedef enum symfollow	symfollow_t;
726*8329232eSGordon Ross typedef enum vcexcl	vcexcl_t;
727*8329232eSGordon Ross typedef enum create	create_t;
728*8329232eSGordon Ross 
729*8329232eSGordon Ross /* Vnode Events - Used by VOP_VNEVENT */
730*8329232eSGordon Ross typedef enum vnevent	{
731*8329232eSGordon Ross 	VE_SUPPORT	= 0,	/* Query */
732*8329232eSGordon Ross 	VE_RENAME_SRC	= 1,	/* Rename, with vnode as source */
733*8329232eSGordon Ross 	VE_RENAME_DEST	= 2,	/* Rename, with vnode as target/destination */
734*8329232eSGordon Ross 	VE_REMOVE	= 3,	/* Remove of vnode's name */
735*8329232eSGordon Ross 	VE_RMDIR	= 4,	/* Remove of directory vnode's name */
736*8329232eSGordon Ross 	VE_CREATE	= 5,	/* Create with vnode's name which exists */
737*8329232eSGordon Ross 	VE_LINK		= 6,	/* Link with vnode's name as source */
738*8329232eSGordon Ross 	VE_RENAME_DEST_DIR	= 7,	/* Rename with vnode as target dir */
739*8329232eSGordon Ross 	VE_MOUNTEDOVER	= 8,	/* File or Filesystem got mounted over vnode */
740*8329232eSGordon Ross 	VE_TRUNCATE = 9		/* Truncate */
741*8329232eSGordon Ross } vnevent_t;
742*8329232eSGordon Ross 
743*8329232eSGordon Ross /*
744*8329232eSGordon Ross  * Values for checking vnode open and map counts
745*8329232eSGordon Ross  */
746*8329232eSGordon Ross enum v_mode { V_READ, V_WRITE, V_RDORWR, V_RDANDWR };
747*8329232eSGordon Ross 
748*8329232eSGordon Ross typedef enum v_mode v_mode_t;
749*8329232eSGordon Ross 
750*8329232eSGordon Ross #define	V_TRUE	1
751*8329232eSGordon Ross #define	V_FALSE	0
752*8329232eSGordon Ross 
753*8329232eSGordon Ross /*
754*8329232eSGordon Ross  * Structure used on VOP_GETSECATTR and VOP_SETSECATTR operations
755*8329232eSGordon Ross  */
756*8329232eSGordon Ross 
757*8329232eSGordon Ross typedef struct vsecattr {
758*8329232eSGordon Ross 	uint_t		vsa_mask;	/* See below */
759*8329232eSGordon Ross 	int		vsa_aclcnt;	/* ACL entry count */
760*8329232eSGordon Ross 	void		*vsa_aclentp;	/* pointer to ACL entries */
761*8329232eSGordon Ross 	int		vsa_dfaclcnt;	/* default ACL entry count */
762*8329232eSGordon Ross 	void		*vsa_dfaclentp;	/* pointer to default ACL entries */
763*8329232eSGordon Ross 	size_t		vsa_aclentsz;	/* ACE size in bytes of vsa_aclentp */
764*8329232eSGordon Ross 	uint_t		vsa_aclflags;	/* ACE ACL flags */
765*8329232eSGordon Ross } vsecattr_t;
766*8329232eSGordon Ross 
767*8329232eSGordon Ross /* vsa_mask values */
768*8329232eSGordon Ross #define	VSA_ACL			0x0001
769*8329232eSGordon Ross #define	VSA_ACLCNT		0x0002
770*8329232eSGordon Ross #define	VSA_DFACL		0x0004
771*8329232eSGordon Ross #define	VSA_DFACLCNT		0x0008
772*8329232eSGordon Ross #define	VSA_ACE			0x0010
773*8329232eSGordon Ross #define	VSA_ACECNT		0x0020
774*8329232eSGordon Ross #define	VSA_ACE_ALLTYPES	0x0040
775*8329232eSGordon Ross #define	VSA_ACE_ACLFLAGS	0x0080	/* get/set ACE ACL flags */
776*8329232eSGordon Ross 
777*8329232eSGordon Ross /*
778*8329232eSGordon Ross  * Structure used by various vnode operations to determine
779*8329232eSGordon Ross  * the context (pid, host, identity) of a caller.
780*8329232eSGordon Ross  *
781*8329232eSGordon Ross  * The cc_caller_id is used to identify one or more callers who invoke
782*8329232eSGordon Ross  * operations, possibly on behalf of others.  For example, the NFS
783*8329232eSGordon Ross  * server could have it's own cc_caller_id which can be detected by
784*8329232eSGordon Ross  * vnode/vfs operations or (FEM) monitors on those operations.  New
785*8329232eSGordon Ross  * caller IDs are generated by fs_new_caller_id().
786*8329232eSGordon Ross  */
787*8329232eSGordon Ross typedef struct caller_context {
788*8329232eSGordon Ross 	pid_t		cc_pid;		/* Process ID of the caller */
789*8329232eSGordon Ross 	int		cc_sysid;	/* System ID, used for remote calls */
790*8329232eSGordon Ross 	u_longlong_t	cc_caller_id;	/* Identifier for (set of) caller(s) */
791*8329232eSGordon Ross 	ulong_t		cc_flags;
792*8329232eSGordon Ross } caller_context_t;
793*8329232eSGordon Ross 
794*8329232eSGordon Ross /*
795*8329232eSGordon Ross  * Flags for caller context.  The caller sets CC_DONTBLOCK if it does not
796*8329232eSGordon Ross  * want to block inside of a FEM monitor.  The monitor will set CC_WOULDBLOCK
797*8329232eSGordon Ross  * and return EAGAIN if the operation would have blocked.
798*8329232eSGordon Ross  */
799*8329232eSGordon Ross #define	CC_WOULDBLOCK	0x01
800*8329232eSGordon Ross #define	CC_DONTBLOCK	0x02
801*8329232eSGordon Ross 
802*8329232eSGordon Ross /*
803*8329232eSGordon Ross  * Structure tags for function prototypes, defined elsewhere.
804*8329232eSGordon Ross  */
805*8329232eSGordon Ross struct pathname;
806*8329232eSGordon Ross struct fid;
807*8329232eSGordon Ross struct flock64;
808*8329232eSGordon Ross struct flk_callback;
809*8329232eSGordon Ross struct shrlock;
810*8329232eSGordon Ross struct page;
811*8329232eSGordon Ross struct seg;
812*8329232eSGordon Ross struct as;
813*8329232eSGordon Ross struct pollhead;
814*8329232eSGordon Ross struct taskq;
815*8329232eSGordon Ross 
816*8329232eSGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL)
817*8329232eSGordon Ross 
818*8329232eSGordon Ross /*
819*8329232eSGordon Ross  * VNODE_OPS defines all the vnode operations.  It is used to define
820*8329232eSGordon Ross  * the vnodeops structure (below) and the fs_func_p union (vfs_opreg.h).
821*8329232eSGordon Ross  */
822*8329232eSGordon Ross #define