VNODE(9)
π VNODE(9) β the Kernel Developer's Manual glow-up π
okay bestie, gather round, because today we're talking about vnode(9) and honestly? it's the main character of the entire Unix filesystem. no cap. π«Ά
β¨ NAME β¨
vnode β the internal representation of a file or directory. literally what a file is, on the inside. π
β¨ SYNOPSIS β¨
#include <sys/param.h>
#include <sys/vnode.h>
like, include both, don't skip the first one, she's there for a reason. π
β¨ DESCRIPTION β¨
okay so. the vnode is the focus of all file activity in Unix. everything. all of it. every file thing that happens? a vnode is involved. periodt.
a vnode is described by struct vnode. and here's the vibe: there is a unique vnode allocated for each active file, each current directory, each mounted-on file, each text file, and the root. like each one gets her own. π
π« the three reference counts (yes, three, she's busy)
v_usecountβ the number of clients within the kernel which are using this vnode. this one is maintained byvref(9),vrele(9)andvput(9).v_holdcntβ the number of clients within the kernel who veto the recycling of this vnode. maintained byvhold(9)andvdrop(9). so when both thev_usecountand thev_holdcntof a vnode reaches zero, the vnode gets put on the freelist and may be reused for another file β possibly in another file system π³. the transition from the freelist is handled bygetnewvnode(9).v_writecountβ a count of the number of clients which are writing into the file. maintained by theopen(2)andclose(2)system calls.
π¦ the rules of holding a vnode
any call which returns a vnode (e.g., vget(9), VOP_LOOKUP(9), etc.) will increase the v_usecount of the vnode by one. that's the deal.
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. π
bestie please actually release it. the reference is not a souvenir. π
πΈ other commonly used members of the vnode structure
v_idβ used to maintain consistency in the name cache.v_mountβ points at the file system which owns the vnode.v_typeβ contains the type of object the vnode represents.v_dataβ used by file systems to store file system specific data with the vnode.v_opβ used by theVOP_*macros to call functions in the file system which implement the vnode's functionality.
it's giving "small struct, enormous responsibility". π
β¨ VNODE TYPES β¨
the v_type field, but make it a personality quiz:
VNONβ No type. (mystery era π)VREGβ A regular file; may be with or without VM object backing. If you want to make sure this get a backing object, callvnode_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, callvnode_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. she's gone, she's resting, don't call her. π
β¨ IMPLEMENTATION NOTES β¨
VFIFOuses the"struct fileops"from/sys/kern/sys_pipe.c.VSOCKuses 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. lore. π
and now the warning, listen up:
Calls tomalloc(9)orfree(9)when holding a vnode interlock, will cause a LOR (Lock Order Reversal) due to the intertwining of VM Objects and Vnodes.
do not do this. not even once. π
β¨ SEE ALSO β¨
malloc(9), VFS(9), VOP_ACCESS(9), VOP_ACLCHECK(9), VOP_ADVISE(9), VOP_ADVLOCK(9), VOP_ALLOCATE(9), VOP_ATTRIB(9), VOP_BWRITE(9), VOP_CREATE(9), VOP_FSYNC(9), VOP_GETACL(9), VOP_GETEXTATTR(9), VOP_GETPAGES(9), VOP_INACTIVE(9), VOP_IOCTL(9), VOP_LINK(9), VOP_LISTEXTATTR(9), VOP_LOCK(9), VOP_LOOKUP(9), VOP_OPENCLOSE(9), VOP_PATHCONF(9), VOP_PRINT(9), VOP_RDWR(9), VOP_READDIR(9), VOP_READLINK(9), VOP_REALLOCBLKS(9), VOP_REMOVE(9), VOP_RENAME(9), VOP_REVOKE(9), VOP_SETACL(9), VOP_SETEXTATTR(9), VOP_STRATEGY(9), VOP_VPTOCNP(9), VOP_VPTOFH(9)
that's the whole friend group. go say hi. π
β¨ AUTHORS β¨
This manual page was written by Doug Rabson. king behaviour, honestly. π
and that's the tea, bestie π this one shipped with Debian, dated February 12, 2014, and it's still iconic. slay, vnode, slay. β¨π¦ππ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1996 Doug Rabson
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms