VNODE(9)
π VNODE(9) π
okay bestie, welcome to the Kernel Developer's Manual β today's main character is vnode(9), and honestly? it ate. let's get into it π«Ά
β¨ NAME β¨
vnode β the internal representation of a file or directory. like, the whole vibe of a file, condensed into one struct. iconic π
π SYNOPSIS π
#include <sys/param.h>
#include <sys/vnode.h>
that's it. two includes. slay.
π¦ DESCRIPTION π¦
so the vnode is, like, the focus of all file activity in Unix. everything orbits it. it's described by struct vnode, and ngl there is a unique vnode allocated for each active file, each current directory, each mounted-on file, text file, and the root. one each. no sharing. main character energy only π
every vnode has three reference counts: v_usecount, v_holdcnt, and v_writecount. let me break it down:
v_usecountβ the number of clients within the kernel which are using this vnode. this one's 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).v_writecountβ a count of the number of clients which are writing into the file. maintained by theopen(2)andclose(2)system calls.
and here's the tea β β when both the v_usecount and the v_holdcnt of 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 by getnewvnode(9). recycling era β»οΈ
any call which returns a vnode (e.g., vget(9), VOP_LOOKUP(9), etc.) will increase the v_usecount of the vnode by one. and 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. don't forget, bestie, or you'll leak it π
other commonly used members of the vnode structure, because the girlies love a struct tour:
v_idβ used to maintain consistency in the name cachev_mountβ points at the file system which owns the vnodev_typeβ contains the type of object the vnode representsv_dataβ used by file systems to store file system specific data with the vnodev_opβ used by theVOP_*()functions to call functions in the file system which implement the vnode's functionality
and the VOP_*() function declarations and definitions are generated from sys/kern/vnode_if.src by the sys/tools/vnode_if.awk script. the interfaces are documented in their respective manual pages like VOP_READ(9) and VOP_WRITE(9). go read those, iykyk π
π§ VNODE TYPES π§
the type check!! every vnode has to pick a lane π«
VNONβ No type. a mystery. unlabeled.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. sorry bestie πVFIFOβ A FIFO (named pipe). Advisory locking will not work on this. same deal πVBADβ Indicates that the vnode has been reclaimed. rip, it's over π
π IMPLEMENTATION NOTES π
so here's where it gets a little unhinged, but we love her anyway:
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. it's giving "we'll finish that later" π«
β οΈ also major warning: 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. no cap, don't do it π¨
π FILES π
sys/kern/vnode_if.srcβ The input file forsys/tools/vnode_if.awk.sys/tools/vnode_if.awkβ The script generating the source code of theVOP_*()functions.
β 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_READ_PGCACHE(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_SETLABEL(9), VOP_STRATEGY(9), VOP_VPTOCNP(9), VOP_VPTOFH(9)
like, that's the whole friend group. go say hi π
πΈ AUTHORS πΈ
This manual page was written by Doug Rabson. thank you king π«Ά
and that's the page!! this lil beauty came from the Debian crew, dated July 15, 2025, and it's filed under VNODE(9) in section 9. mwah πβ¨ π¦
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 1996 Doug Rabson
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms