1.\" $NetBSD: vnode.9,v 1.70 2015/07/17 06:45:55 wiz Exp $ 2.\" 3.\" Copyright (c) 2001, 2005, 2006 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Gregory McGarry. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd July 12, 2015 31.Dt VNODE 9 32.Os 33.Sh NAME 34.Nm vnode , 35.Nm vref , 36.Nm vrele , 37.Nm vrele_async , 38.Nm vget , 39.Nm vput , 40.Nm vhold , 41.Nm holdrele , 42.Nm vcache_get , 43.Nm vcache_new , 44.Nm vcache_rekey_enter , 45.Nm vcache_rekey_exit , 46.Nm vcache_remove , 47.Nm vrecycle , 48.Nm vgone , 49.Nm vgonel , 50.Nm vdead_check , 51.Nm vflush , 52.Nm vaccess , 53.Nm bdevvp , 54.Nm cdevvp , 55.Nm vfinddev , 56.Nm vdevgone , 57.Nm vwakeup , 58.Nm vflushbuf , 59.Nm vinvalbuf , 60.Nm vtruncbuf , 61.Nm vprint 62.Nd kernel representation of a file or directory 63.Sh SYNOPSIS 64.In sys/param.h 65.In sys/vnode.h 66.Ft void 67.Fn vref "struct vnode *vp" 68.Ft void 69.Fn vrele "struct vnode *vp" 70.Ft void 71.Fn vrele_async "struct vnode *vp" 72.Ft int 73.Fn vget "struct vnode *vp" "int lockflag" "int wait" 74.Ft void 75.Fn vput "struct vnode *vp" 76.Ft void 77.Fn vhold "struct vnode *vp" 78.Ft void 79.Fn holdrele "struct vnode *vp" 80.Ft int 81.Fn vcache_get "struct mount *mp" "const void *key" "size_t key_len" "struct vnode **vpp" 82.Ft int 83.Fn vcache_new "struct mount *mp" "struct vnode *dvp" "struct vattr *vap" "kauth_cred_t cred" "struct vnode **vpp" 84.Ft int 85.Fn vcache_rekey_enter "struct mount *mp" "struct vnode *vp" "const void *old_key" "size_t old_key_len" "const void *new_key" "size_t new_key_len" 86.Ft void 87.Fn vcache_rekey_exit "struct mount *mp" "struct vnode *vp" "const void *old_key" "size_t old_key_len" "const void *new_key" "size_t new_key_len" 88.Ft void 89.Fn vcache_remove "struct mount *mp" "const void *key" "size_t key_len" 90.Ft int 91.Fn vrecycle "struct vnode *vp" 92.Ft void 93.Fn vgone "struct vnode *vp" 94.Ft void 95.Fn vgonel "struct vnode *vp" "struct lwp *l" 96.Ft int 97.Fn vdead_check "struct vnode *vp" "int flags" 98.Ft int 99.Fn vflush "struct mount *mp" "struct vnode *skipvp" "int flags" 100.Ft int 101.Fn vaccess "enum vtype type" "mode_t file_mode" "uid_t uid" "gid_t gid" "mode_t acc_mode" "kauth_cred_t cred" 102.Ft int 103.Fn bdevvp "dev_t dev" "struct vnode **vpp" 104.Ft int 105.Fn cdevvp "dev_t dev" "struct vnode **vpp" 106.Ft int 107.Fn vfinddev "dev_t dev" "enum vtype" "struct vnode **vpp" 108.Ft void 109.Fn vdevgone "int maj" "int minl" "int minh" "enum vtype type" 110.Ft void 111.Fn vwakeup "struct buf *bp" 112.Ft int 113.Fn vflushbuf "struct vnode *vp" "int sync" 114.Ft int 115.Fn vinvalbuf "struct vnode *vp" "int flags" "kauth_cred_t cred" "struct lwp *l" "int slpflag" "int slptimeo" 116.Ft int 117.Fn vtruncbuf "struct vnode *vp" "daddr_t lbn" "int slpflag" "int slptimeo" 118.Ft void 119.Fn vprint "const char *label" "struct vnode *vp" 120.Sh DESCRIPTION 121A 122.Em vnode 123represents an on-disk file in use by the system. 124Each 125.Xr vfs 9 126file system provides a set of 127.Xr vnodeops 9 128operations on vnodes, invoked by file-system-independent system calls 129and supported by file-system-independent library routines. 130.Pp 131Each mounted file system provides a vnode for the root of the file 132system, via 133.Xr VFS_ROOT 9 . 134Other vnodes are obtained by 135.Xr VOP_LOOKUP 9 . 136Users of vnodes usually invoke these indirectly via 137.Xr namei 9 138to obtain vnodes from paths. 139.Pp 140Each file system usually maintains a cache mapping recently used inode 141numbers, or the equivalent, to vnodes, and a cache mapping recently 142used file names to vnodes. 143If memory is scarce, the system may decide to 144.Em reclaim 145an unused cached vnode, calling 146.Xr VOP_RECLAIM 9 147to remove it from the caches and to free file-system-specific memory 148associated with it. 149A file system may also choose to immediately reclaim a cached vnode 150once it is unused, in 151.Xr VOP_INACTIVE 9 , 152if the vnode has been deleted on disk. 153.Pp 154When a file system retrieves a vnode from a cache, the vnode may not 155have any users, and another thread in the system may be simultaneously 156deciding to reclaim it. 157Thus, to retrieve a vnode from a cache, one must use 158.Fn vget , 159not 160.Fn vref , 161to acquire the first reference, and be prepared for 162.Fn vget 163to fail if another thread is reclaiming the vnode. 164.Pp 165The vnode has the following structure: 166.Bd -literal 167struct vnode { 168 struct uvm_object v_uobj; /* the VM object */ 169 kcondvar_t v_cv; /* synchronization */ 170 voff_t v_size; /* size of file */ 171 voff_t v_writesize; /* new size after write */ 172 int v_iflag; /* VI_* flags */ 173 int v_vflag; /* VV_* flags */ 174 int v_uflag; /* VU_* flags */ 175 int v_numoutput; /* # of pending writes */ 176 int v_writecount; /* ref count of writers */ 177 int v_holdcnt; /* page & buffer refs */ 178 int v_synclist_slot; /* synclist slot index */ 179 struct mount *v_mount; /* ptr to vfs we are in */ 180 int (**v_op)(void *); /* vnode operations vector */ 181 TAILQ_ENTRY(vnode) v_freelist; /* vnode freelist */ 182 struct vnodelst *v_freelisthd; /* which freelist? */ 183 TAILQ_ENTRY(vnode) v_mntvnodes; /* vnodes for mount point */ 184 struct buflists v_cleanblkhd; /* clean blocklist head */ 185 struct buflists v_dirtyblkhd; /* dirty blocklist head */ 186 TAILQ_ENTRY(vnode) v_synclist; /* vnodes with dirty bufs */ 187 LIST_HEAD(, namecache) v_dnclist; /* namecaches (children) */ 188 LIST_HEAD(, namecache) v_nclist; /* namecaches (parent) */ 189 union { 190 struct mount *vu_mountedhere;/* ptr to vfs (VDIR) */ 191 struct socket *vu_socket; /* unix ipc (VSOCK) */ 192 struct specnode *vu_specnode; /* device (VCHR, VBLK) */ 193 struct fifoinfo *vu_fifoinfo; /* fifo (VFIFO) */ 194 struct uvm_ractx *vu_ractx; /* read-ahead ctx (VREG) */ 195 } v_un; 196 enum vtype v_type; /* vnode type */ 197 enum vtagtype v_tag; /* type of underlying data */ 198 struct vnlock v_lock; /* lock for this vnode */ 199 void *v_data; /* private data for fs */ 200 struct klist v_klist; /* notes attached to vnode */ 201}; 202.Ed 203.Pp 204Most members of the vnode structure should be treated as opaque and 205only manipulated using the proper functions. 206There are some rather common exceptions detailed throughout this page. 207.Pp 208Files and file systems are inextricably linked with the virtual memory 209system and 210.Em v_uobj 211contains the data maintained by the virtual memory system. 212For compatibility with code written before the integration of 213.Xr uvm 9 214into 215.Nx , 216C-preprocessor directives are used to alias the members of 217.Em v_uobj . 218.Pp 219Vnode flags are recorded by 220.Em v_iflag , 221.Em v_vflag 222and 223.Em v_uflag . 224Valid flags are: 225.Pp 226.Bl -tag -offset indent -width ".Dv VI_WRMAPDIRTY" -compact 227.It Dv VV_ROOT 228This vnode is the root of its file system. 229.It Dv VV_SYSTEM 230This vnode is being used by the kernel; only used to skip quota files in 231.Fn vflush . 232.It Dv VV_ISTTY 233This vnode represents a tty; used when reading dead vnodes. 234.It Dv VV_MAPPED 235This vnode might have user mappings. 236.It Dv VV_MPSAFE 237This file system is MP safe. 238.It Dv VV_LOCKSWORK 239This vnode's file system supports locking. 240.It Dv VI_TEXT 241This vnode is a pure text prototype. 242.It Dv VI_EXECMAP 243This vnode has executable mappings. 244.It Dv VI_WRMAP 245This vnode might have PROT_WRITE user mappings. 246.It Dv VI_WRMAPDIRTY 247This vnode might have dirty pages due to 248.Dv VWRITEMAP . 249.It Dv VI_XLOCK 250This vnode is currently locked to change underlying type. 251.It Dv VI_ONWORKLST 252This vnode is on syncer work-list. 253.It Dv VI_MARKER 254A dummy marker vnode. 255.It Dv VI_CLEAN 256This vnode has been reclaimed and is no longer attached to a file system. 257.It Dv VU_DIROP 258This vnode is involved in a directory operation. 259This flag is used exclusively by LFS. 260.El 261.Pp 262The 263.Dv VI_XLOCK 264flag is used to prevent multiple processes from entering 265the vnode reclamation code. 266It is also used as a flag to indicate that reclamation is in progress. 267Before 268.Em v_iflag 269can be modified, the 270.Em v_interlock 271mutex must be acquired. 272See 273.Xr lock 9 274for details on the kernel locking API. 275.Pp 276Each vnode has three reference counts: 277.Em v_usecount , 278.Em v_writecount 279and 280.Em v_holdcnt . 281The first is the number of active references within the 282kernel to the vnode. 283This count is maintained by 284.Fn vref , 285.Fn vrele , 286.Fn vrele_async , 287and 288.Fn vput . 289The second is the number of active references within the kernel to the 290vnode performing write access to the file. 291It is maintained by the 292.Xr open 2 293and 294.Xr close 2 295system calls. 296The third is the number of references within the kernel 297requiring the vnode to remain active and not be recycled. 298This count is maintained by 299.Fn vhold 300and 301.Fn holdrele . 302When both the 303.Em v_usecount 304and 305.Em v_holdcnt 306reach zero, the vnode is recycled to the freelist and may be reused 307for another file. 308The transition to and from the freelist is handled by 309a kernel thread 310and 311.Fn vrecycle . 312Access to 313.Em v_usecount , 314.Em v_writecount 315and 316.Em v_holdcnt 317is also protected by the 318.Em v_interlock 319mutex. 320.Pp 321The number of pending synchronous and asynchronous writes on the 322vnode are recorded in 323.Em v_numoutput . 324It is used by 325.Xr fsync 2 326to wait for all writes to complete before returning to the user. 327Its value must only be modified at splbio (see 328.Xr spl 9 ) . 329It does not track the number of dirty buffers attached to the 330vnode. 331.Pp 332.Em v_dnclist 333and 334.Em v_nclist 335are used by 336.Xr namecache 9 337to maintain the list of associated entries so that 338.Xr cache_purge 9 339can purge them. 340.Pp 341The link to the file system which owns the vnode is recorded by 342.Em v_mount . 343See 344.Xr vfsops 9 345for further information of file system mount status. 346.Pp 347The 348.Em v_op 349pointer points to its vnode operations vector. 350This vector describes what operations can be done to the file associated 351with the vnode. 352The system maintains one vnode operations vector for each file system 353type configured into the kernel. 354The vnode operations vector contains a pointer to a function for 355each operation supported by the file system. 356See 357.Xr vnodeops 9 358for a description of vnode operations. 359.Pp 360When not in use, vnodes are kept on the freelist through 361.Em v_freelist . 362The vnodes still reference valid files but may be reused to refer to a 363new file at any time. 364When a valid vnode which is on the freelist is used again, the user 365must call 366.Fn vget 367to increment the reference count and retrieve it from the freelist. 368When a user wants a new vnode for another file, 369.Fn vcache_get 370or 371.Fn vcache_new 372is invoked to allocate a vnode and initialize it for the new file. 373.Pp 374The type of object the vnode represents is recorded by 375.Em v_type . 376It is used by generic code to perform checks to ensure operations are 377performed on valid file system objects. 378Valid types are: 379.Pp 380.Bl -tag -offset indent -width VFIFO -compact 381.It Dv VNON 382The vnode has no type. 383.It Dv VREG 384The vnode represents a regular file. 385.It Dv VDIR 386The vnode represents a directory. 387.It Dv VBLK 388The vnode represents a block special device. 389.It Dv VCHR 390The vnode represents a character special device. 391.It Dv VLNK 392The vnode represents a symbolic link. 393.It Dv VSOCK 394The vnode represents a socket. 395.It Dv VFIFO 396The vnode represents a pipe. 397.It Dv VBAD 398The vnode represents a bad file (not currently used). 399.El 400.Pp 401Vnode tag types are used by external programs only (e.g., 402.Xr pstat 8 ) , 403and should never be inspected by the kernel. 404Its use is deprecated 405since new 406.Em v_tag 407values cannot be defined for loadable file systems. 408The 409.Em v_tag 410member is read-only. 411Valid tag types are: 412.Pp 413.Bl -tag -offset indent -width "VT_FILECORE " -compact 414.It Dv VT_NON 415non file system 416.It Dv VT_UFS 417universal file system 418.It Dv VT_NFS 419network file system 420.It Dv VT_MFS 421memory file system 422.It Dv VT_MSDOSFS 423FAT file system 424.It Dv VT_LFS 425log-structured file system 426.It Dv VT_LOFS 427loopback file system 428.It Dv VT_FDESC 429file descriptor file system 430.It Dv VT_NULL 431null file system layer 432.It Dv VT_UMAP 433uid/gid remapping file system layer 434.It Dv VT_KERNFS 435kernel interface file system 436.It Dv VT_PROCFS 437process interface file system 438.It Dv VT_AFS 439AFS file system 440.It Dv VT_ISOFS 441ISO 9660 file system(s) 442.It Dv VT_UNION 443union file system 444.It Dv VT_ADOSFS 445Amiga file system 446.It Dv VT_EXT2FS 447Linux's ext2 file system 448.It Dv VT_CODA 449Coda file system 450.It Dv VT_FILECORE 451filecore file system 452.It Dv VT_NTFS 453Microsoft NT's file system 454.It Dv VT_VFS 455virtual file system 456.It Dv VT_OVERLAY 457overlay file system 458.It Dv VT_SMBFS 459SMB file system 460.It Dv VT_PTYFS 461pseudo-terminal device file system 462.It Dv VT_TMPFS 463efficient memory file system 464.It Dv VT_UDF 465universal disk format file system 466.It Dv VT_SYSVBFS 467systemV boot file system 468.El 469.Pp 470All vnode locking operations use 471.Em v_lock . 472This lock is acquired by calling 473.Xr vn_lock 9 474and released by calling 475.Xr VOP_UNLOCK 9 . 476The reason for this asymmetry is that 477.Xr vn_lock 9 478is a wrapper for 479.Xr VOP_LOCK 9 480with extra checks, while the unlocking step usually does not need 481additional checks and thus has no wrapper. 482.Pp 483The vnode locking operation is complicated because it is used for many 484purposes. 485Sometimes it is used to bundle a series of vnode operations (see 486.Xr vnodeops 9 ) 487into an atomic group. 488Many file systems rely on it to prevent race conditions in updating 489file system type specific data structures rather than using their 490own private locks. 491The vnode lock can operate as a multiple-reader (shared-access lock) 492or single-writer lock (exclusive access lock), however many current file 493system implementations were written assuming only single-writer 494locking. 495Multiple-reader locking functions equivalently only in the presence 496of big-lock SMP locking or a uni-processor machine. 497The lock may be held while sleeping. 498While the 499.Em v_lock 500is acquired, the holder is guaranteed that the vnode will not be 501reclaimed or invalidated. 502Most file system functions require that you hold the vnode lock on entry. 503See 504.Xr lock 9 505for details on the kernel locking API. 506.Pp 507Each file system underlying a vnode allocates its own private area and 508hangs it from 509.Em v_data . 510.Pp 511Most functions discussed in this page that operate on vnodes cannot be 512called from interrupt context. 513The members 514.Em v_numoutput , 515.Em v_holdcnt , 516.Em v_dirtyblkhd , 517.Em v_cleanblkhd , 518.Em v_freelist , 519and 520.Em v_synclist 521are modified in interrupt context and must be protected by 522.Xr splbio 9 523unless it is certain that there is no chance an interrupt handler will 524modify them. 525The vnode lock must not be acquired within interrupt context. 526.Sh FUNCTIONS 527.Bl -tag -width compact 528.It Fn vref "vp" 529Increment 530.Em v_usecount 531of the vnode 532.Em vp . 533Any kernel thread system which uses a vnode (e.g., during the operation 534of some algorithm or to store in a data structure) should call 535.Fn vref . 536.It Fn vrele "vp" 537Decrement 538.Em v_usecount 539of unlocked vnode 540.Em vp . 541Any code in the system which is using a vnode should call 542.Fn vrele 543when it is finished with the vnode. 544If 545.Em v_usecount 546of the vnode reaches zero and 547.Em v_holdcnt 548is greater than zero, the vnode is placed on the holdlist. 549If both 550.Em v_usecount 551and 552.Em v_holdcnt 553are zero, the vnode is placed on the freelist. 554.It Fn vrele_async "vp" 555Will asychronously release the vnode in different context than the caller, 556sometime after the call. 557.It Fn vget "vp" "lockflags" "wait" 558Reclaim vnode 559.Fa vp 560from the freelist and increment its reference count. 561.Pp 562The vnode 563.Fa vp 564may be changing state: another thread may be initializing it from disk, 565or revoking it with 566.Xr revoke 2 , 567or reclaiming it with 568.Xr VOP_RECLAIM 9 . 569In that case, 570.Fn vget 571will wait until the state has changed, if 572.Fa lockflags 573is 574.Li 0 575and 576.Fa wait 577is 578.Li true ; 579or will return 580.Er EBUSY 581if 582.Fa lockflags 583is 584.Dv LK_NOWAIT 585and 586.Fa wait 587is 588.Li false . 589.Pp 590(The extra argument enables the compiler to detect old code which 591additionally used 592.Fn vget 593to lock the vnode.) 594.Pp 595Returns 596.Bl -tag -offset abcd -width ENOENT -compact 597.It Er EBUSY 598if 599.Fa vp 600was changing state and 601.Fa wait 602is false. 603.It Er ENOENT 604if the system was reclaiming 605.Fa vp 606with 607.Xr VOP_RECLAIM 9 . 608.It Li 0 609on success. 610.El 611.It Fn vput "vp" 612Legacy convenience routine for unlocking and releasing 613.Fa vp . 614Equivalent to: 615.Bd -literal -offset abcd 616.No "VOP_UNLOCK(" Ns Fa vp Ns Li ");" 617.No "vrele(" Ns Fa vp Ns Li ");" 618.Ed 619.Pp 620Note that this is 621.Em not 622an inverse of 623.Fn vget . 624The name appears so for hysterical raisins. 625New code should prefer using 626.Xr VOP_UNLOCK 9 627and 628.Fn vrele 629directly. 630.It Fn vhold "vp" 631Mark the vnode 632.Fa vp 633as active by incrementing 634.Em vp-\*[Gt]v_holdcnt 635and moving the vnode from the freelist to the holdlist. 636Once on the holdlist, the vnode will not be recycled until it is 637released with 638.Fn holdrele . 639.It Fn holdrele "vp" 640Mark the vnode 641.Fa vp 642as inactive by decrementing 643.Em vp-\*[Gt]v_holdcnt 644and moving the vnode from the holdlist to the freelist. 645.It Fn vcache_get "mp" "key" "key_len" "vpp" 646Allocate a new vnode. 647The new vnode is returned referenced in the address specified by 648.Fa vpp . 649.Pp 650The argument 651.Fa mp 652is the mount point for the file system to lookup the file in. 653.Pp 654The arguments 655.Fa key 656and 657.Fa key_len 658uniquely identify the file in the file system. 659.Pp 660If a vnode is successfully retrieved zero is returned, otherwise an 661appropriate error code is returned. 662.It Fn vcache_new "mp" "dvp" "vap" "cred" "vpp" 663Allocate a new vnode with a new file. 664The new vnode is returned referenced in the address specified by 665.Fa vpp . 666.Pp 667The argument 668.Fa mp 669is the mount point for the file system to create the file in. 670.Pp 671The argument 672.Fa dvp 673points to the directory to create the file in. 674.Pp 675The argument 676.Fa vap 677points to the attributes for the file to create. 678.Pp 679The argument 680.Fa cred 681holds the credentials for the file to create. 682.Pp 683If a vnode is successfully created zero is returned, otherwise an 684appropriate error code is returned. 685.It Fn vcache_rekey_enter "mp" "vp" "old_key" "old_key_len" "new_key" "new_key_len" 686Prepare to change the key of a cached vnode. 687.Pp 688The argument 689.Fa mp 690is the mount point for the file system the vnode 691.Fa vp 692resides in. 693.Pp 694The arguments 695.Fa old_key 696and 697.Fa old_key_len 698identify the cached vnode. 699.Pp 700The arguments 701.Fa new_key 702and 703.Fa new_key_len 704will identify the vnode after rename. 705.Pp 706If the new key already exists 707.Er EEXIST 708is returned, otherwise zero is returned. 709.It Fn vcache_rekey_exit "mp" "vp" "old_key" "old_key_len" "new_key" "new_key_len" 710Finish rename after calling 711.Fn vcache_rekey_enter . 712.It Fn vcache_remove "mp" "key" "key_len" 713Remove a vnode from the cache. 714Must be called when a file system reclaims a vnode. 715.Pp 716The argument 717.Fa mp 718is the mount point for the file system this file resides in. 719.Pp 720The arguments 721.Fa key 722and 723.Fa key_len 724uniquely identify the file in the file system. 725.It Fn vrecycle "vp" 726Recycle the referenced vnode 727.Fa vp 728if this is the last reference. 729.Fn vrecycle 730is a null operation if the reference count is greater than one. 731.It Fn vgone "vp" 732Eliminate all activity associated with the unlocked vnode 733.Fa vp 734in preparation for recycling. 735.It Fn vgonel "vp" "p" 736Eliminate all activity associated with the locked vnode 737.Fa vp 738in preparation for recycling. 739.It Fn vdead_check "vp" "flags" 740Check the vnode 741.Fa vp 742for being or becoming dead. 743Returns 744.Er ENOENT 745for a dead vnode and zero otherwise. 746If 747.Fa flags 748is 749.Dv VDEAD_NOWAIT 750it will return 751.Er EBUSY 752if the vnode is becoming dead and the function will not sleep. 753.Pp 754Whenever this function returns a non-zero value all future calls 755for this 756.Fa vp 757will also return a non-zero value. 758.It Fn vflush "mp" "skipvp" "flags" 759Remove any vnodes in the vnode table belonging to mount point 760.Fa mp . 761If 762.Fa skipvp 763is not 764.Dv NULL 765it is exempt from being flushed. 766The argument 767.Fa flags 768is a set of flags modifying the operation of 769.Fn vflush . 770If 771.Dv FORCECLOSE 772is not specified, there should not be any active vnodes and 773the error 774.Er EBUSY 775is returned if any are found (this is a user error, not a system error). 776If 777.Dv FORCECLOSE 778is specified, active vnodes that are found are detached. 779If 780.Dv WRITECLOSE 781is set, only flush out regular file vnodes open for writing. 782SKIPSYSTEM causes any vnodes marked 783.Dv V_SYSTEM 784to be skipped. 785.It Fn vaccess "type" "file_mode" "uid" "gid" "acc_mode" "cred" 786Do access checking by comparing the file's permissions to the caller's 787desired access type 788.Fa acc_mode 789and credentials 790.Fa cred . 791.It Fn bdevvp "dev" "vpp" 792Create a vnode for a block device. 793.Fn bdevvp 794is used for root file systems, swap areas and for memory file system 795special devices. 796.It Fn cdevvp "dev" "vpp" 797Create a vnode for a character device. 798.Fn cdevvp 799is used for the console and kernfs special devices. 800.It Fn vfinddev "dev" "vtype" "vpp" 801Lookup a vnode by device number. 802The vnode is referenced and returned in the address specified by 803.Fa vpp . 804.It Fn vdevgone "int maj" "int min" "int minh" "enum vtype type" 805Reclaim all vnodes that correspond to the specified minor number range 806.Fa minl 807to 808.Fa minh 809(endpoints inclusive) of the specified major 810.Fa maj . 811.It Fn vwakeup "bp" 812Update outstanding I/O count 813.Em vp-\*[Gt]v_numoutput 814for the vnode 815.Em bp-\*[Gt]b_vp 816and do a wakeup if requested and 817.Em vp-\*[Gt]vflag 818has 819.Dv VBWAIT 820set. 821.It Fn vflushbuf "vp" "sync" 822Flush all dirty buffers to disk for the file with the locked vnode 823.Fa vp . 824The argument 825.Fa sync 826specifies whether the I/O should be synchronous and 827.Fn vflushbuf 828will sleep until 829.Em vp-\*[Gt]v_numoutput 830is zero and 831.Em vp-\*[Gt]v_dirtyblkhd 832is empty. 833.It Fn vinvalbuf "vp" "flags" "cred" "l" "slpflag" "slptimeo" 834Flush out and invalidate all buffers associated with locked vnode 835.Fa vp . 836The argument 837.Fa l 838and 839.Fa cred 840specified the calling process and its credentials. 841The 842.Xr ltsleep 9 843flag and timeout are specified by the arguments 844.Fa slpflag 845and 846.Fa slptimeo 847respectively. 848If the operation is successful zero is returned, otherwise an 849appropriate error code is returned. 850.It Fn vtruncbuf "vp" "lbn" "slpflag" "slptimeo" 851Destroy any in-core buffers past the file truncation length for the 852locked vnode 853.Fa vp . 854The truncation length is specified by 855.Fa lbn . 856.Fn vtruncbuf 857will sleep while the I/O is performed, The 858.Xr ltsleep 9 859flag and timeout are specified by the arguments 860.Fa slpflag 861and 862.Fa slptimeo 863respectively. 864If the operation is successful zero is returned, otherwise an 865appropriate error code is returned. 866.It Fn vprint "label" "vp" 867This function is used by the kernel to dump vnode information during a 868panic. 869It is only used if the kernel option DIAGNOSTIC is compiled into the kernel. 870The argument 871.Fa label 872is a string to prefix the information dump of vnode 873.Fa vp . 874.El 875.Sh CODE REFERENCES 876The vnode framework is implemented within the file 877.Pa sys/kern/vfs_subr.c . 878.Sh SEE ALSO 879.Xr intro 9 , 880.Xr lock 9 , 881.Xr namecache 9 , 882.Xr namei 9 , 883.Xr uvm 9 , 884.Xr vattr 9 , 885.Xr vfs 9 , 886.Xr vfsops 9 , 887.Xr vnodeops 9 , 888.Xr vnsubr 9 889.Sh BUGS 890The locking protocol is inconsistent. 891Many vnode operations are passed locked vnodes on entry but release 892the lock before they exit. 893The locking protocol is used in some places to attempt to make a 894series of operations atomic (e.g., access check then operation). 895This does not work for non-local file systems that do not support locking 896(e.g., NFS). 897The 898.Nm 899interface would benefit from a simpler locking protocol. 900