1.\" -*- nroff -*- 2.\" 3.\" Copyright (c) 1996 Doug Rabson 4.\" 5.\" All rights reserved. 6.\" 7.\" This program is free software. 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 DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 19.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 22.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28.\" 29.\" $Id: vnode.9,v 1.1 1997/03/03 18:00:57 dfr Exp $ 30.\" 31.Dd July 24, 1996 32.Os 33.Dt VNODE 9 34.Sh NAME 35.Nm vnode 36.Nd internal representation of a file or directory 37.Sh SYNOPSIS 38.Fd #include <sys/vnode.h> 39.Pp 40.Bd -literal 41/* 42 * Vnode types. VNON means no type. 43 */ 44enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD }; 45 46/* 47 * Vnode tag types. 48 * These are for the benefit of external programs only (e.g., pstat) 49 * and should NEVER be inspected by the kernel. 50 */ 51enum vtagtype { 52 VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_PC, VT_LFS, VT_LOFS, VT_FDESC, 53 VT_PORTAL, VT_NULL, VT_UMAP, VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS, 54 VT_UNION, VT_MSDOSFS, VT_DEVFS 55}; 56 57/* 58 * Each underlying filesystem allocates its own private area and hangs 59 * it from v_data. If non-null, this area is freed in getnewvnode(). 60 */ 61LIST_HEAD(buflists, buf); 62 63typedef int vop_t __P((void *)); 64 65struct vnode { 66 u_long v_flag; /* vnode flags (see below) */ 67 int v_usecount; /* reference count of users */ 68 int v_writecount; /* reference count of writers */ 69 int v_holdcnt; /* page & buffer references */ 70 daddr_t v_lastr; /* last read (read-ahead) */ 71 u_long v_id; /* capability identifier */ 72 struct mount *v_mount; /* ptr to vfs we are in */ 73 vop_t **v_op; /* vnode operations vector */ 74 TAILQ_ENTRY(vnode) v_freelist; /* vnode freelist */ 75 LIST_ENTRY(vnode) v_mntvnodes; /* vnodes for mount point */ 76 struct buflists v_cleanblkhd; /* clean blocklist head */ 77 struct buflists v_dirtyblkhd; /* dirty blocklist head */ 78 long v_numoutput; /* num of writes in progress */ 79 enum vtype v_type; /* vnode type */ 80 union { 81 struct mount *vu_mountedhere;/* ptr to mounted vfs (VDIR) */ 82 struct socket *vu_socket; /* unix ipc (VSOCK) */ 83 struct specinfo *vu_specinfo; /* device (VCHR, VBLK) */ 84 struct fifoinfo *vu_fifoinfo; /* fifo (VFIFO) */ 85 } v_un; 86 struct nqlease *v_lease; /* Soft reference to lease */ 87 daddr_t v_lastw; /* last write (write cluster) */ 88 daddr_t v_cstart; /* start block of cluster */ 89 daddr_t v_lasta; /* last allocation */ 90 int v_clen; /* length of current cluster */ 91 int v_ralen; /* Read-ahead length */ 92 int v_usage; /* Vnode usage counter */ 93 daddr_t v_maxra; /* last readahead block */ 94 void *v_object; /* Place to store VM object */ 95 enum vtagtype v_tag; /* type of underlying data */ 96 void *v_data; /* private data for fs */ 97}; 98#define v_mountedhere v_un.vu_mountedhere 99#define v_socket v_un.vu_socket 100#define v_specinfo v_un.vu_specinfo 101#define v_fifoinfo v_un.vu_fifoinfo 102 103/* 104 * Vnode flags. 105 */ 106#define VROOT 0x0001 /* root of its file system */ 107#define VTEXT 0x0002 /* vnode is a pure text prototype */ 108#define VSYSTEM 0x0004 /* vnode being used by kernel */ 109#define VOLOCK 0x0008 /* vnode is locked waiting for an object */ 110#define VOWANT 0x0010 /* a process is waiting for VOLOCK */ 111#define VXLOCK 0x0100 /* vnode is locked to change underlying type */ 112#define VXWANT 0x0200 /* process is waiting for vnode */ 113#define VBWAIT 0x0400 /* waiting for output to complete */ 114#define VALIASED 0x0800 /* vnode has an alias */ 115#define VDIROP 0x1000 /* LFS: vnode is involved in a directory op */ 116#define VVMIO 0x2000 /* VMIO flag */ 117#define VNINACT 0x4000 /* LFS: skip ufs_inactive() in lfs_vunref */ 118#define VAGE 0x8000 /* Insert vnode at head of free list */ 119.Ed 120.Sh DESCRIPTION 121The vnode is the focus of all file activity in UNIX. There is a 122unique vnode allocated for each active file, each current directory, 123each mounted-on file, text file, and the root. 124.Pp 125Each vnode has two reference counts, 126.Dv v_usecount 127and 128.Dv v_writecount . 129The first is the number of clients within the kernel which are 130using this vnode. This count is maintained by 131.Xr vref 9 , 132.Xr vrele 9 and 133.Xr vput 9 . 134When the 135.Dv v_usecount 136of a vnode reaches zero then the vnode may be reused for another 137file, possibly in another filesystem. 138The second is a count of the number of clients which are writing into 139the file. It is maintained by the 140.Xr open 2 141and 142.Xr close 2 143system calls. 144.Pp 145Any call which returns a vnode (e.g. 146.Xr VFS_GET 9 , 147.Xr VOP_LOOKUP 9 148etc.) 149will increase the 150.Dv v_usecount 151of the vnode by one. When the caller is finished with the vnode, it 152should release this reference by calling 153.Xr vrele 9 154(or 155.Xr vput 9 156if the vnode is locked). 157.Pp 158Other commonly used members of the vnode structure are 159.Dv v_id 160which is used to maintain consistency in the name cache, 161.Dv v_mount 162which points at the filesystem which owns the vnode, 163.Dv v_type 164which contains the type of object the vnode represents and 165.Dv v_data 166which is used by filesystems to store filesystem specific data with 167the vnode. 168The 169.Dv v_op 170field is used by the 171.Dv VOP_* 172macros to call functions in the filesystem which implement the vnode's 173functionality. 174.Sh SEE ALSO 175.Xr VFS 9 176.Sh AUTHORS 177This man page was written by Doug Rabson. 178 179