VNODE(9)

NAME
vnode - internal representation of a file, directory, or other VFS entity

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

DESCRIPTION
The vnode is the focus of all file activity in UNIX. The vnode is described by struct vnode. 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 numerous reference counts, v_sysref, v_auxrefs, v_opencount, and v_writecount.

v_sysref represents the number of primary references to the vnode. It is actually a structure which utilizes the SYSREF API and also manages allocation and deallocation of the vnode. Primary references keep a vnode ready for I/O and prevent it from being deactivated. Primary references are managed by vref(9) and vrele(9).

v_auxrefs represents the number of auxiliary references to a vnode. Auxiliary references prevent a vnode from being reclaimed (if not already being reclaimed), reused for other purposes, or otherwise destroyed, but do not activate or deactivate the vnode. Auxiliary references are managed by vhold(9) and vdrop(9).

v_opencount represents the number of discrete open() calls made on the vnode (reading or writing). v_writecount represents the number of discrete open() calls made on the vnode for the purpose of writing. This field will be a subset of v_opencount. These fields are managed primarily by calls to vn_open(9) and vn_close(9).

A deactivated vnode or a vnode in an unknown state accessed from an Auxiliary data structure can be reactivated, referenced, and locked using vget(9) and vput(9).

An actively referenced and possibly locked vnode must be passed to most kernel procedures taking a vnode as an argument. Most kernel procedures returning a vnode will return one that is actively referenced.

Other commonly used members of the vnode structure are 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_ops field is used by the VOP_* macros to call functions in the filesystem which implement the vnode's functionality.

VNODE TYPES

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 vfs_object_create(9).

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 vfs_object_create(9).

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.

IMPLEMENTATION NOTES
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.

SEE ALSO
VFS(9)

AUTHORS
This manual page was written by Doug Rabson.