VOP_OPEN(9)
π VOP_OPEN(9) β kernel dev manual energy β¨
okay so bestie, we're in the VOP_OPEN(9) page today β yes it's a kernel developer's manual page, yes it's about vnodes, and yes you're gonna slay it π«Ά
πΈ NAME πΈ
VOP_OPEN, VOP_CLOSE β open or close a file, literally that's the whole vibe π
β¨ SYNOPSIS β¨
#include <sys/param.h>
#include <sys/vnode.h>
int
VOP_OPEN(struct vnode *vp, int mode, struct ucred *cred,
struct thread *td, struct file *fp);
int
VOP_CLOSE(struct vnode *vp, int mode, struct ucred *cred,
struct thread *td);
look at those signatures, so clean, so iconic π
π¦ DESCRIPTION π¦
so here's the tea β β the VOP_OPEN() entry point gets called before a file is accessed by a process, and VOP_CLOSE() gets called after a file is finished with by the process. that's it, that's the whole lifecycle arc, main character energy from start to finish π¬
now the arguments, because of course we're doing the arguments:
vpβ the vnode of the file. that's your girl πmodeβ the access mode required by the calling process.credβ the caller's credentials. yes, we're checking ids, no cap πͺͺtdβ the thread which is accessing the file.fpβ the file being opened.
a pointer to the file fp is genuinely useful for file systems which require such information, e.g., fdescfs(5). for in-kernel opens, just use NULL as the fp argument to VOP_OPEN() β lowkey handy π
the access mode is a set of flags, including FREAD, FWRITE, O_NONBLOCK, O_APPEND. flags on flags on flags, we love to see it π©
and the thread td passed to VOP_CLOSE() may be NULL if the last reference to the open file is released from a kernel context β like, for example, the destruction of a socket buffer containing the file reference in a SCM_RIGHTS message. so NULL td is not a bug, it's just the kernel doing kernel things π
π LOCKS π
okay this part matters, pay attention bestie π
VOP_OPEN() expects vp to be locked on entry, and will leave it locked on return. no funny business, it stays locked the whole time fr fr π
VOP_CLOSE() expects at least a reference to be associated with the vnode, and genuinely does not care whether the vnode is locked or not. the lock and reference state is left unchanged on return. but β and this is the important part β note that vn_close expects an unlocked, referenced vnode and will dereference the vnode prior to returning. so don't hand it a locked one, that's not the assignment π
β RETURN VALUES β
zero is returned on success. otherwise, an error code is returned. simple, clean, no notes π«
π SEE ALSO π
go read those next, iykyk π
π AUTHORS π
this manual page was written by Doug Rabson. legend behavior, honestly π«‘
and that's the whole page, bestie β go forth and open and close files responsibly π β¨
this lil sign-off comes to you from the Debian crew, dated October 17, 2025 β periodt π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- 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