__bread_gfp(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– __bread_gfp β€” a kernel API manual, but make it cute πŸ’–

okay so this one lives in the Kernel API Manual (section 9, kernel functions, iykyk) and it's literally called __bread_gfp. yes bestie, bread. it reads a block. we love a carb-loaded syscall-adjacent moment 🍞✨


✨ NAME ✨

__bread_gfp β€” Read a block. that's it. that's the whole vibe. 🫢


🌸 SYNOPSIS 🌸

struct buffer_head * __bread_gfp (struct block_device *bdev , sector_t
block , unsigned size , gfp_t gfp );

look at her. four arguments, one struct buffer_head * return, main character energy fr fr πŸ‘‘


πŸŽ€ ARGUMENTS πŸŽ€

  • bdev β€” The block device to read from. like, where the data actually lives πŸ’Ύ
  • block β€” Block number in units of block size. not bytes, bestie, blocks β€” don't get it twisted πŸ™ˆ
  • size β€” The block size of this device in bytes. πŸ“
  • gfp β€” Not page allocation flags; see below. ⚠️ okay this one's a trap, more on that in a sec

πŸ’… DESCRIPTION πŸ’…

🚨 real talk first: You are not expected to call this function. The manpage says it, I'm saying it, we're all saying it. You should use one of sb_bread, sb_bread_unmovable or __bread instead. periodt.

So what does she do? Read a specified block, and return the buffer head that refers to it. simple, iconic, done. πŸ¦‹

Now the gfp tea β˜• β€” this is where people mess up:

  • If gfp is 0, the memory will be allocated using the block device's default GFP flags.
  • If gfp is __GFP_MOVABLE, the memory may be allocated from a movable area. 🚚
  • Do not pass in a complete set of GFP flags. like, I'm begging you. don't. 😭

And the returned buffer head? It has its refcount increased. so the caller should call brelse when it has finished with the buffer. don't just wander off and leave her hanging, that's so not slay πŸ’€


⭐ CONTEXT ⭐

May sleep waiting for I/O. 😴 so like, don't call her somewhere you can't nap. she's gonna wait for the disk, it's giving "loading screen but make it kernel" 🌈


🌟 RETURN 🌟

  • NULL if the block was unreadable. πŸ˜” yeah. she can come back empty-handed. handle it.

πŸ‘‘ SEE ALSO πŸ‘‘

Kernel file ./fs/buffer.c β€” and honestly the whole friend group:

that's the whole group chat, no cap πŸ’œ


and that's the page!! πŸŽ€ she comes from ./fs, dated October 2026, and she's filed under __bread_gfp(9) β€” go read a block bestie, but like, through sb_bread or __bread, please, I'm literally asking πŸ™πŸ’–

πŸ“¦ where this page comes from