---
name: "vnode"
section: "9freebsd"
platform: "linux"
package: "freebsd-manpages"
version: "12.2-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/vnode/9freebsd"
---

# vnode(9freebsd)

internal representation of a file or directory

## NAME

**vnode** – internal representation of a file or directory

## SYNOPSIS

**#include \<sys/param.h\>**

**#include \<sys/vnode.h\>**

## DESCRIPTION

The vnode is the focus of all file activity in UNIX. A 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 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)](/vref/9.md), [vrele(9)](/vrele/9.md) and [vput(9)](/vput/9.md). The second is the number of clients within the kernel who veto the recycling of this vnode. This count is maintained by [vhold(9)](/vhold/9.md) and [vdrop(9)](/vdrop/9.md). 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 file system. The transition from the freelist is handled by [getnewvnode(9)](/getnewvnode/9.md). The third is a count of the number of clients which are writing into the file. It is maintained by the [open(2)](/open/2.md) and [close(2)](/close/2.md) system calls.

Any call which returns a vnode (e.g., [vget(9)](/vget/9.md), [VOP\_LOOKUP(9)](/VOP_LOOKUP/9.md), 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)](/vrele/9.md) (or [vput(9)](/vput/9.md) 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 file system which owns the vnode, *v\_type* which contains the type of object the vnode represents and *v\_data* which is used by file systems to store file system specific data with the vnode. The *v\_op* field is used by the VOP\_\* macros to call functions in the file system 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 **vnode\_create\_vobject**().

- 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 **vnode\_create\_vobject**().

- VCHR

  A character device.

- VLNK

  A symbolic link.

- VSOCK

  A socket. Advisory locking will not work on this.

- VFIFO

  A FIFO (named pipe). Advisory locking will not work on this.

- VBAD

  Indicates that the vnode has been reclaimed.

## 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.

Calls to [malloc(9)](/malloc/9.md) or [free(9)](/free/9.md) when holding a **vnode** interlock, will cause a LOR (Lock Order Reversal) due to the intertwining of VM Objects and Vnodes.

## SEE ALSO

[malloc(9)](/malloc/9.md), [VFS(9)](/VFS/9.md), [VOP\_ACCESS(9)](/VOP_ACCESS/9.md), [VOP\_ACLCHECK(9)](/VOP_ACLCHECK/9.md), [VOP\_ADVISE(9)](/VOP_ADVISE/9.md), [VOP\_ADVLOCK(9)](/VOP_ADVLOCK/9.md), [VOP\_ALLOCATE(9)](/VOP_ALLOCATE/9.md), [VOP\_ATTRIB(9)](/VOP_ATTRIB/9.md), [VOP\_BWRITE(9)](/VOP_BWRITE/9.md), [VOP\_CREATE(9)](/VOP_CREATE/9.md), [VOP\_FSYNC(9)](/VOP_FSYNC/9.md), [VOP\_GETACL(9)](/VOP_GETACL/9.md), [VOP\_GETEXTATTR(9)](/VOP_GETEXTATTR/9.md), [VOP\_GETPAGES(9)](/VOP_GETPAGES/9.md), [VOP\_INACTIVE(9)](/VOP_INACTIVE/9.md), [VOP\_IOCTL(9)](/VOP_IOCTL/9.md), [VOP\_LINK(9)](/VOP_LINK/9.md), [VOP\_LISTEXTATTR(9)](/VOP_LISTEXTATTR/9.md), [VOP\_LOCK(9)](/VOP_LOCK/9.md), [VOP\_LOOKUP(9)](/VOP_LOOKUP/9.md), [VOP\_OPENCLOSE(9)](/VOP_OPENCLOSE/9.md), [VOP\_PATHCONF(9)](/VOP_PATHCONF/9.md), [VOP\_PRINT(9)](/VOP_PRINT/9.md), [VOP\_RDWR(9)](/VOP_RDWR/9.md), [VOP\_READDIR(9)](/VOP_READDIR/9.md), [VOP\_READLINK(9)](/VOP_READLINK/9.md), [VOP\_REALLOCBLKS(9)](/VOP_REALLOCBLKS/9.md), [VOP\_REMOVE(9)](/VOP_REMOVE/9.md), [VOP\_RENAME(9)](/VOP_RENAME/9.md), [VOP\_REVOKE(9)](/VOP_REVOKE/9.md), [VOP\_SETACL(9)](/VOP_SETACL/9.md), [VOP\_SETEXTATTR(9)](/VOP_SETEXTATTR/9.md), [VOP\_STRATEGY(9)](/VOP_STRATEGY/9.md), [VOP\_VPTOCNP(9)](/VOP_VPTOCNP/9.md), [VOP\_VPTOFH(9)](/VOP_VPTOFH/9.md)

## AUTHORS

This manual page was written by Doug Rabson.
