VOP_RDWR(9)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’… VOP_RDWR β€” the kernel dev manual, section 9, bestie

okay so this is VOP_RDWR(9) from the Kernel Developer's Manual (section 9, the kernel-dev one, not the user-command one β€” iykyk) and it's literally the whole tea on reading and writing file contents at the vnode layer. pull up a chair. πŸŽ€


✨ NAME ✨

VOP_READ, VOP_WRITE β€” read or write a file


✨ SYNOPSIS ✨

#include <sys/param.h>
#include <sys/vnode.h>
#include <sys/uio.h>

int
VOP_READ(struct vnode *vp, struct uio *uio, int ioflag,
    struct ucred *cred);

int
VOP_WRITE(struct vnode *vp, struct uio *uio, int ioflag,
    struct ucred *cred);

✨ DESCRIPTION ✨

these are the entry points that read or write the actual contents of a file. main character energy, honestly. 🌟

the arguments are:

  • vp β€” the vnode of the file. the whole file's little identity card. πŸͺͺ
  • uio β€” the location of the data to be read or written. where the goods live.
  • ioflag β€” various flags. (we get into these, don't worry)
  • cnp β€” the credentials of the caller. yes bestie, the arg rundown literally says cnp while the synopsis says cred β€” that's just how the page is written, no cap, we're keeping it exactly as-is. πŸ™ˆ

🌸 the ioflag situation (this is the good part)

so the ioflag argument is how you give directives and hints to the file system. when you're attempting a read, the high 16 bits are used to provide a read-ahead hint (in units of file system blocks) that the file system should attempt. cute, right? ✨

the low 16 bits are a bit mask which can contain the following flags:

  • IO_UNIT β€” do I/O as atomic unit. all-or-nothing vibes. πŸ’…
  • IO_APPEND β€” append write to end. no cutting the line.
  • IO_SYNC β€” do I/O synchronously. we wait. we're patient. 🧚
  • IO_NODELOCKED β€” underlying node already locked. somebody got here first.
  • IO_NDELAY β€” FNDELAY flag set in file table.
  • IO_VMIO β€” data already in VMIO space. been there, done that. πŸ‘‘

πŸ”’ LOCKS πŸ”’

the file should be locked on entry and will still be locked on exit. like, you hold the lock the whole time, you don't drop it, periodt. πŸ”₯

also: a rangelock covering the whole i/o range should be owned around the call.


🫢 RETURN VALUES 🫢

zero is returned on success πŸŽ‰ β€” otherwise an error code is returned. 😭


πŸ’€ ERRORS πŸ’€

  • [EFBIG] β€” an attempt was made to write a file that exceeds the process's file size limit or the maximum file size. too big, babe.
  • [ENOSPC] β€” the file system is full. it's giving crowded elevator. πŸ“
  • [EPERM] β€” an append-only flag is set on the file, but the caller is attempting to write before the current end of file. rude, honestly.

🌈 SEE ALSO 🌈

uiomove(9), vnode(9)


πŸ‘‘ AUTHORS πŸ‘‘

this manual page was written by Doug Rabson. iconic of him, fr fr. 🫢


quick vibe check before you go: this page is a kernel developer's page, so nothing here is deprecated or undefined-behaviour-flagged in the original β€” it's just the straight-up contract. read the flags carefully, hold your locks, and you're slaying. πŸ’–

that's the whole page, bestie β€” originally dated July 24, 1996, shipped under the Debian banner, and still living rent-free in VOP_RDWR(9) to this day. mwah. πŸ’‹

πŸ“¦ where this page comes from