Skip site navigation (1)Skip section navigation (2)

FreeBSD Man Pages

Man Page or Keyword Search:
Man Architecture
Apropos Keyword Search (all sections) Output format
home | help
VNODE(9)               FreeBSD Kernel Developer's Manual              VNODE(9)

     vnode - internal representation of a file or directory

     #include <sys/param.h>
     #include <sys/vnode.h>

      * Vnode types.  VNON means no type.
     enum vtype      { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD };

      * Vnode tag types.
      * These are for the benefit of external programs only (e.g., pstat)
      * and should NEVER be inspected by the kernel.
     enum vtagtype   {

      * Each underlying filesystem allocates its own private area and hangs
      * it from v_data.  If non-null, this area is freed in getnewvnode().
     TAILQ_HEAD(buflists, buf);

     typedef int     vop_t __P((void *));
     struct namecache;

      * Reading or writing any of these items requires holding the appropriate lock.
      * v_freelist is locked by the global vnode_free_list simple lock.
      * v_mntvnodes is locked by the global mntvnodes simple lock.
      * v_flag, v_usecount, v_holdcount and v_writecount are
      *    locked by the v_interlock simple lock.
      * v_pollinfo is locked by the lock contained inside it.
     struct vnode {
             u_long  v_flag;                         /* vnode flags (see below) */
             int     v_usecount;                     /* reference count of users */
             int     v_writecount;                   /* reference count of writers */
             int     v_holdcnt;                      /* page & buffer references */
             daddr_t v_lastr;                        /* last read (read-ahead) */
             u_long  v_id;                           /* capability identifier */
             struct  mount *v_mount;                 /* ptr to vfs we are in */
             vop_t   **v_op;                         /* vnode operations vector */
             TAILQ_ENTRY(vnode) v_freelist;          /* vnode freelist */
             LIST_ENTRY(vnode) v_mntvnodes;          /* vnodes for mount point */
             struct  buflists v_cleanblkhd;          /* clean blocklist head */
             struct  buflists v_dirtyblkhd;          /* dirty blocklist head */
             LIST_ENTRY(vnode) v_synclist;           /* vnodes with dirty buffers */
             long    v_numoutput;                    /* num of writes in progress */
             enum    vtype v_type;                   /* vnode type */
             union {
                     struct mount    *vu_mountedhere;/* ptr to mounted vfs (VDIR) */
                     struct socket   *vu_socket;     /* unix ipc (VSOCK) */
                     struct specinfo *vu_specinfo;   /* device (VCHR, VBLK) */
                     struct fifoinfo *vu_fifoinfo;   /* fifo (VFIFO) */
             } v_un;
             struct  nqlease *v_lease;               /* Soft reference to lease */
             daddr_t v_lastw;                        /* last write (write cluster) */
             daddr_t v_cstart;                       /* start block of cluster */
             daddr_t v_lasta;                        /* last allocation */
             int     v_clen;                         /* length of current cluster */
             int     v_maxio;                        /* maximum I/O cluster size */
             struct vm_object *v_object;             /* Place to store VM object */
             struct  simplelock v_interlock;         /* lock on usecount and flag */
             struct  lock *v_vnlock;                 /* used for non-locking fs's */
             enum    vtagtype v_tag;                 /* type of underlying data */
             void    *v_data;                        /* private data for fs */
             LIST_HEAD(, namecache) v_cache_src;     /* Cache entries from us */
             TAILQ_HEAD(, namecache) v_cache_dst;    /* Cache entries to us */
             struct  vnode *v_dd;                    /* .. vnode */
             u_long  v_ddid;                         /* .. capability identifier */
             struct  {
                     struct  simplelock vpi_lock;    /* lock to protect below */
                     struct  selinfo vpi_selinfo;    /* identity of poller(s) */
                     short   vpi_events;             /* what they are looking for */
                     short   vpi_revents;            /* what has happened */
             } v_pollinfo;
     #define v_mountedhere   v_un.vu_mountedhere
     #define v_socket        v_un.vu_socket
     #define v_specinfo      v_un.vu_specinfo
     #define v_fifoinfo      v_un.vu_fifoinfo

      * Vnode flags.
     #define VROOT           0x00001 /* root of its file system */
     #define VTEXT           0x00002 /* vnode is a pure text prototype */
     #define VSYSTEM         0x00004 /* vnode being used by kernel */
     #define VISTTY          0x00008 /* vnode represents a tty */
     #define VXLOCK          0x00100 /* vnode is locked to change underlying type */
     #define VXWANT          0x00200 /* process is waiting for vnode */
     #define VBWAIT          0x00400 /* waiting for output to complete */
     #define VALIASED        0x00800 /* vnode has an alias */
     #define VDIROP          0x01000 /* LFS: vnode is involved in a directory op */
     #define VOBJBUF         0x02000 /* Allocate buffers in VM object */
     #define VNINACT         0x04000 /* LFS: skip ufs_inactive() in lfs_vunref */
     #define VAGE            0x08000 /* Insert vnode at head of free list */
     #define VOLOCK          0x10000 /* vnode is locked waiting for an object */
     #define VOWANT          0x20000 /* a process is waiting for VOLOCK */
     #define VDOOMED         0x40000 /* This vnode is being recycled */
     #define VFREE           0x80000 /* This vnode is on the freelist */
     #define VTBFREE         0x100000 /* This vnode is on the to-be-freelist */
     #define VONWORKLST      0x200000 /* On syncer work-list */
     #define VMOUNT          0x400000 /* Mount in progress */

     The vnode is the focus of all file activity in UNIX.  There is a unique
     vnode allocated for each active file, each current directory, each
     mounted-on file, text file, and the root.

     Each vnode has three reference counts, v_usecount, v_holdcnt and
     v_writecount.  The first is the number of clients within the kernel which
     are using this vnode.  This count is maintained by vref(9), vrele(9) and
     vput(9).  The second is the number of clients within the kernel who veto
     the recycling of this vnode.  This count is maintained by vhold(9) and
     vdrop(9).  When both the v_usecount and the v_holdcnt of a vnode reaches
     zero then the vnode will be put on the freelist and may be reused for
     another file, possibly in another filesystem.  The transition to and from
     the freelist is handled by getnewvnode(9), vfree(9) and vbusy(9).  The
     third is a count of the number of clients which are writing into the
     file.  It is maintained by the open(2) and close(2) system calls.

     Any call which returns a vnode (e.g. VFS_GET(9), VOP_LOOKUP(9) etc.)
     will increase the v_usecount of the vnode by one.  When the caller is
     finished with the vnode, it should release this reference by calling
     vrele(9) (or vput(9) if the vnode is locked).

     Other commonly used members of the vnode structure are v_id which is used
     to maintain consistency in the name cache, v_mount which points at the
     filesystem which owns the vnode, v_type which contains the type of object
     the vnode represents and v_data which is used by filesystems to store
     filesystem specific data with the vnode.  The v_op field is used by the
     VOP_* macros to call functions in the filesystem which implement the
     vnode's functionality.

     VNON   No type.

     VREG   A regular file; may be with or without VM object backing.  If you
            want to make sure this get a backing object, call

     VDIR   A directory.

     VBLK   A block device; may be with or without VM object backing.  If you
            want to make sure this get a backing object, call

     VCHR   A character device.

     VLNK   A symbolic link.

     VSOCK  A socket.  Advisory locking won't work on this.

     VFIFO  A FIFO (named pipe).  Advisory locking won't work on this.

     VBAD   An old style bad sector map

     VFIFO uses the "struct fileops" from /sys/kern/sys_pipe.c.  VSOCK uses
     the "struct fileops" from /sys/kern/sys_socket.c.  Everything else uses
     the one from /sys/kern/vfs_vnops.c.

     The VFIFO/VSOCK code, which is why "struct fileops" is used at all, is an
     artifact of an incomplete integration of the VFS code into the kernel.


     This man page was written by Doug Rabson.

FreeBSD 11.0-PRERELEASE          June 30, 1999         FreeBSD 11.0-PRERELEASE


Want to link to this manual page? Use this URL:

home | help