__bread(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– __bread β€” read a block πŸ’–

okay so real talk, this one lives in the Kernel API Manual (__bread(9)), and it's genuinely one of those little functions that does exactly what the name says, which is iconic of it honestly.


✨ SYNOPSIS ✨

struct buffer_head * __bread (struct block_device *bdev , sector_t block
, unsigned size );

like, three args, one buffer head, zero drama 🫢


πŸŽ€ ARGUMENTS πŸŽ€

  • bdev β€” the block device you're reading from, bestie. that's the whole vibe.
  • block β€” the block number, and heads up: it's in units of block size, not bytes. don't be out here doing byte math, i'm begging 😭
  • size β€” the block size of this device, in bytes.

🌸 DESCRIPTION 🌸

So what it does is: read a specified block, and return the buffer head that refers to it. simple, clean, slay.

The memory is allocated from the movable area so that it can be migrated β€” yes, movable, it's giving flexible queen energy ✨

The returned buffer head has its refcount increased. not me stressing about refcounts but like, that's literally the whole point: the caller should call brelse when it has finished with the buffer. that's not optional, that's your responsibility, periodt πŸ’…

🚨 do NOT forget the brelse. the refcount is up, and only you can bring it back down. iykyk.

πŸ¦‹ CONTEXT πŸ¦‹

May sleep waiting for I/O. so like, it might nap on you. plan accordingly 🌈


πŸ’€ RETURN πŸ’€

Returns NULL if the block was unreadable. that's it, that's the failure mode β€” check it, bestie πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘

Kernel file ./include/linux/buffer_head.h, plus these absolute legends:


okay that's the whole page, go read your blocks responsibly πŸŽ€βœ¨

sign-off szn: this one came out of ./include/linux, dated October 2026. mwah, take care of your buffer heads for me πŸ’œπŸ”₯

πŸ“¦ where this page comes from