master
  1/*	$NetBSD: vnode.h,v 1.304 2022/10/26 23:40:30 riastradh 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
 78struct 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 */
 90enum 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 */
100enum 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)
118struct vnode;
119struct buf;
120
121LIST_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 */
141struct 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
192typedef 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 */
202struct 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 */
257struct 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 */
387extern const enum vtype	iftovt_tab[];
388extern 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: do not flush the log */
411#define	FSYNC_CACHE	0x0100		/* fsync: flush disk caches too */
412
413#define	UPDATE_WAIT	0x0001		/* update: wait for completion */
414#define	UPDATE_DIROP	0x0002		/* update: hint to fs to wait or not */
415#define	UPDATE_CLOSE	0x0004		/* update: clean up on close */
416
417#define VDEAD_NOWAIT	0x0001		/* vdead_check: do not sleep */
418
419void holdrelel(struct vnode *);
420void holdrele(struct vnode *);
421void vholdl(struct vnode *);
422void vhold(struct vnode *);
423void vref(struct vnode *);
424
425#define	NULLVP	((struct vnode *)NULL)
426
427/*
428 * Macro to determine kevent interest on a vnode.
429 */
430#define	_VN_KEVENT_INTEREST(vp, n)					\
431	(((vp)->v_klist->vk_interest & (n)) != 0)
432
433static inline bool
434VN_KEVENT_INTEREST(struct vnode *vp, long hint)
435{
436	mutex_enter(vp->v_interlock);
437	bool rv = _VN_KEVENT_INTEREST(vp, hint);
438	mutex_exit(vp->v_interlock);
439	return rv;
440}
441
442static inline void
443VN_KNOTE(struct vnode *vp, long hint)
444{
445	mutex_enter(vp->v_interlock);
446	if (__predict_false(_VN_KEVENT_INTEREST(vp, hint))) {
447		knote(&vp->v_klist->vk_klist, hint);
448	}
449	mutex_exit(vp->v_interlock);
450}
451
452void	vn_knote_attach(struct vnode *, struct knote *);
453void	vn_knote_detach(struct vnode *, struct knote *);
454
455/*
456 * Global vnode data.
457 */
458extern struct vnode	*rootvnode;	/* root (i.e. "/") vnode */
459extern int		desiredvnodes;	/* number of vnodes desired */
460extern unsigned int	numvnodes;	/* current number of vnodes */
461
462#endif /* _KERNEL */
463
464
465/*
466 * Mods for exensibility.
467 */
468
469/*
470 * Flags for vdesc_flags:
471 */
472#define	VDESC_MAX_VPS		8
473/* Low order 16 flag bits are reserved for willrele flags for vp arguments. */
474#define	VDESC_VP0_WILLRELE	0x00000001
475#define	VDESC_VP1_WILLRELE	0x00000002
476#define	VDESC_VP2_WILLRELE	0x00000004
477#define	VDESC_VP3_WILLRELE	0x00000008
478#define	VDESC_VP0_WILLPUT	0x00000101
479#define	VDESC_VP1_WILLPUT	0x00000202
480#define	VDESC_VP2_WILLPUT	0x00000404
481#define	VDESC_VP3_WILLPUT	0x00000808
482
483/*
484 * VDESC_NO_OFFSET is used to identify the end of the offset list
485 * and in places where no such field exists.
486 */
487#define	VDESC_NO_OFFSET -1
488
489/*
490 * This structure describes the vnode operation taking place.
491 */
492struct vnodeop_desc {
493	int		vdesc_offset;	/* offset in vector--first for speed */
494	const char	*vdesc_name;	/* a readable name for debugging */
495	int		vdesc_flags;	/* VDESC_* flags */
496
497	/*
498	 * These ops are used by bypass routines to map and locate arguments.
499	 * Creds and procs are not needed in bypass routines, but sometimes
500	 * they are useful to (for example) transport layers.
501	 * Nameidata is useful because it has a cred in it.
502	 */
503	const int	*vdesc_vp_offsets;	/* list ended by VDESC_NO_OFFSET */
504	int		vdesc_vpp_offset;	/* return vpp location */
505	int		vdesc_cred_offset;	/* cred location, if any */
506	int		vdesc_componentname_offset; /* if any */
507};
508
509#ifdef _KERNEL
510
511extern const struct vnodeop_desc * const vfs_op_descs[];
512
513/*
514 * Union filesystem hook for vn_readdir().
515 */
516extern int (*vn_union_readdir_hook) (struct vnode **, struct file *, struct lwp *);
517
518/*
519 * Macros for offsets in the vdesc struct.
520 */
521#define	VOPARG_OFFSETOF(type, member)	offsetof(type, member)
522#define	VOPARG_OFFSETTO(type,offset,sp)	((type)(((char *)(sp)) + (offset)))
523
524/*
525 * This structure is used to configure the new vnodeops vector.
526 */
527struct vnodeopv_entry_desc {
528	const struct vnodeop_desc *opve_op;	/* which operation this is */
529	int (*opve_impl)(void *);	/* code implementing this operation */
530};
531
532struct vnodeopv_desc {
533			/* ptr to the ptr to the vector where op should go */
534	int (***opv_desc_vector_p)(void *);
535	const struct vnodeopv_entry_desc *opv_desc_ops; /* null terminated list */
536};
537
538/*
539 * A default routine which just returns an error.
540 */
541int vn_default_error(void *);
542
543/*
544 * A generic structure.
545 * This can be used by bypass routines to identify generic arguments.
546 */
547struct vop_generic_args {
548	struct vnodeop_desc *a_desc;
549	/* other random data follows, presumably */
550};
551
552/*
553 * VOCALL calls an op given an ops vector.  We break it out because BSD's
554 * vclean changes the ops vector and then wants to call ops with the old
555 * vector.
556 */
557/*
558 * actually, vclean doesn't use it anymore, but nfs does,
559 * for device specials and fifos.
560 */
561#define	VOCALL(OPSV,OFF,AP) (( *((OPSV)[(OFF)])) (AP))
562
563/*
564 * This call works for vnodes in the kernel.
565 */
566#define	VCALL(VP,OFF,AP) VOCALL((VP)->v_op,(OFF),(AP))
567#define	VDESC(OP) (& __CONCAT(OP,_desc))
568#define	VOFFSET(OP) (VDESC(OP)->vdesc_offset)
569
570/* XXX This include should go away */
571#include <sys/mount.h>
572
573/*
574 * Finally, include the default set of vnode operations.
575 */
576#include <sys/vnode_if.h>
577
578/*
579 * Public vnode manipulation functions.
580 */
581struct file;
582struct filedesc;
583struct nameidata;
584struct pathbuf;
585struct proc;
586struct stat;
587struct uio;
588struct vattr;
589struct vnode;
590
591/* see vnode(9) */
592void	vfs_vnode_sysinit(void);
593int 	bdevvp(dev_t, struct vnode **);
594int 	cdevvp(dev_t, struct vnode **);
595void 	vattr_null(struct vattr *);
596void	vdevgone(int, int, int, enum vtype);
597int	vfinddev(dev_t, enum vtype, struct vnode **);
598int	vflush(struct mount *, struct vnode *, int);
599int	vflushbuf(struct vnode *, int);
600void 	vgone(struct vnode *);
601int	vinvalbuf(struct vnode *, int, kauth_cred_t, struct lwp *, bool, int);
602void	vprint(const char *, struct vnode *);
603void 	vput(struct vnode *);
604bool	vrecycle(struct vnode *);
605void 	vrele(struct vnode *);
606void 	vrele_async(struct vnode *);
607void	vrele_flush(struct mount *);
608int	vtruncbuf(struct vnode *, daddr_t, bool, int);
609void	vwakeup(struct buf *);
610int	vdead_check(struct vnode *, int);
611void	vrevoke(struct vnode *);
612void	vremfree(struct vnode *);
613void	vshareilock(struct vnode *, struct vnode *);
614void	vshareklist(struct vnode *, struct vnode *);
615int	vrefcnt(struct vnode *);
616int	vcache_get(struct mount *, const void *, size_t, struct vnode **);
617int	vcache_new(struct mount *, struct vnode *,
618	    struct vattr *, kauth_cred_t, void *, struct vnode **);
619int	vcache_rekey_enter(struct mount *, struct vnode *,
620	    const void *, size_t, const void *, size_t);
621void	vcache_rekey_exit(struct mount *, struct vnode *,
622	    const void *, size_t, const void *, size_t);
623
624/* see vnsubr(9) */
625int	vn_bwrite(void *);
626int 	vn_close(struct vnode *, int, kauth_cred_t);
627int	vn_isunder(struct vnode *, struct vnode *, struct lwp *);
628int	vn_lock(struct vnode *, int);
629void	vn_markexec(struct vnode *);
630int	vn_marktext(struct vnode *);
631int 	vn_open(struct vnode *, struct pathbuf *, int, int, int,
632	    struct vnode **, bool *, int *);
633int 	vn_rdwr(enum uio_rw, struct vnode *, void *, int, off_t, enum uio_seg,
634    int, kauth_cred_t, size_t *, struct lwp *);
635int	vn_readdir(struct file *, char *, int, unsigned int, int *,
636    struct lwp *, off_t **, int *);
637int	vn_stat(struct vnode *, struct stat *);
638int	vn_kqfilter(struct file *, struct knote *);
639int	vn_writechk(struct vnode *);
640int	vn_openchk(struct vnode *, kauth_cred_t, int);
641int	vn_extattr_get(struct vnode *, int, int, const char *, size_t *,
642	    void *, struct lwp *);
643int	vn_extattr_set(struct vnode *, int, int, const char *, size_t,
644	    const void *, struct lwp *);
645int	vn_extattr_rm(struct vnode *, int, int, const char *, struct lwp *);
646int	vn_fifo_bypass(void *);
647int	vn_bdev_open(dev_t, struct vnode **, struct lwp *);
648int	vn_bdev_openpath(struct pathbuf *pb, struct vnode **, struct lwp *);
649
650
651/* initialise global vnode management */
652void	vntblinit(void);
653
654/* misc stuff */
655void	sched_sync(void *);
656void	vn_syncer_add_to_worklist(struct vnode *, int);
657void	vn_syncer_remove_from_worklist(struct vnode *);
658int	dorevoke(struct vnode *, kauth_cred_t);
659int	rawdev_mounted(struct vnode *, struct vnode **);
660uint8_t	vtype2dt(enum vtype);
661
662/* see vfssubr(9) */
663int	vfs_unixify_accmode(accmode_t *);
664void	vfs_getnewfsid(struct mount *);
665void	vfs_timestamp(struct timespec *);
666#if defined(DDB) || defined(DEBUGPRINT)
667void	vfs_vnode_print(struct vnode *, int, void (*)(const char *, ...)
668    __printflike(1, 2));
669void	vfs_vnode_lock_print(void *, int, void (*)(const char *, ...)
670    __printflike(1, 2));
671void	vfs_mount_print(struct mount *, int, void (*)(const char *, ...)
672    __printflike(1, 2));
673void	vfs_mount_print_all(int, void (*)(const char *, ...)
674    __printflike(1, 2));
675#endif /* DDB */
676
677#endif /* _KERNEL */
678
679#endif /* !_SYS_VNODE_H_ */