BUF_LOCK(9)

πŸ’– BUF_LOCK(9) πŸ’–

okay so bestie, this is a Kernel Developer's Manual page β€” yes we're in the kernel now, we're not in userspace anymore, we're literally in the grown-up section of the manual, and honestly? iconic. ✨


🌸 NAME 🌸

BUF_LOCK β€” locks a buffer 🫢


✨ SYNOPSIS ✨

so first you gotta bring in the whole squad of headers, no skipping:

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/uio.h>
#include <sys/bio.h>
#include <sys/buf.h>

int
BUF_LOCK(struct buf *bp, int locktype);

πŸ’… DESCRIPTION πŸ’…

okay so the way that BUF_LOCK() works is: it locks the buffer you hand it. that's the whole vibe. πŸ”’

and here's the part you actually need to know, bestie β€” if the lock is already held by somebody else, this call will block until it can actually acquire the lock. like it's just gonna stand there in the group chat waiting for its turn, no matter how long it takes. unless you set LK_NOWAIT, in which case it does not do that. periodt.

now, its arguments, because we love a breakdown:

  • bp β€” the buffer you wanna lock. that's your main character right there. πŸ‘‘
  • locktype β€” flags that control what kind of lock you're getting. for the details on those, go read lockmgr(9), that's the source of truth, iykyk. 🧚

🌈 RETURN VALUES 🌈

you get a 0 back when it succeeds β€” slay, we love a clean win. ✨

for what all the non-zero return values mean, you gotta go check lockmgr(9), because that's where the lore lives. 😭


πŸ¦‹ SEE ALSO πŸ¦‹

the whole little friend group, go read them too:


πŸŽ€ AUTHORS πŸŽ€

this manual page was written by Chad David <davidc@acns.ab.ca>. thank you Chad, we appreciate you fr fr. πŸ’–


and that's the page bestie, no cap β€” written on this Debian system, dated July 9, 2001, from the Kernel Developer's Manual, section 9. she's vintage, she's got history, and she ate. πŸ’…β­πŸŒˆ
πŸ“¦ where this page comes from