Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: vnode.h,v 1.305 2026/03/21 14:26:06 yamt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 /*
     30  * Copyright (c) 1989, 1993
     31  *	The Regents of the University of California.  All rights reserved.
     32  *
     33  * Redistribution and use in source and binary forms, with or without
     34  * modification, are permitted provided that the following conditions
     35  * are met:
     36  * 1. Redistributions of source code must retain the above copyright
     37  *    notice, this list of conditions and the following disclaimer.
     38  * 2. Redistributions in binary form must reproduce the above copyright
     39  *    notice, this list of conditions and the following disclaimer in the
     40  *    documentation and/or other materials provided with the distribution.
     41  * 3. Neither the name of the University nor the names of its contributors
     42  *    may be used to endorse or promote products derived from this software
     43  *    without specific prior written permission.
     44  *
     45  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     46  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     47  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     48  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     49  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     50  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     51  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     52  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     53  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     54  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     55  * SUCH DAMAGE.
     56  *
     57  *	@(#)vnode.h	8.17 (Berkeley) 5/20/95
     58  */
     59 
     60 #ifndef _SYS_VNODE_H_
     61 #define	_SYS_VNODE_H_
     62 
     63 #include <sys/event.h>
     64 #include <sys/queue.h>
     65 #include <sys/condvar.h>
     66 #include <sys/rwlock.h>
     67 #include <sys/mutex.h>
     68 #include <sys/time.h>
     69 #include <sys/acl.h>
     70 
     71 /* XXX: clean up includes later */
     72 #include <uvm/uvm_param.h>	/* XXX */
     73 #if defined(_KERNEL) || defined(_KMEMUSER)
     74 #include <uvm/uvm_pglist.h>	/* XXX */
     75 #include <uvm/uvm_object.h>	/* XXX */
     76 #include <uvm/uvm_extern.h>	/* XXX */
     77 
     78 struct uvm_ractx;
     79 #endif
     80 
     81 /*
     82  * The vnode is the focus of all file activity in UNIX.  There is a
     83  * unique vnode allocated for each active file, each current directory,
     84  * each mounted-on file, text file, and the root.
     85  */
     86 
     87 /*
     88  * Vnode types.  VNON means no type.
     89  */
     90 enum vtype	{ VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD };
     91 
     92 #define	VNODE_TYPES \
     93     "VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD"
     94 
     95 /*
     96  * Vnode tag types.
     97  * These are for the benefit of external programs only (e.g., pstat)
     98  * and should NEVER be inspected by the kernel.
     99  */
    100 enum vtagtype	{
    101 	VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_MSDOSFS, VT_LFS, VT_LOFS,
    102 	VT_FDESC, VT_PORTAL, VT_NULL, VT_UMAP, VT_KERNFS, VT_PROCFS,
    103 	VT_AFS, VT_ISOFS, VT_UNION, VT_ADOSFS, VT_EXT2FS, VT_CODA,
    104 	VT_FILECORE, VT_NTFS, VT_VFS, VT_OVERLAY, VT_SMBFS, VT_PTYFS,
    105 	VT_TMPFS, VT_UDF, VT_SYSVBFS, VT_PUFFS, VT_HFS, VT_EFS, VT_ZFS,
    106 	VT_RUMP, VT_NILFS, VT_V7FS, VT_CHFS, VT_AUTOFS
    107 };
    108 
    109 #define	VNODE_TAGS \
    110     "VT_NON", "VT_UFS", "VT_NFS", "VT_MFS", "VT_MSDOSFS", "VT_LFS", "VT_LOFS", \
    111     "VT_FDESC", "VT_PORTAL", "VT_NULL", "VT_UMAP", "VT_KERNFS", "VT_PROCFS", \
    112     "VT_AFS", "VT_ISOFS", "VT_UNION", "VT_ADOSFS", "VT_EXT2FS", "VT_CODA", \
    113     "VT_FILECORE", "VT_NTFS", "VT_VFS", "VT_OVERLAY", "VT_SMBFS", "VT_PTYFS", \
    114     "VT_TMPFS", "VT_UDF", "VT_SYSVBFS", "VT_PUFFS", "VT_HFS", "VT_EFS", \
    115     "VT_ZFS", "VT_RUMP", "VT_NILFS", "VT_V7FS", "VT_CHFS", "VT_AUTOFS"
    116 
    117 #if defined(_KERNEL) || defined(_KMEMUSER)
    118 struct vnode;
    119 struct buf;
    120 
    121 LIST_HEAD(buflists, buf);
    122 
    123 /*
    124  * Reading or writing any of these items requires holding the appropriate
    125  * lock.  Field markings and the corresponding locks:
    126  *
    127  *	-	stable, reference to the vnode is required
    128  *	b	bufcache_lock
    129  *	e	exec_lock
    130  *	f	vnode_free_list_lock, or vrele_lock for vrele_list
    131  *	i	v_interlock
    132  *	i+b	v_interlock + bufcache_lock to modify, either to inspect
    133  *	i+u	v_interlock + v_uobj.vmobjlock to modify, either to inspect
    134  *	k	locked by underlying filesystem (maybe kernel_lock)
    135  *	u	v_uobj.vmobjlock
    136  *	v	vnode lock
    137  *
    138  * Each underlying filesystem allocates its own private area and hangs
    139  * it from v_data.
    140  */
    141 struct vnode {
    142 	/*
    143 	 * VM system related items.
    144 	 */
    145 	struct uvm_object v_uobj;		/* u   the VM object */
    146 	voff_t		v_size;			/* i+u size of file */
    147 	voff_t		v_writesize;		/* i+u new size after write */
    148 
    149 	/*
    150 	 * Unstable items get their own cache line.
    151 	 * On _LP64 this fills the space nicely.
    152 	 */
    153 	kcondvar_t	v_cv			/* i   synchronization */
    154 	    __aligned(COHERENCY_UNIT);
    155 	int		v_iflag;		/* i+u VI_* flags */
    156 	int		v_uflag;		/* k   VU_* flags */
    157 	int		v_usecount;		/* i   reference count */
    158 	int		v_numoutput;		/* i   # of pending writes */
    159 	int		v_writecount;		/* i   ref count of writers */
    160 	int		v_holdcnt;		/* i   page & buffer refs */
    161 	struct buflists	v_cleanblkhd;		/* i+b clean blocklist head */
    162 	struct buflists	v_dirtyblkhd;		/* i+b dirty blocklist head */
    163 
    164 	/*
    165 	 * The remaining items are largely stable.
    166 	 */
    167 	int		v_vflag			/* v   VV_* flags */
    168 	    __aligned(COHERENCY_UNIT);
    169 	kmutex_t	*v_interlock;		/* -   vnode interlock */
    170 	struct mount	*v_mount;		/* v   ptr to vfs we are in */
    171 	int		(**v_op)(void *);	/* :   vnode operations vector */
    172 	union {
    173 		struct mount	*vu_mountedhere;/* v   ptr to vfs (VDIR) */
    174 		struct socket	*vu_socket;	/* v   unix ipc (VSOCK) */
    175 		struct specnode	*vu_specnode;	/* v   device (VCHR, VBLK) */
    176 		struct fifoinfo	*vu_fifoinfo;	/* v   fifo (VFIFO) */
    177 		struct uvm_ractx *vu_ractx;	/* u   read-ahead ctx (VREG) */
    178 	} v_un;
    179 	enum vtype	v_type;			/* -   vnode type */
    180 	enum vtagtype	v_tag;			/* -   type of underlying data */
    181 	void 		*v_data;		/* -   private data for fs */
    182 	struct vnode_klist *v_klist;		/* i   kevent / knote info */
    183 
    184 	void		*v_segvguard;		/* e   for PAX_SEGVGUARD */
    185 };
    186 #define	v_mountedhere	v_un.vu_mountedhere
    187 #define	v_socket	v_un.vu_socket
    188 #define	v_specnode	v_un.vu_specnode
    189 #define	v_fifoinfo	v_un.vu_fifoinfo
    190 #define	v_ractx		v_un.vu_ractx
    191 
    192 typedef struct vnode vnode_t;
    193 
    194 /*
    195  * Structure that encompasses the kevent state for a vnode.  This is
    196  * carved out as a separate structure because some vnodes may share
    197  * this state with one another.
    198  *
    199  * N.B. if two vnodes share a vnode_klist, then they must also share
    200  * v_interlock.
    201  */
    202 struct vnode_klist {
    203 	struct klist	vk_klist;	/* i   notes attached to vnode */
    204 	long		vk_interest;	/* i   what the notes are interested in */
    205 };
    206 #endif
    207 
    208 /*
    209  * Vnode flags.  The first set are locked by vnode lock or are stable.
    210  * VSYSTEM is only used to skip vflush()ing quota files.  VISTTY is used
    211  * when reading dead vnodes.
    212  */
    213 #define	VV_ROOT		0x00000001	/* root of its file system */
    214 #define	VV_SYSTEM	0x00000002	/* vnode being used by kernel */
    215 #define	VV_ISTTY	0x00000004	/* vnode represents a tty */
    216 #define	VV_MAPPED	0x00000008	/* vnode might have user mappings */
    217 #define	VV_MPSAFE	0x00000010	/* file system code is MP safe */
    218 
    219 /*
    220  * The second set are locked by vp->v_interlock.  VI_TEXT and VI_EXECMAP are
    221  * typically updated with vp->v_uobj.vmobjlock also held as the VM system
    222  * uses them for accounting purposes.
    223  */
    224 #define	VI_TEXT		0x00000100	/* vnode is a pure text prototype */
    225 #define	VI_EXECMAP	0x00000200	/* might have PROT_EXEC mappings */
    226 #define	VI_WRMAP	0x00000400	/* might have PROT_WRITE u. mappings */
    227 #define	VI_PAGES	0x00000800	/* UVM object has >0 pages */
    228 #define	VI_ONWORKLST	0x00004000	/* On syncer work-list */
    229 #define	VI_DEADCHECK	0x00008000	/* UVM: need to call vdead_check() */
    230 
    231 /*
    232  * The third set are locked by the underlying file system.
    233  */
    234 #define	VU_DIROP	0x01000000	/* LFS: involved in a directory op */
    235 
    236 #define	VNODE_FLAGBITS \
    237     "\20\1ROOT\2SYSTEM\3ISTTY\4MAPPED\5MPSAFE\11TEXT\12EXECMAP" \
    238     "\13WRMAP\14PAGES\17ONWORKLST\20DEADCHECK\31DIROP"
    239 
    240 #define	VSIZENOTSET	((voff_t)-1)
    241 
    242 /*
    243  * vnode lock flags
    244  */
    245 #define	LK_NONE		0x00000000	/* no lock - for VOP_ISLOCKED() */
    246 #define	LK_SHARED	0x00000001	/* shared lock */
    247 #define	LK_EXCLUSIVE	0x00000002	/* exclusive lock */
    248 #define	LK_UPGRADE	0x00000010	/* upgrade shared -> exclusive */
    249 #define	LK_DOWNGRADE	0x00000020	/* downgrade exclusive -> shared */
    250 #define	LK_NOWAIT	0x00000100	/* do not sleep to await lock */
    251 #define	LK_RETRY	0x00000200	/* vn_lock: retry until locked */
    252 
    253 /*
    254  * Vnode attributes.  A field value of VNOVAL represents a field whose value
    255  * is unavailable (getattr) or which is not to be changed (setattr).
    256  */
    257 struct vattr {
    258 	enum vtype	va_type;	/* vnode type (for create) */
    259 	mode_t		va_mode;	/* files access mode and type */
    260 	nlink_t		va_nlink;	/* number of references to file */
    261 	uid_t		va_uid;		/* owner user id */
    262 	gid_t		va_gid;		/* owner group id */
    263 	dev_t		va_fsid;	/* file system id (dev for now) */
    264 	ino_t		va_fileid;	/* file id */
    265 	u_quad_t	va_size;	/* file size in bytes */
    266 	long		va_blocksize;	/* blocksize preferred for i/o */
    267 	struct timespec	va_atime;	/* time of last access */
    268 	struct timespec	va_mtime;	/* time of last modification */
    269 	struct timespec	va_ctime;	/* time file changed */
    270 	struct timespec va_birthtime;	/* time file created */
    271 	u_long		va_gen;		/* generation number of file */
    272 	u_long		va_flags;	/* flags defined for file */
    273 	dev_t		va_rdev;	/* device the special file represents */
    274 	u_quad_t	va_bytes;	/* bytes of disk space held by file */
    275 	u_quad_t	va_filerev;	/* file modification number */
    276 	unsigned int	va_vaflags;	/* operations flags, see below */
    277 	long		va_spare;	/* remain quad aligned */
    278 };
    279 
    280 /*
    281  * Flags for va_vaflags.
    282  */
    283 #define	VA_UTIMES_NULL	0x01		/* utimes argument was NULL */
    284 #define	VA_EXCLUSIVE	0x02		/* exclusive create request */
    285 
    286 #ifdef _KERNEL
    287 
    288 /*
    289  * Flags for ioflag.
    290  */
    291 #define	IO_UNIT		0x00010		/* do I/O as atomic unit */
    292 #define	IO_APPEND	0x00020		/* append write to end */
    293 #define	IO_SYNC		(0x40|IO_DSYNC)	/* sync I/O file integrity completion */
    294 #define	IO_NODELOCKED	0x00080		/* underlying node already locked */
    295 #define	IO_NDELAY	0x00100		/* FNDELAY flag set in file table */
    296 #define	IO_DSYNC	0x00200		/* sync I/O data integrity completion */
    297 #define	IO_ALTSEMANTICS	0x00400		/* use alternate i/o semantics */
    298 #define	IO_NORMAL	0x00800		/* operate on regular data */
    299 #define	IO_EXT		0x01000		/* operate on extended attributes */
    300 #define	IO_DIRECT	0x02000		/* direct I/O hint */
    301 #define	IO_JOURNALLOCKED 0x04000	/* journal is already locked */
    302 #define	IO_ADV_MASK	0x00003		/* access pattern hint */
    303 
    304 #define	IO_ADV_SHIFT	0
    305 #define	IO_ADV_ENCODE(adv)	(((adv) << IO_ADV_SHIFT) & IO_ADV_MASK)
    306 #define	IO_ADV_DECODE(ioflag)	(((ioflag) & IO_ADV_MASK) >> IO_ADV_SHIFT)
    307 
    308 /*
    309  * Flags for accmode_t.
    310  */
    311 #define	VEXEC			000000000100 /* execute/search permission */
    312 #define	VWRITE			000000000200 /* write permission */
    313 #define	VREAD			000000000400 /* read permission */
    314 #define	VADMIN			000000010000 /* being the file owner */
    315 #define	VAPPEND			000000040000 /* permission to write/append */
    316 
    317 /*
    318  * VEXPLICIT_DENY makes VOP_ACCESSX(9) return EPERM or EACCES only
    319  * if permission was denied explicitly, by a "deny" rule in NFSv4 ACL,
    320  * and 0 otherwise.  This never happens with ordinary unix access rights
    321  * or POSIX.1e ACLs.  Obviously, VEXPLICIT_DENY must be OR-ed with
    322  * some other V* constant.
    323  */
    324 #define	VEXPLICIT_DENY		000000100000
    325 #define	VREAD_NAMED_ATTRS 	000000200000 /* not used */
    326 #define	VWRITE_NAMED_ATTRS 	000000400000 /* not used */
    327 #define	VDELETE_CHILD	 	000001000000
    328 #define	VREAD_ATTRIBUTES 	000002000000 /* permission to stat(2) */
    329 #define	VWRITE_ATTRIBUTES 	000004000000 /* change {m,c,a}time */
    330 #define	VDELETE		 	000010000000
    331 #define	VREAD_ACL	 	000020000000 /* read ACL and file mode */
    332 #define	VWRITE_ACL	 	000040000000 /* change ACL and/or file mode */
    333 #define	VWRITE_OWNER	 	000100000000 /* change file owner */
    334 #define	VSYNCHRONIZE	 	000200000000 /* not used */
    335 #define	VCREAT			000400000000 /* creating new file */
    336 #define	VVERIFY			001000000000 /* verification required */
    337 
    338 #define __VNODE_PERM_BITS	\
    339 	"\10"			\
    340 	"\07VEXEC"		\
    341 	"\10VWRITE"		\
    342 	"\11VREAD"		\
    343 	"\15VADMIN"		\
    344 	"\17VAPPEND"		\
    345 	"\20VEXPLICIT_DENY"	\
    346 	"\21VREAD_NAMED_ATTRS"	\
    347 	"\22VWRITE_NAMED_ATTRS"	\
    348 	"\23VDELETE_CHILD"	\
    349 	"\24VREAD_ATTRIBUTES"	\
    350 	"\25VWRITE_ATTRIBUTES"	\
    351 	"\26VDELETE"		\
    352 	"\27VREAD_ACL"		\
    353 	"\30VWRITE_ACL"		\
    354 	"\31VWRITE_OWNER"	\
    355 	"\32VSYNCHRONIZE"	\
    356 	"\33VCREAT"		\
    357 	"\34VVERIFY"
    358 
    359 /*
    360  * Permissions that were traditionally granted only to the file owner.
    361  */
    362 #define VADMIN_PERMS	(VADMIN | VWRITE_ATTRIBUTES | VWRITE_ACL | \
    363     VWRITE_OWNER)
    364 
    365 /*
    366  * Permissions that were traditionally granted to everyone.
    367  */
    368 #define VSTAT_PERMS	(VREAD_ATTRIBUTES | VREAD_ACL)
    369 
    370 /*
    371  * Permissions that allow to change the state of the file in any way.
    372  */
    373 #define VMODIFY_PERMS	(VWRITE | VAPPEND | VADMIN_PERMS | VDELETE_CHILD | \
    374     VDELETE)
    375 
    376 /*
    377  * Token indicating no attribute value yet assigned.
    378  */
    379 #define	VNOVAL	(-1)
    380 #define VNOVALSIZE ((u_quad_t)-1)
    381 #define VNOVALFLAGS ((u_long)-1)
    382 
    383 /*
    384  * Convert between vnode types and inode formats (since POSIX.1
    385  * defines mode word of stat structure in terms of inode formats).
    386  */
    387 extern const enum vtype	iftovt_tab[];
    388 extern const int	vttoif_tab[];
    389 #define	IFTOVT(mode)	(iftovt_tab[((mode) & S_IFMT) >> 12])
    390 #define	VTTOIF(indx)	(vttoif_tab[(int)(indx)])
    391 #define	MAKEIMODE(indx, mode)	(int)(VTTOIF(indx) | (mode))
    392 
    393 /*
    394  * Flags to various vnode functions.
    395  */
    396 #define	SKIPSYSTEM	0x0001	/* vflush: skip vnodes marked VSYSTEM */
    397 #define	FORCECLOSE	0x0002	/* vflush: force file closeure */
    398 #define	WRITECLOSE	0x0004	/* vflush: only close writable files */
    399 #define	V_SAVE		0x0001	/* vinvalbuf: sync file first */
    400 
    401 /*
    402  * Flags to various vnode operations.
    403  */
    404 #define	REVOKEALL	0x0001	/* revoke: revoke all aliases */
    405 
    406 #define	FSYNC_WAIT	0x0001	/* fsync: wait for completion */
    407 #define	FSYNC_DATAONLY	0x0002	/* fsync: hint: sync file data only */
    408 #define	FSYNC_RECLAIM	0x0004	/* fsync: hint: vnode is being reclaimed */
    409 #define	FSYNC_LAZY	0x0008	/* fsync: lazy sync (trickle) */
    410 #define	FSYNC_NOLOG	0x0010	/* fsync: don't flush the log (ffs internal) */
    411 #define	FSYNC_CACHE	0x0100	/* fsync: flush disk caches too */
    412 
    413 #define VDEAD_NOWAIT	0x0001	/* vdead_check: do not sleep */
    414 
    415 /*
    416  * Flags some filesystems intenally use for their "UPDATE" functions.
    417  * (Historically, these used to be VOP_UPDATE flags.)
    418  */
    419 #define	UPDATE_WAIT	0x0001	/* update: wait for completion */
    420 #define	UPDATE_DIROP	0x0002	/* update: hint to fs to wait or not */
    421 #define	UPDATE_CLOSE	0x0004	/* update: clean up on close */
    422 
    423 void holdrelel(struct vnode *);
    424 void holdrele(struct vnode *);
    425 void vholdl(struct vnode *);
    426 void vhold(struct vnode *);
    427 void vref(struct vnode *);
    428 
    429 #define	NULLVP	((struct vnode *)NULL)
    430 
    431 /*
    432  * Macro to determine kevent interest on a vnode.
    433  */
    434 #define	_VN_KEVENT_INTEREST(vp, n)					\
    435 	(((vp)->v_klist->vk_interest & (n)) != 0)
    436 
    437 static inline bool
    438 VN_KEVENT_INTEREST(struct vnode *vp, long hint)
    439 {
    440 	mutex_enter(vp->v_interlock);
    441 	bool rv = _VN_KEVENT_INTEREST(vp, hint);
    442 	mutex_exit(vp->v_interlock);
    443 	return rv;
    444 }
    445 
    446 static inline void
    447 VN_KNOTE(struct vnode *vp, long hint)
    448 {
    449 	mutex_enter(vp->v_interlock);
    450 	if (__predict_false(_VN_KEVENT_INTEREST(vp, hint))) {
    451 		knote(&vp->v_klist->vk_klist, hint);
    452 	}
    453 	mutex_exit(vp->v_interlock);
    454 }
    455 
    456 void	vn_knote_attach(struct vnode *, struct knote *);
    457 void	vn_knote_detach(struct vnode *, struct knote *);
    458 
    459 /*
    460  * Global vnode data.
    461  */
    462 extern struct vnode	*rootvnode;	/* root (i.e. "/") vnode */
    463 extern int		desiredvnodes;	/* number of vnodes desired */
    464 extern unsigned int	numvnodes;	/* current number of vnodes */
    465 
    466 #endif /* _KERNEL */
    467 
    468 
    469 /*
    470  * Mods for exensibility.
    471  */
    472 
    473 /*
    474  * Flags for vdesc_flags:
    475  */
    476 #define	VDESC_MAX_VPS		8
    477 /* Low order 16 flag bits are reserved for willrele flags for vp arguments. */
    478 #define	VDESC_VP0_WILLRELE	0x00000001
    479 #define	VDESC_VP1_WILLRELE	0x00000002
    480 #define	VDESC_VP2_WILLRELE	0x00000004
    481 #define	VDESC_VP3_WILLRELE	0x00000008
    482 #define	VDESC_VP0_WILLPUT	0x00000101
    483 #define	VDESC_VP1_WILLPUT	0x00000202
    484 #define	VDESC_VP2_WILLPUT	0x00000404
    485 #define	VDESC_VP3_WILLPUT	0x00000808
    486 
    487 /*
    488  * VDESC_NO_OFFSET is used to identify the end of the offset list
    489  * and in places where no such field exists.
    490  */
    491 #define	VDESC_NO_OFFSET -1
    492 
    493 /*
    494  * This structure describes the vnode operation taking place.
    495  */
    496 struct vnodeop_desc {
    497 	int		vdesc_offset;	/* offset in vector--first for speed */
    498 	const char	*vdesc_name;	/* a readable name for debugging */
    499 	int		vdesc_flags;	/* VDESC_* flags */
    500 
    501 	/*
    502 	 * These ops are used by bypass routines to map and locate arguments.
    503 	 * Creds and procs are not needed in bypass routines, but sometimes
    504 	 * they are useful to (for example) transport layers.
    505 	 * Nameidata is useful because it has a cred in it.
    506 	 */
    507 	const int	*vdesc_vp_offsets;	/* list ended by VDESC_NO_OFFSET */
    508 	int		vdesc_vpp_offset;	/* return vpp location */
    509 	int		vdesc_cred_offset;	/* cred location, if any */
    510 	int		vdesc_componentname_offset; /* if any */
    511 };
    512 
    513 #ifdef _KERNEL
    514 
    515 extern const struct vnodeop_desc * const vfs_op_descs[];
    516 
    517 /*
    518  * Union filesystem hook for vn_readdir().
    519  */
    520 extern int (*vn_union_readdir_hook) (struct vnode **, struct file *, struct lwp *);
    521 
    522 /*
    523  * Macros for offsets in the vdesc struct.
    524  */
    525 #define	VOPARG_OFFSETOF(type, member)	offsetof(type, member)
    526 #define	VOPARG_OFFSETTO(type,offset,sp)	((type)(((char *)(sp)) + (offset)))
    527 
    528 /*
    529  * This structure is used to configure the new vnodeops vector.
    530  */
    531 struct vnodeopv_entry_desc {
    532 	const struct vnodeop_desc *opve_op;	/* which operation this is */
    533 	int (*opve_impl)(void *);	/* code implementing this operation */
    534 };
    535 
    536 struct vnodeopv_desc {
    537 			/* ptr to the ptr to the vector where op should go */
    538 	int (***opv_desc_vector_p)(void *);
    539 	const struct vnodeopv_entry_desc *opv_desc_ops; /* null terminated list */
    540 };
    541 
    542 /*
    543  * A default routine which just returns an error.
    544  */
    545 int vn_default_error(void *);
    546 
    547 /*
    548  * A generic structure.
    549  * This can be used by bypass routines to identify generic arguments.
    550  */
    551 struct vop_generic_args {
    552 	struct vnodeop_desc *a_desc;
    553 	/* other random data follows, presumably */
    554 };
    555 
    556 /*
    557  * VOCALL calls an op given an ops vector.  We break it out because BSD's
    558  * vclean changes the ops vector and then wants to call ops with the old
    559  * vector.
    560  */
    561 /*
    562  * actually, vclean doesn't use it anymore, but nfs does,
    563  * for device specials and fifos.
    564  */
    565 #define	VOCALL(OPSV,OFF,AP) (( *((OPSV)[(OFF)])) (AP))
    566 
    567 /*
    568  * This call works for vnodes in the kernel.
    569  */
    570 #define	VCALL(VP,OFF,AP) VOCALL((VP)->v_op,(OFF),(AP))
    571 #define	VDESC(OP) (& __CONCAT(OP,_desc))
    572 #define	VOFFSET(OP) (VDESC(OP)->vdesc_offset)
    573 
    574 /* XXX This include should go away */
    575 #include <sys/mount.h>
    576 
    577 /*
    578  * Finally, include the default set of vnode operations.
    579  */
    580 #include <sys/vnode_if.h>
    581 
    582 /*
    583  * Public vnode manipulation functions.
    584  */
    585 struct file;
    586 struct filedesc;
    587 struct nameidata;
    588 struct pathbuf;
    589 struct proc;
    590 struct stat;
    591 struct uio;
    592 struct vattr;
    593 struct vnode;
    594 
    595 /* see vnode(9) */
    596 void	vfs_vnode_sysinit(void);
    597 int 	bdevvp(dev_t, struct vnode **);
    598 int 	cdevvp(dev_t, struct vnode **);
    599 void 	vattr_null(struct vattr *);
    600 void	vdevgone(int, int, int, enum vtype);
    601 int	vfinddev(dev_t, enum vtype, struct vnode **);
    602 int	vflush(struct mount *, struct vnode *, int);
    603 int	vflushbuf(struct vnode *, int);
    604 void 	vgone(struct vnode *);
    605 int	vinvalbuf(struct vnode *, int, kauth_cred_t, struct lwp *, bool, int);
    606 void	vprint(const char *, struct vnode *);
    607 void 	vput(struct vnode *);
    608 bool	vrecycle(struct vnode *);
    609 void 	vrele(struct vnode *);
    610 void 	vrele_async(struct vnode *);
    611 void	vrele_flush(struct mount *);
    612 int	vtruncbuf(struct vnode *, daddr_t, bool, int);
    613 void	vwakeup(struct buf *);
    614 int	vdead_check(struct vnode *, int);
    615 void	vrevoke(struct vnode *);
    616 void	vremfree(struct vnode *);
    617 void	vshareilock(struct vnode *, struct vnode *);
    618 void	vshareklist(struct vnode *, struct vnode *);
    619 int	vrefcnt(struct vnode *);
    620 int	vcache_get(struct mount *, const void *, size_t, struct vnode **);
    621 int	vcache_new(struct mount *, struct vnode *,
    622 	    struct vattr *, kauth_cred_t, void *, struct vnode **);
    623 int	vcache_rekey_enter(struct mount *, struct vnode *,
    624 	    const void *, size_t, const void *, size_t);
    625 void	vcache_rekey_exit(struct mount *, struct vnode *,
    626 	    const void *, size_t, const void *, size_t);
    627 
    628 /* see vnsubr(9) */
    629 int	vn_bwrite(void *);
    630 int 	vn_close(struct vnode *, int, kauth_cred_t);
    631 int	vn_isunder(struct vnode *, struct vnode *, struct lwp *);
    632 int	vn_lock(struct vnode *, int);
    633 void	vn_markexec(struct vnode *);
    634 int	vn_marktext(struct vnode *);
    635 int 	vn_open(struct vnode *, struct pathbuf *, int, int, int,
    636 	    struct vnode **, bool *, int *);
    637 int 	vn_rdwr(enum uio_rw, struct vnode *, void *, int, off_t, enum uio_seg,
    638     int, kauth_cred_t, size_t *, struct lwp *);
    639 int	vn_readdir(struct file *, char *, int, unsigned int, int *,
    640     struct lwp *, off_t **, int *);
    641 int	vn_stat(struct vnode *, struct stat *);
    642 int	vn_kqfilter(struct file *, struct knote *);
    643 int	vn_writechk(struct vnode *);
    644 int	vn_openchk(struct vnode *, kauth_cred_t, int);
    645 int	vn_extattr_get(struct vnode *, int, int, const char *, size_t *,
    646 	    void *, struct lwp *);
    647 int	vn_extattr_set(struct vnode *, int, int, const char *, size_t,
    648 	    const void *, struct lwp *);
    649 int	vn_extattr_rm(struct vnode *, int, int, const char *, struct lwp *);
    650 int	vn_fifo_bypass(void *);
    651 int	vn_bdev_open(dev_t, struct vnode **, struct lwp *);
    652 int	vn_bdev_openpath(struct pathbuf *pb, struct vnode **, struct lwp *);
    653 
    654 
    655 /* initialise global vnode management */
    656 void	vntblinit(void);
    657 
    658 /* misc stuff */
    659 void	sched_sync(void *);
    660 void	vn_syncer_add_to_worklist(struct vnode *, int);
    661 void	vn_syncer_remove_from_worklist(struct vnode *);
    662 int	dorevoke(struct vnode *, kauth_cred_t);
    663 int	rawdev_mounted(struct vnode *, struct vnode **);
    664 uint8_t	vtype2dt(enum vtype);
    665 
    666 /* see vfssubr(9) */
    667 int	vfs_unixify_accmode(accmode_t *);
    668 void	vfs_getnewfsid(struct mount *);
    669 void	vfs_timestamp(struct timespec *);
    670 #if defined(DDB) || defined(DEBUGPRINT)
    671 void	vfs_vnode_print(struct vnode *, int, void (*)(const char *, ...)
    672     __printflike(1, 2));
    673 void	vfs_vnode_lock_print(void *, int, void (*)(const char *, ...)
    674     __printflike(1, 2));
    675 void	vfs_mount_print(struct mount *, int, void (*)(const char *, ...)
    676     __printflike(1, 2));
    677 void	vfs_mount_print_all(int, void (*)(const char *, ...)
    678     __printflike(1, 2));
    679 #endif /* DDB */
    680 
    681 #endif /* _KERNEL */
    682 
    683 #endif /* !_SYS_VNODE_H_ */
    684