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