VOP_OPEN(9)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms