bdev_getblk(9)
π bdev_getblk(9)
ok so bestie, welcome to the Kernel API Manual page for bdev_getblk β yeah that's a section 9 manpage, kernel-internals territory, we're literally in the engine room rn π
β¨ NAME β¨
bdev_getblk β grab yourself a buffer_head from a block device's buffer cache. no cap, that's the whole job π
πΈ SYNOPSIS πΈ
struct buffer_head * bdev_getblk (struct block_device *bdev , sector_t
block , unsigned size , gfp_t gfp );
π¦ ARGUMENTS π¦
bdevβ the block device. the main character of this whole operation π«Άblockβ the block number. like, which block, bestie.sizeβ the size ofbuffer_heads for thisbdev.gfpβ the memory allocation flags to use. yes these are the flags, use them responsibly π
π DESCRIPTION π
ok so here's the tea β β the buffer head you get back has its reference count incremented, but ngl it is not locked. so don't go assuming you own it like that.
when you're done with the buffer, the caller should call brelse β that's literally the cleanup step, don't skip it, it's giving "return the thing you borrowed" energy π
also? the buffer may not be uptodate. which like β if you need it uptodate, that's a you problem, bestie. the caller can bring it uptodate either by reading it or by overwriting it. two options, both valid, choose your fighter β¨
β RETURN β
you get the buffer head π β¦or NULL if memory could not be allocated π (allocation said "not today").
π SEE ALSO π
kernel file ./fs/buffer.c β and the whole squad, fr fr:
bio_endio_bh(9)end_buffer_read_sync(9)bh_end_read(9)bh_end_write(9)bh_end_async_write(9)mmb_sync(9)block_dirty_folio(9)mark_buffer_dirty(9)__brelse(9)__bforget(9)bh_submit(9)__bread_gfp(9)block_invalidate_folio(9)clean_bdev_aliases(9)try_to_free_buffers(9)bh_uptodate_or_lock(9)__bh_read(9)__bh_read_batch(9)
reminder bestie: bump the refcount, call brelse when you're done, and never assume uptodate. those are the rules and they ate π
and that's the page!! brought to you by ./fs, October 2026 edition β mwah, go read some buffers, ily, bye ππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms