VOP_STRATEGY(9)

πŸ’… VOP_STRATEGY β€” the "read or write a file system buffer" page (yes bestie, it's a section 9 kernel dev manual, come thru)

okay so. if you're poking at the guts of a kernel, VOP_STRATEGY(9) is the lil' vnode operation that does the actual I/O for a file system buffer. she reads, she writes, she blocks. main character energy, no cap. πŸŽ€


✨ SYNOPSIS ✨

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

int
VOP_STRATEGY(struct vnode *vp, struct buf *bp);

like literally just two headers and one function, we love a minimal slay πŸ’–


🌸 DESCRIPTION 🌸

so here's the tea on the arguments:

  • vp β€” the vnode that the buffer is for. it's giving "whose buffer is this" energy πŸ¦‹
  • bp β€” the buffer that's getting read or written. the moment of truth.

this call either reads or writes data from a file, and which one it does depends entirely on the value of bp->b_io.bio_cmd. so like, check that field, bestie, it's the vibe check of the whole operation πŸ”₯

the call may block. so don't be out here acting surprised when it does. she's allowed to take her time. periodt.

πŸ’« RETURN VALUES πŸ’«

okay so this is the part where it gets a little unhinged: this function always returns zero. zero. always. 0. every single time. 🀑

so how do errors get reported?? not via the return value, that's for sure. if something goes wrong you have to:

  • set BIO_ERROR on the b_ioflags field in struct buf, and
  • set b_error to the appropriate errno value.

that's the whole entire protocol. set the flag, set the errno, return 0, go about your day. iconic behaviour honestly πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘

go read those too, iykyk πŸ“š


🫢 AUTHORS 🫢

this manual page was written by Doug Rabson. thank u doug, we love u, ur doing amazing sweetie πŸ’œ


and that's the whole page, bestie!! this one comes to you from the Debian crew, dated February 2, 2014 β€” an absolute classic, a real vintage moment, and she still hits. now go read buf(9) like i told you. mwah πŸŒˆπŸ’–βœ¨

πŸ“¦ where this page comes from