xref: /illumos-gate/usr/src/uts/common/sys/vnode.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #ifndef _SYS_VNODE_H
41 #define	_SYS_VNODE_H
42 
43 #pragma ident	"%Z%%M%	%I%	%E% SMI"
44 
45 #include <sys/types.h>
46 #include <sys/t_lock.h>
47 #include <sys/rwstlock.h>
48 #include <sys/time_impl.h>
49 #include <sys/cred.h>
50 #include <sys/uio.h>
51 #include <sys/resource.h>
52 #include <vm/seg_enum.h>
53 #ifdef	_KERNEL
54 #include <sys/buf.h>
55 #endif	/* _KERNEL */
56 
57 #ifdef	__cplusplus
58 extern "C" {
59 #endif
60 
61 
62 typedef int (*fs_generic_func_p) ();
63 
64 /*
65  * File systems use arrays of fs_operation_def structures to form
66  * name/value pairs of operations.  These arrays get passed to:
67  *
68  * 	- vn_make_ops() to create vnodeops
69  * 	- vfs_makefsops()/vfs_setfsops() to create vfsops.
70  */
71 typedef struct fs_operation_def {
72 	char *name;			/* name of operation (NULL at end) */
73 	fs_generic_func_p func;		/* function implementing operation */
74 } fs_operation_def_t;
75 
76 /*
77  * The operation registration mechanism uses two master tables of operations:
78  * one for vnode operations (vn_ops_table[]) and one for vfs operations
79  * (vfs_ops_table[]).  These tables are arrays of fs_operation_trans_def
80  * structures.  They contain all of the information necessary for the system
81  * to populate an operations structure (e.g., vnodeops, vfsops).
82  *
83  * File systems call registration routines (vfs_setfsops(), vfs_makefsops(),
84  * and vn_make_ops()) and pass in their operations specification tables
85  * (arrays of fs_operation_def structures).  These routines use the master
86  * table(s) of operations to build a vnodeops or vfsops structure.
87  */
88 typedef struct fs_operation_trans_def {
89 	char *name;			/* name of operation (NULL at end) */
90 	int offset;			/* byte offset within ops vector */
91 	fs_generic_func_p defaultFunc;	/* default function */
92 	fs_generic_func_p errorFunc; 	/* error function */
93 } fs_operation_trans_def_t;
94 
95 
96 /*
97  * The vnode is the focus of all file activity in UNIX.
98  * A vnode is allocated for each active file, each current
99  * directory, each mounted-on file, and the root.
100  *
101  * Each vnode is usually associated with a file-system-specific node (for
102  * UFS, this is the in-memory inode).  Generally, a vnode and an fs-node
103  * should be created and destroyed together as a pair.
104  *
105  * If a vnode is reused for a new file, it should be reinitialized by calling
106  * either vn_reinit() or vn_recycle().
107  *
108  * vn_reinit() resets the entire vnode as if it was returned by vn_alloc().
109  * The caller is responsible for setting up the entire vnode after calling
110  * vn_reinit().  This is important when using kmem caching where the vnode is
111  * allocated by a constructor, for instance.
112  *
113  * vn_recycle() is used when the file system keeps some state around in both
114  * the vnode and the associated FS-node.  In UFS, for example, the inode of
115  * a deleted file can be reused immediately.  The v_data, v_vfsp, v_op, etc.
116  * remains the same but certain fields related to the previous instance need
117  * to be reset.  In particular:
118  *	v_femhead
119  *	v_path
120  *	v_rdcnt, v_wrcnt
121  *	v_mmap_read, v_mmap_write
122  */
123 
124 /*
125  * vnode types.  VNON means no type.  These values are unrelated to
126  * values in on-disk inodes.
127  */
128 typedef enum vtype {
129 	VNON	= 0,
130 	VREG	= 1,
131 	VDIR	= 2,
132 	VBLK	= 3,
133 	VCHR	= 4,
134 	VLNK	= 5,
135 	VFIFO	= 6,
136 	VDOOR	= 7,
137 	VPROC	= 8,
138 	VSOCK	= 9,
139 	VPORT	= 10,
140 	VBAD	= 11
141 } vtype_t;
142 
143 /*
144  * Many of the fields in the vnode are read-only once they are initialized
145  * at vnode creation time.  Other fields are protected by locks.
146  *
147  * IMPORTANT: vnodes should be created ONLY by calls to vn_alloc().  They
148  * may not be embedded into the file-system specific node (inode).  The
149  * size of vnodes may change.
150  *
151  * The v_lock protects:
152  *   v_flag
153  *   v_stream
154  *   v_count
155  *   v_shrlocks
156  *   v_path
157  *
158  * A special lock (implemented by vn_vfswlock in vnode.c) protects:
159  *   v_vfsmountedhere
160  *
161  * The global flock_lock mutex (in flock.c) protects:
162  *   v_filocks
163  *
164  * IMPORTANT NOTE:
165  *
166  *   The following vnode fields are considered public and may safely be
167  *   accessed by file systems or other consumers:
168  *
169  *     v_lock
170  *     v_flag
171  *     v_count
172  *     v_data
173  *     v_vfsp
174  *     v_stream
175  *     v_type
176  *     v_rdev
177  *
178  * ALL OTHER FIELDS SHOULD BE ACCESSED ONLY BY THE OWNER OF THAT FIELD.
179  * In particular, file systems should not access other fields; they may
180  * change or even be removed.  The functionality which was once provided
181  * by these fields is available through vn_* functions.
182  */
183 
184 struct fem_head;	/* from fem.h */
185 
186 typedef struct vnode {
187 	kmutex_t	v_lock;		/* protects vnode fields */
188 	uint_t		v_flag;		/* vnode flags (see below) */
189 	uint_t		v_count;	/* reference count */
190 	void		*v_data;	/* private data for fs */
191 	struct vfs	*v_vfsp;	/* ptr to containing VFS */
192 	struct stdata	*v_stream;	/* associated stream */
193 	enum vtype	v_type;		/* vnode type */
194 	dev_t		v_rdev;		/* device (VCHR, VBLK) */
195 
196 	/* PRIVATE FIELDS BELOW - DO NOT USE */
197 
198 	struct vfs	*v_vfsmountedhere; /* ptr to vfs mounted here */
199 	struct vnodeops	*v_op;		/* vnode operations */
200 	struct page	*v_pages;	/* vnode pages list */
201 	pgcnt_t		v_npages;	/* # pages on this vnode */
202 	pgcnt_t		v_msnpages;	/* # pages charged to v_mset */
203 	struct page	*v_scanfront;	/* scanner front hand */
204 	struct page	*v_scanback;	/* scanner back hand */
205 	struct filock	*v_filocks;	/* ptr to filock list */
206 	struct shrlocklist *v_shrlocks;	/* ptr to shrlock list */
207 	krwlock_t	v_nbllock;	/* sync for NBMAND locks */
208 	kcondvar_t	v_cv;		/* synchronize locking */
209 	void		*v_locality;	/* hook for locality info */
210 	struct fem_head	*v_femhead;	/* fs monitoring */
211 	char		*v_path;	/* cached path */
212 	uint_t		v_rdcnt;	/* open for read count  (VREG only) */
213 	uint_t		v_wrcnt;	/* open for write count (VREG only) */
214 	u_longlong_t	v_mmap_read;	/* mmap read count */
215 	u_longlong_t	v_mmap_write;	/* mmap write count */
216 	void		*v_mpssdata;	/* info for large page mappings */
217 	hrtime_t	v_scantime;	/* last time this vnode was scanned */
218 	ushort_t	v_mset;		/* memory set ID */
219 	uint_t		v_msflags;	/* memory set flags */
220 	struct vnode	*v_msnext;	/* list of vnodes on an mset */
221 	struct vnode	*v_msprev;	/* list of vnodes on an mset */
222 	krwlock_t	v_mslock;	/* protects v_mset */
223 } vnode_t;
224 
225 #define	IS_DEVVP(vp)	\
226 	((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
227 
228 /*
229  * vnode flags.
230  */
231 #define	VROOT		0x01	/* root of its file system */
232 #define	VNOCACHE	0x02	/* don't keep cache pages on vnode */
233 #define	VNOMAP		0x04	/* file cannot be mapped/faulted */
234 #define	VDUP		0x08	/* file should be dup'ed rather then opened */
235 #define	VNOSWAP		0x10	/* file cannot be used as virtual swap device */
236 #define	VNOMOUNT	0x20	/* file cannot be covered by mount */
237 #define	VISSWAP		0x40	/* vnode is being used for swap */
238 #define	VSWAPLIKE	0x80	/* vnode acts like swap (but may not be) */
239 
240 #define	IS_SWAPVP(vp)	(((vp)->v_flag & (VISSWAP | VSWAPLIKE)) != 0)
241 
242 typedef struct vn_vfslocks_entry {
243 	rwstlock_t ve_lock;
244 	void *ve_vpvfs;
245 	struct vn_vfslocks_entry *ve_next;
246 	uint32_t ve_refcnt;
247 	char pad[64 - sizeof (rwstlock_t) - 2 * sizeof (void *) - \
248 	    sizeof (uint32_t)];
249 } vn_vfslocks_entry_t;
250 
251 /*
252  * The following two flags are used to lock the v_vfsmountedhere field
253  */
254 #define	VVFSLOCK	0x100
255 #define	VVFSWAIT	0x200
256 
257 /*
258  * Used to serialize VM operations on a vnode
259  */
260 #define	VVMLOCK		0x400
261 
262 /*
263  * Tell vn_open() not to fail a directory open for writing but
264  * to go ahead and call VOP_OPEN() to let the filesystem check.
265  */
266 #define	VDIROPEN	0x800
267 
268 /*
269  * Flag to let the VM system know that this file is most likely a binary
270  * or shared library since it has been mmap()ed EXEC at some time.
271  */
272 #define	VVMEXEC		0x1000
273 
274 #define	VPXFS		0x2000  /* clustering: global fs proxy vnode */
275 
276 #define	IS_PXFSVP(vp)	((vp)->v_flag & VPXFS)
277 
278 #define	V_XATTRDIR	0x4000	/* attribute unnamed directory */
279 
280 #define	V_LOCALITY	0x8000	/* whether locality aware */
281 
282 /*
283  * Flag that indicates the VM should maintain the v_pages list with all modified
284  * pages on one end and unmodified pages at the other. This makes finding dirty
285  * pages to write back to disk much faster at the expense of taking a minor
286  * fault on the first store instruction which touches a writable page.
287  */
288 #define	VMODSORT	(0x10000)
289 #define	IS_VMODSORT(vp) \
290 	(pvn_vmodsort_supported != 0 && ((vp)->v_flag  & VMODSORT) != 0)
291 
292 #define	VISSWAPFS	0x20000	/* vnode is being used for swapfs */
293 #define	IS_SWAPFSVP(vp)	(((vp)->v_flag & VISSWAPFS) != 0)
294 
295 /*
296  * Vnode attributes.  A bit-mask is supplied as part of the
297  * structure to indicate the attributes the caller wants to
298  * set (setattr) or extract (getattr).
299  */
300 
301 /*
302  * Note that va_nodeid and va_nblocks are 64bit data type.
303  * We support large files over NFSV3. With Solaris client and
304  * Server that generates 64bit ino's and sizes these fields
305  * will overflow if they are 32 bit sizes.
306  */
307 
308 typedef struct vattr {
309 	uint_t		va_mask;	/* bit-mask of attributes */
310 	vtype_t		va_type;	/* vnode type (for create) */
311 	mode_t		va_mode;	/* file access mode */
312 	uid_t		va_uid;		/* owner user id */
313 	gid_t		va_gid;		/* owner group id */
314 	dev_t		va_fsid;	/* file system id (dev for now) */
315 	u_longlong_t	va_nodeid;	/* node id */
316 	nlink_t		va_nlink;	/* number of references to file */
317 	u_offset_t	va_size;	/* file size in bytes */
318 	timestruc_t	va_atime;	/* time of last access */
319 	timestruc_t	va_mtime;	/* time of last modification */
320 	timestruc_t	va_ctime;	/* time of last status change */
321 	dev_t		va_rdev;	/* device the file represents */
322 	uint_t		va_blksize;	/* fundamental block size */
323 	u_longlong_t	va_nblocks;	/* # of blocks allocated */
324 	uint_t		va_seq;		/* sequence number */
325 } vattr_t;
326 
327 #ifdef _SYSCALL32
328 /*
329  * For bigtypes time_t changed to 64 bit on the 64-bit kernel.
330  * Define an old version for user/kernel interface
331  */
332 
333 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
334 #pragma pack(4)
335 #endif
336 
337 typedef struct vattr32 {
338 	uint32_t	va_mask;	/* bit-mask of attributes */
339 	vtype_t		va_type;	/* vnode type (for create) */
340 	mode32_t	va_mode;	/* file access mode */
341 	uid32_t		va_uid;		/* owner user id */
342 	gid32_t		va_gid;		/* owner group id */
343 	dev32_t		va_fsid;	/* file system id (dev for now) */
344 	u_longlong_t	va_nodeid;	/* node id */
345 	nlink_t		va_nlink;	/* number of references to file */
346 	u_offset_t	va_size;	/* file size in bytes */
347 	timestruc32_t	va_atime;	/* time of last access */
348 	timestruc32_t	va_mtime;	/* time of last modification */
349 	timestruc32_t	va_ctime;	/* time of last status change */
350 	dev32_t		va_rdev;	/* device the file represents */
351 	uint32_t	va_blksize;	/* fundamental block size */
352 	u_longlong_t	va_nblocks;	/* # of blocks allocated */
353 	uint32_t	va_seq;		/* sequence number */
354 } vattr32_t;
355 
356 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
357 #pragma pack()
358 #endif
359 
360 #else  /* not _SYSCALL32 */
361 #define	vattr32		vattr
362 typedef vattr_t		vattr32_t;
363 #endif /* _SYSCALL32 */
364 
365 /*
366  * Attributes of interest to the caller of setattr or getattr.
367  */
368 #define	AT_TYPE		0x0001
369 #define	AT_MODE		0x0002
370 #define	AT_UID		0x0004
371 #define	AT_GID		0x0008
372 #define	AT_FSID		0x0010
373 #define	AT_NODEID	0x0020
374 #define	AT_NLINK	0x0040
375 #define	AT_SIZE		0x0080
376 #define	AT_ATIME	0x0100
377 #define	AT_MTIME	0x0200
378 #define	AT_CTIME	0x0400
379 #define	AT_RDEV		0x0800
380 #define	AT_BLKSIZE	0x1000
381 #define	AT_NBLOCKS	0x2000
382 /*			0x4000 */	/* unused */
383 #define	AT_SEQ		0x8000
384 
385 #define	AT_ALL		(AT_TYPE|AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|\
386 			AT_NLINK|AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|\
387 			AT_RDEV|AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
388 
389 #define	AT_STAT		(AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\
390 			AT_SIZE|AT_ATIME|AT_MTIME|AT_CTIME|AT_RDEV|AT_TYPE)
391 
392 #define	AT_TIMES	(AT_ATIME|AT_MTIME|AT_CTIME)
393 
394 #define	AT_NOSET	(AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
395 			AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
396 
397 /*
398  *  Modes.  Some values same as S_xxx entries from stat.h for convenience.
399  */
400 #define	VSUID		04000		/* set user id on execution */
401 #define	VSGID		02000		/* set group id on execution */
402 #define	VSVTX		01000		/* save swapped text even after use */
403 
404 /*
405  * Permissions.
406  */
407 #define	VREAD		00400
408 #define	VWRITE		00200
409 #define	VEXEC		00100
410 
411 #define	MODEMASK	07777		/* mode bits plus permission bits */
412 #define	PERMMASK	00777		/* permission bits */
413 
414 /*
415  * Check whether mandatory file locking is enabled.
416  */
417 
418 #define	MANDMODE(mode)		(((mode) & (VSGID|(VEXEC>>3))) == VSGID)
419 #define	MANDLOCK(vp, mode)	((vp)->v_type == VREG && MANDMODE(mode))
420 
421 /*
422  * Flags for vnode operations.
423  */
424 enum rm		{ RMFILE, RMDIRECTORY };	/* rm or rmdir (remove) */
425 enum symfollow	{ NO_FOLLOW, FOLLOW };		/* follow symlinks (or not) */
426 enum vcexcl	{ NONEXCL, EXCL };		/* (non)excl create */
427 enum create	{ CRCREAT, CRMKNOD, CRMKDIR };	/* reason for create */
428 
429 typedef enum rm		rm_t;
430 typedef enum symfollow	symfollow_t;
431 typedef enum vcexcl	vcexcl_t;
432 typedef enum create	create_t;
433 
434 /* Vnode Events - Used by VOP_VNEVENT */
435 typedef enum vnevent	{
436 	VE_SUPPORT	= 0,	/* Query */
437 	VE_RENAME_SRC	= 1,	/* Rename, with vnode as source */
438 	VE_RENAME_DEST	= 2,	/* Rename, with vnode as target/destination */
439 	VE_REMOVE	= 3,	/* Remove of vnode's name */
440 	VE_RMDIR	= 4	/* Remove of directory vnode's name */
441 } vnevent_t;
442 
443 /*
444  * Values for checking vnode open and map counts
445  */
446 enum v_mode { V_READ, V_WRITE, V_RDORWR, V_RDANDWR };
447 
448 typedef enum v_mode v_mode_t;
449 
450 #define	V_TRUE	1
451 #define	V_FALSE	0
452 
453 /*
454  * Structure used on VOP_GETSECATTR and VOP_SETSECATTR operations
455  */
456 
457 typedef struct vsecattr {
458 	uint_t		vsa_mask;	/* See below */
459 	int		vsa_aclcnt;	/* ACL entry count */
460 	void		*vsa_aclentp;	/* pointer to ACL entries */
461 	int		vsa_dfaclcnt;	/* default ACL entry count */
462 	void		*vsa_dfaclentp;	/* pointer to default ACL entries */
463 } vsecattr_t;
464 
465 /* vsa_mask values */
466 #define	VSA_ACL		0x0001
467 #define	VSA_ACLCNT	0x0002
468 #define	VSA_DFACL	0x0004
469 #define	VSA_DFACLCNT	0x0008
470 #define	VSA_ACE		0x0010
471 #define	VSA_ACECNT	0x0020
472 
473 /*
474  * Structure used by various vnode operations to determine
475  * the context (pid, host, identity) of a caller.
476  *
477  * The cc_caller_id is used to identify one or more callers who invoke
478  * operations, possibly on behalf of others.  For example, the NFS
479  * server could have it's own cc_caller_id which can be detected by
480  * vnode/vfs operations or (FEM) monitors on those operations.  New
481  * caller IDs are generated by fs_new_caller_id().
482  */
483 typedef struct caller_context {
484 	pid_t		cc_pid;		/* Process ID of the caller */
485 	int		cc_sysid;	/* System ID, used for remote calls */
486 	u_longlong_t	cc_caller_id;	/* Identifier for (set of) caller(s) */
487 } caller_context_t;
488 
489 /*
490  * Structure tags for function prototypes, defined elsewhere.
491  */
492 struct pathname;
493 struct fid;
494 struct flock64;
495 struct flk_callback;
496 struct shrlock;
497 struct page;
498 struct seg;
499 struct as;
500 struct pollhead;
501 
502 /*
503  * Operations on vnodes.  Note: File systems should never operate directly
504  * on a 'vnodeops' structure -- it WILL change in future releases!  They
505  * should use vn_make_ops() to create the structure.
506  */
507 typedef struct vnodeops {
508 	const char *vnop_name;
509 	int	(*vop_open)(vnode_t **, int, cred_t *);
510 	int	(*vop_close)(vnode_t *, int, int, offset_t, cred_t *);
511 	int	(*vop_read)(vnode_t *, uio_t *, int, cred_t *,
512 				caller_context_t *);
513 	int	(*vop_write)(vnode_t *, uio_t *, int, cred_t *,
514 				caller_context_t *);
515 	int	(*vop_ioctl)(vnode_t *, int, intptr_t, int, cred_t *, int *);
516 	int	(*vop_setfl)(vnode_t *, int, int, cred_t *);
517 	int	(*vop_getattr)(vnode_t *, vattr_t *, int, cred_t *);
518 	int	(*vop_setattr)(vnode_t *, vattr_t *, int, cred_t *,
519 				caller_context_t *);
520 	int	(*vop_access)(vnode_t *, int, int, cred_t *);
521 	int	(*vop_lookup)(vnode_t *, char *, vnode_t **, struct pathname *,
522 				int, vnode_t *, cred_t *);
523 	int	(*vop_create)(vnode_t *, char *, vattr_t *, vcexcl_t, int,
524 				vnode_t **, cred_t *, int);
525 	int	(*vop_remove)(vnode_t *, char *, cred_t *);
526 	int	(*vop_link)(vnode_t *, vnode_t *, char *, cred_t *);
527 	int	(*vop_rename)(vnode_t *, char *, vnode_t *, char *, cred_t *);
528 	int	(*vop_mkdir)(vnode_t *, char *, vattr_t *, vnode_t **,
529 				cred_t *);
530 	int	(*vop_rmdir)(vnode_t *, char *, vnode_t *, cred_t *);
531 	int	(*vop_readdir)(vnode_t *, uio_t *, cred_t *, int *);
532 	int	(*vop_symlink)(vnode_t *, char *, vattr_t *, char *, cred_t *);
533 	int	(*vop_readlink)(vnode_t *, uio_t *, cred_t *);
534 	int	(*vop_fsync)(vnode_t *, int, cred_t *);
535 	void	(*vop_inactive)(vnode_t *, cred_t *);
536 	int	(*vop_fid)(vnode_t *, struct fid *);
537 	int	(*vop_rwlock)(vnode_t *, int, caller_context_t *);
538 	void	(*vop_rwunlock)(vnode_t *, int, caller_context_t *);
539 	int	(*vop_seek)(vnode_t *, offset_t, offset_t *);
540 	int	(*vop_cmp)(vnode_t *, vnode_t *);
541 	int	(*vop_frlock)(vnode_t *, int, struct flock64 *, int, offset_t,
542 				struct flk_callback *, cred_t *);
543 	int	(*vop_space)(vnode_t *, int, struct flock64 *, int, offset_t,
544 				cred_t *, caller_context_t *);
545 	int	(*vop_realvp)(vnode_t *, vnode_t **);
546 	int	(*vop_getpage)(vnode_t *, offset_t, size_t, uint_t *,
547 				struct page **, size_t, struct seg *,
548 				caddr_t, enum seg_rw, cred_t *);
549 	int	(*vop_putpage)(vnode_t *, offset_t, size_t, int, cred_t *);
550 	int	(*vop_map)(vnode_t *, offset_t, struct as *, caddr_t *, size_t,
551 				uchar_t, uchar_t, uint_t, cred_t *);
552 	int	(*vop_addmap)(vnode_t *, offset_t, struct as *, caddr_t, size_t,
553 				uchar_t, uchar_t, uint_t, cred_t *);
554 	int	(*vop_delmap)(vnode_t *, offset_t, struct as *, caddr_t, size_t,
555 				uint_t, uint_t, uint_t, cred_t *);
556 	int	(*vop_poll)(vnode_t *, short, int, short *, struct pollhead **);
557 	int	(*vop_dump)(vnode_t *, caddr_t, int, int);
558 	int	(*vop_pathconf)(vnode_t *, int, ulong_t *, cred_t *);
559 	int	(*vop_pageio)(vnode_t *, struct page *, u_offset_t, size_t,
560 				int, cred_t *);
561 	int	(*vop_dumpctl)(vnode_t *, int, int *);
562 	void	(*vop_dispose)(vnode_t *, struct page *, int, int, cred_t *);
563 	int	(*vop_setsecattr)(vnode_t *, vsecattr_t *, int, cred_t *);
564 	int	(*vop_getsecattr)(vnode_t *, vsecattr_t *, int, cred_t *);
565 	int	(*vop_shrlock)(vnode_t *, int, struct shrlock *, int, cred_t *);
566 	int	(*vop_vnevent)(vnode_t *, vnevent_t);
567 } vnodeops_t;
568 
569 #ifdef	_KERNEL
570 
571 extern int	fop_open(vnode_t **, int, cred_t *);
572 extern int	fop_close(vnode_t *, int, int, offset_t, cred_t *);
573 extern int	fop_read(vnode_t *, uio_t *, int, cred_t *, caller_context_t *);
574 extern int	fop_write(vnode_t *, uio_t *, int, cred_t *,
575 				caller_context_t *);
576 extern int	fop_ioctl(vnode_t *, int, intptr_t, int, cred_t *, int *);
577 extern int	fop_setfl(vnode_t *, int, int, cred_t *);
578 extern int	fop_getattr(vnode_t *, vattr_t *, int, cred_t *);
579 extern int	fop_setattr(vnode_t *, vattr_t *, int, cred_t *,
580 				caller_context_t *);
581 extern int	fop_access(vnode_t *, int, int, cred_t *);
582 extern int	fop_lookup(vnode_t *, char *, vnode_t **, struct pathname *,
583 				int, vnode_t *, cred_t *);
584 extern int	fop_create(vnode_t *, char *, vattr_t *, vcexcl_t, int,
585 				vnode_t **, cred_t *, int);
586 extern int	fop_remove(vnode_t *vp, char *, cred_t *);
587 extern int	fop_link(vnode_t *, vnode_t *, char *, cred_t *);
588 extern int	fop_rename(vnode_t *, char *, vnode_t *, char *, cred_t *);
589 extern int	fop_mkdir(vnode_t *, char *, vattr_t *, vnode_t **, cred_t *);
590 extern int	fop_rmdir(vnode_t *, char *, vnode_t *, cred_t *);
591 extern int	fop_readdir(vnode_t *, uio_t *, cred_t *, int *);
592 extern int	fop_symlink(vnode_t *, char *, vattr_t *, char *, cred_t *);
593 extern int	fop_readlink(vnode_t *, uio_t *, cred_t *);
594 extern int	fop_fsync(vnode_t *, int, cred_t *);
595 extern void	fop_inactive(vnode_t *, cred_t *);
596 extern int	fop_fid(vnode_t *, struct fid *);
597 extern int	fop_rwlock(vnode_t *, int, caller_context_t *);
598 extern void	fop_rwunlock(vnode_t *, int, caller_context_t *);
599 extern int	fop_seek(vnode_t *, offset_t, offset_t *);
600 extern int	fop_cmp(vnode_t *, vnode_t *);
601 extern int	fop_frlock(vnode_t *, int, struct flock64 *, int, offset_t,
602 				struct flk_callback *, cred_t *);
603 extern int	fop_space(vnode_t *, int, struct flock64 *, int, offset_t,
604 				cred_t *, caller_context_t *);
605 extern int	fop_realvp(vnode_t *, vnode_t **);
606 extern int	fop_getpage(vnode_t *, offset_t, size_t, uint_t *,
607 				struct page **, size_t, struct seg *,
608 				caddr_t, enum seg_rw, cred_t *);
609 extern int	fop_putpage(vnode_t *, offset_t, size_t, int, cred_t *);
610 extern int	fop_map(vnode_t *, offset_t, struct as *, caddr_t *, size_t,
611 				uchar_t, uchar_t, uint_t, cred_t *cr);
612 extern int	fop_addmap(vnode_t *, offset_t, struct as *, caddr_t, size_t,
613 				uchar_t, uchar_t, uint_t, cred_t *);
614 extern int	fop_delmap(vnode_t *, offset_t, struct as *, caddr_t, size_t,
615 				uint_t, uint_t, uint_t, cred_t *);
616 extern int	fop_poll(vnode_t *, short, int, short *, struct pollhead **);
617 extern int	fop_dump(vnode_t *, caddr_t, int, int);
618 extern int	fop_pathconf(vnode_t *, int, ulong_t *, cred_t *);
619 extern int	fop_pageio(vnode_t *, struct page *, u_offset_t, size_t, int,
620 				cred_t *);
621 extern int	fop_dumpctl(vnode_t *, int, int *);
622 extern void	fop_dispose(vnode_t *, struct page *, int, int, cred_t *);
623 extern int	fop_setsecattr(vnode_t *, vsecattr_t *, int, cred_t *);
624 extern int	fop_getsecattr(vnode_t *, vsecattr_t *, int, cred_t *);
625 extern int	fop_shrlock(vnode_t *, int, struct shrlock *, int, cred_t *);
626 extern int	fop_vnevent(vnode_t *, vnevent_t);
627 
628 #endif	/* _KERNEL */
629 
630 #define	VOP_OPEN(vpp, mode, cr) \
631 	fop_open(vpp, mode, cr)
632 #define	VOP_CLOSE(vp, f, c, o, cr) \
633 	fop_close(vp, f, c, o, cr)
634 #define	VOP_READ(vp, uiop, iof, cr, ct) \
635 	fop_read(vp, uiop, iof, cr, ct)
636 #define	VOP_WRITE(vp, uiop, iof, cr, ct) \
637 	fop_write(vp, uiop, iof, cr, ct)
638 #define	VOP_IOCTL(vp, cmd, a, f, cr, rvp) \
639 	fop_ioctl(vp, cmd, a, f, cr, rvp)
640 #define	VOP_SETFL(vp, f, a, cr) \
641 	fop_setfl(vp, f, a, cr)
642 #define	VOP_GETATTR(vp, vap, f, cr) \
643 	fop_getattr(vp, vap, f, cr)
644 #define	VOP_SETATTR(vp, vap, f, cr, ct) \
645 	fop_setattr(vp, vap, f, cr, ct)
646 #define	VOP_ACCESS(vp, mode, f, cr) \
647 	fop_access(vp, mode, f, cr)
648 #define	VOP_LOOKUP(vp, cp, vpp, pnp, f, rdir, cr) \
649 	fop_lookup(vp, cp, vpp, pnp, f, rdir, cr)
650 #define	VOP_CREATE(dvp, p, vap, ex, mode, vpp, cr, flag) \
651 	fop_create(dvp, p, vap, ex, mode, vpp, cr, flag)
652 #define	VOP_REMOVE(dvp, p, cr) \
653 	fop_remove(dvp, p, cr)
654 #define	VOP_LINK(tdvp, fvp, p, cr) \
655 	fop_link(tdvp, fvp, p, cr)
656 #define	VOP_RENAME(fvp, fnm, tdvp, tnm, cr) \
657 	fop_rename(fvp, fnm, tdvp, tnm, cr)
658 #define	VOP_MKDIR(dp, p, vap, vpp, cr) \
659 	fop_mkdir(dp, p, vap, vpp, cr)
660 #define	VOP_RMDIR(dp, p, cdir, cr) \
661 	fop_rmdir(dp, p, cdir, cr)
662 #define	VOP_READDIR(vp, uiop, cr, eofp) \
663 	fop_readdir(vp, uiop, cr, eofp)
664 #define	VOP_SYMLINK(dvp, lnm, vap, tnm, cr) \
665 	fop_symlink(dvp, lnm, vap, tnm, cr)
666 #define	VOP_READLINK(vp, uiop, cr) \
667 	fop_readlink(vp, uiop, cr)
668 #define	VOP_FSYNC(vp, syncflag, cr) \
669 	fop_fsync(vp, syncflag, cr)
670 #define	VOP_INACTIVE(vp, cr) \
671 	fop_inactive(vp, cr)
672 #define	VOP_FID(vp, fidp) \
673 	fop_fid(vp, fidp)
674 #define	VOP_RWLOCK(vp, w, ct) \
675 	fop_rwlock(vp, w, ct)
676 #define	VOP_RWUNLOCK(vp, w, ct) \
677 	fop_rwunlock(vp, w, ct)
678 #define	VOP_SEEK(vp, ooff, noffp) \
679 	fop_seek(vp, ooff, noffp)
680 #define	VOP_CMP(vp1, vp2) \
681 	fop_cmp(vp1, vp2)
682 #define	VOP_FRLOCK(vp, cmd, a, f, o, cb, cr) \
683 	fop_frlock(vp, cmd, a, f, o, cb, cr)
684 #define	VOP_SPACE(vp, cmd, a, f, o, cr, ct) \
685 	fop_space(vp, cmd, a, f, o, cr, ct)
686 #define	VOP_REALVP(vp1, vp2) \
687 	fop_realvp(vp1, vp2)
688 #define	VOP_GETPAGE(vp, of, sz, pr, pl, ps, sg, a, rw, cr) \
689 	fop_getpage(vp, of, sz, pr, pl, ps, sg, a, rw, cr)
690 #define	VOP_PUTPAGE(vp, of, sz, fl, cr) \
691 	fop_putpage(vp, of, sz, fl, cr)
692 #define	VOP_MAP(vp, of, as, a, sz, p, mp, fl, cr) \
693 	fop_map(vp, of, as, a, sz, p, mp, fl, cr)
694 #define	VOP_ADDMAP(vp, of, as, a, sz, p, mp, fl, cr) \
695 	fop_addmap(vp, of, as, a, sz, p, mp, fl, cr)
696 #define	VOP_DELMAP(vp, of, as, a, sz, p, mp, fl, cr) \
697 	fop_delmap(vp, of, as, a, sz, p, mp, fl, cr)
698 #define	VOP_POLL(vp, events, anyyet, reventsp, phpp) \
699 	fop_poll(vp, events, anyyet, reventsp, phpp)
700 #define	VOP_DUMP(vp, addr, bn, count) \
701 	fop_dump(vp, addr, bn, count)
702 #define	VOP_PATHCONF(vp, cmd, valp, cr) \
703 	fop_pathconf(vp, cmd, valp, cr)
704 #define	VOP_PAGEIO(vp, pp, io_off, io_len, flags, cr) \
705 	fop_pageio(vp, pp, io_off, io_len, flags, cr)
706 #define	VOP_DUMPCTL(vp, action, blkp) \
707 	fop_dumpctl(vp, action, blkp)
708 #define	VOP_DISPOSE(vp, pp, flag, dn, cr) \
709 	fop_dispose(vp, pp, flag, dn, cr)
710 #define	VOP_GETSECATTR(vp, vsap, f, cr) \
711 	fop_getsecattr(vp, vsap, f, cr)
712 #define	VOP_SETSECATTR(vp, vsap, f, cr) \
713 	fop_setsecattr(vp, vsap, f, cr)
714 #define	VOP_SHRLOCK(vp, cmd, shr, f, cr) \
715 	fop_shrlock(vp, cmd, shr, f, cr)
716 #define	VOP_VNEVENT(vp, vnevent) \
717 	fop_vnevent(vp, vnevent)
718 
719 #define	VOPNAME_OPEN		"open"
720 #define	VOPNAME_CLOSE		"close"
721 #define	VOPNAME_READ		"read"
722 #define	VOPNAME_WRITE		"write"
723 #define	VOPNAME_IOCTL		"ioctl"
724 #define	VOPNAME_SETFL		"setfl"
725 #define	VOPNAME_GETATTR		"getattr"
726 #define	VOPNAME_SETATTR		"setattr"
727 #define	VOPNAME_ACCESS		"access"
728 #define	VOPNAME_LOOKUP		"lookup"
729 #define	VOPNAME_CREATE		"create"
730 #define	VOPNAME_REMOVE		"remove"
731 #define	VOPNAME_LINK		"link"
732 #define	VOPNAME_RENAME		"rename"
733 #define	VOPNAME_MKDIR		"mkdir"
734 #define	VOPNAME_RMDIR		"rmdir"
735 #define	VOPNAME_READDIR		"readdir"
736 #define	VOPNAME_SYMLINK		"symlink"
737 #define	VOPNAME_READLINK	"readlink"
738 #define	VOPNAME_FSYNC		"fsync"
739 #define	VOPNAME_INACTIVE	"inactive"
740 #define	VOPNAME_FID		"fid"
741 #define	VOPNAME_RWLOCK		"rwlock"
742 #define	VOPNAME_RWUNLOCK	"rwunlock"
743 #define	VOPNAME_SEEK		"seek"
744 #define	VOPNAME_CMP		"cmp"
745 #define	VOPNAME_FRLOCK		"frlock"
746 #define	VOPNAME_SPACE		"space"
747 #define	VOPNAME_REALVP		"realvp"
748 #define	VOPNAME_GETPAGE		"getpage"
749 #define	VOPNAME_PUTPAGE		"putpage"
750 #define	VOPNAME_MAP		"map"
751 #define	VOPNAME_ADDMAP		"addmap"
752 #define	VOPNAME_DELMAP		"delmap"
753 #define	VOPNAME_POLL		"poll"
754 #define	VOPNAME_DUMP		"dump"
755 #define	VOPNAME_PATHCONF	"pathconf"
756 #define	VOPNAME_PAGEIO		"pageio"
757 #define	VOPNAME_DUMPCTL		"dumpctl"
758 #define	VOPNAME_DISPOSE		"dispose"
759 #define	VOPNAME_GETSECATTR	"getsecattr"
760 #define	VOPNAME_SETSECATTR	"setsecattr"
761 #define	VOPNAME_SHRLOCK		"shrlock"
762 #define	VOPNAME_VNEVENT		"vnevent"
763 
764 /*
765  * Flags for VOP_LOOKUP
766  */
767 #define	LOOKUP_DIR		0x01	/* want parent dir vp */
768 #define	LOOKUP_XATTR		0x02	/* lookup up extended attr dir */
769 #define	CREATE_XATTR_DIR	0x04	/* Create extended attr dir */
770 
771 /*
772  * Flags for VOP_RWLOCK/VOP_RWUNLOCK
773  * VOP_RWLOCK will return the flag that was actually set, or -1 if none.
774  */
775 #define	V_WRITELOCK_TRUE	(1)	/* Request write-lock on the vnode */
776 #define	V_WRITELOCK_FALSE	(0)	/* Request read-lock on the vnode */
777 
778 /*
779  * Flags for VOP_DUMPCTL
780  */
781 #define	DUMP_ALLOC	0
782 #define	DUMP_FREE	1
783 #define	DUMP_SCAN	2
784 
785 /*
786  * Public vnode manipulation functions.
787  */
788 #ifdef	_KERNEL
789 
790 vnode_t *vn_alloc(int);
791 void	vn_reinit(vnode_t *);
792 void	vn_recycle(vnode_t *);
793 void	vn_free(vnode_t *);
794 
795 int	vn_is_readonly(vnode_t *);
796 int   	vn_is_opened(vnode_t *, v_mode_t);
797 int   	vn_is_mapped(vnode_t *, v_mode_t);
798 
799 int	vn_can_change_zones(vnode_t *vp);
800 
801 int	vn_has_flocks(vnode_t *);
802 int	vn_has_mandatory_locks(vnode_t *, int);
803 int	vn_has_cached_data(vnode_t *);
804 
805 void	vn_setops(vnode_t *, vnodeops_t *);
806 vnodeops_t *vn_getops(vnode_t *);
807 int	vn_matchops(vnode_t *, vnodeops_t *);
808 int	vn_matchopval(vnode_t *, char *, fs_generic_func_p);
809 int	vn_ismntpt(vnode_t *);
810 
811 struct vfs *vn_mountedvfs(vnode_t *);
812 
813 void	vn_create_cache(void);
814 void	vn_destroy_cache(void);
815 
816 int	vn_make_ops(const char *, const fs_operation_def_t *, vnodeops_t **);
817 void	vn_freevnodeops(vnodeops_t *);
818 
819 int	vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode,
820 		struct vnode **vpp, enum create crwhy, mode_t umask);
821 int	vn_openat(char *pnamep, enum uio_seg seg, int filemode, int createmode,
822 		struct vnode **vpp, enum create crwhy,
823 		mode_t umask, struct vnode *startvp);
824 int	vn_create(char *pnamep, enum uio_seg seg, struct vattr *vap,
825 		enum vcexcl excl, int mode, struct vnode **vpp,
826 		enum create why, int flag, mode_t umask);
827 int	vn_createat(char *pnamep, enum uio_seg seg, struct vattr *vap,
828 		enum vcexcl excl, int mode, struct vnode **vpp,
829 		enum create why, int flag, mode_t umask, struct vnode *startvp);
830 int	vn_rdwr(enum uio_rw rw, struct vnode *vp, caddr_t base, ssize_t len,
831 		offset_t offset, enum uio_seg seg, int ioflag, rlim64_t ulimit,
832 		cred_t *cr, ssize_t *residp);
833 void	vn_rele(struct vnode *vp);
834 void	vn_rele_stream(struct vnode *vp);
835 int	vn_link(char *from, char *to, enum uio_seg seg);
836 int	vn_rename(char *from, char *to, enum uio_seg seg);
837 int	vn_renameat(vnode_t *fdvp, char *fname, vnode_t *tdvp, char *tname,
838 		enum uio_seg seg);
839 int	vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag);
840 int	vn_removeat(vnode_t *startvp, char *fnamep, enum uio_seg seg,
841 		enum rm dirflag);
842 int	vn_compare(vnode_t *vp1, vnode_t *vp2);
843 int	vn_vfslock(struct vnode *vp);
844 int	vn_vfswlock(struct vnode *vp);
845 int	vn_vfswlock_wait(struct vnode *vp);
846 int	vn_vfsrlock(struct vnode *vp);
847 int	vn_vfsrlock_wait(struct vnode *vp);
848 void	vn_vfsunlock(struct vnode *vp);
849 int	vn_vfswlock_held(struct vnode *vp);
850 vnode_t *specvp(struct vnode *vp, dev_t dev, vtype_t type, struct cred *cr);
851 vnode_t *makespecvp(dev_t dev, vtype_t type);
852 vn_vfslocks_entry_t *vn_vfslocks_getlock(void *);
853 void	vn_vfslocks_rele(vn_vfslocks_entry_t *);
854 
855 /* Vnode event notification */
856 void	vnevent_rename_src(vnode_t *);
857 void	vnevent_rename_dest(vnode_t *);
858 void	vnevent_remove(vnode_t *);
859 void	vnevent_rmdir(vnode_t *);
860 int	vnevent_support(vnode_t *);
861 
862 /* Context identification */
863 u_longlong_t	fs_new_caller_id();
864 
865 char	*vn_path(struct vnode *vp);
866 void	vn_setpath(struct vnode *rootvp, struct vnode *startvp,
867     struct vnode *vp, const char *path, size_t len);
868 void	vn_setpath_str(struct vnode *vp, const char *str, size_t len);
869 
870 /*
871  * This macro should be used instead of calling vn_setpath() directly.  It
872  * optimizes for the common case, where the vnode already has a path.
873  */
874 #define	VN_SETPATH(rvp, svp, vp, p, len) {			\
875 	if (vn_path(vp) == NULL)				\
876 		vn_setpath((rvp), (svp), (vp), (p), (len));	\
877 }
878 
879 void	vn_copypath(struct vnode *src, struct vnode *dst);
880 
881 int	vn_vmpss_usepageio(vnode_t *);
882 
883 /*
884  * Needed for use of IS_VMODSORT() in kernel.
885  */
886 extern uint_t pvn_vmodsort_supported;
887 
888 #define	VN_HOLD(vp)	{ \
889 	mutex_enter(&(vp)->v_lock); \
890 	(vp)->v_count++; \
891 	mutex_exit(&(vp)->v_lock); \
892 }
893 
894 #define	VN_RELE(vp)	{ \
895 	vn_rele(vp); \
896 }
897 
898 #define	VN_SET_VFS_TYPE_DEV(vp, vfsp, type, dev)	{ \
899 	(vp)->v_vfsp = (vfsp); \
900 	(vp)->v_type = (type); \
901 	(vp)->v_rdev = (dev); \
902 }
903 
904 /*
905  * Compare two vnodes for equality.  In general this macro should be used
906  * in preference to calling VOP_CMP directly.
907  */
908 #define	VN_CMP(VP1, VP2)	((VP1) == (VP2) ? 1 : 	\
909 	((VP1) && (VP2) && (vn_getops(VP1) == vn_getops(VP2)) ? \
910 	VOP_CMP(VP1, VP2) : 0))
911 
912 #endif	/* _KERNEL */
913 
914 /*
915  * Flags to VOP_SETATTR/VOP_GETATTR.
916  */
917 #define	ATTR_UTIME	0x01	/* non-default utime(2) request */
918 #define	ATTR_EXEC	0x02	/* invocation from exec(2) */
919 #define	ATTR_COMM	0x04	/* yield common vp attributes */
920 #define	ATTR_HINT	0x08	/* information returned will be `hint' */
921 #define	ATTR_REAL	0x10	/* yield attributes of the real vp */
922 
923 /*
924  * Generally useful macros.
925  */
926 #define	VBSIZE(vp)	((vp)->v_vfsp->vfs_bsize)
927 #define	VTOZ(vp)	((vp)->v_vfsp->vfs_zone)
928 #define	NULLVP		((struct vnode *)0)
929 #define	NULLVPP		((struct vnode **)0)
930 
931 #ifdef	_KERNEL
932 
933 /*
934  * Structure used while handling asynchronous VOP_PUTPAGE operations.
935  */
936 struct async_reqs {
937 	struct async_reqs *a_next;	/* pointer to next arg struct */
938 	struct vnode *a_vp;		/* vnode pointer */
939 	u_offset_t a_off;			/* offset in file */
940 	uint_t a_len;			/* size of i/o request */
941 	int a_flags;			/* flags to indicate operation type */
942 	struct cred *a_cred;		/* cred pointer	*/
943 	ushort_t a_prealloced;		/* set if struct is pre-allocated */
944 };
945 
946 /*
947  * VN_DISPOSE() -- given a page pointer, safely invoke VOP_DISPOSE().
948  */
949 #define	VN_DISPOSE(pp, flag, dn, cr)	{ \
950 	extern struct vnode kvp; \
951 	if ((pp)->p_vnode != NULL && (pp)->p_vnode != &kvp) \
952 		VOP_DISPOSE((pp)->p_vnode, (pp), (flag), (dn), (cr)); \
953 	else if ((flag) == B_FREE) \
954 		page_free((pp), (dn)); \
955 	else \
956 		page_destroy((pp), (dn)); \
957 	}
958 
959 #endif	/* _KERNEL */
960 
961 #ifdef	__cplusplus
962 }
963 #endif
964 
965 #endif	/* _SYS_VNODE_H */
966