bmap(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’« bmap(9) β€” like, the Kernel API Manual page you didn't know you needed

okay so bestie, welcome to bmap(9) 🌸 this is one of those tiny little kernel API pages and honestly it's giving "small but mighty" energy. it's the bmap manpage from the Kernel API Manual and we're gonna read it together, mwah πŸ’…


✨ NAME ✨

bmap β€” find a block number in a file πŸ”

like… the whole personality is "where does this block actually live, fr fr".


πŸŽ€ SYNOPSIS πŸŽ€

int bmap (struct inode *inode , sector_t *block );

that's it. two args, one int coming back at you. iconic minimalism πŸ’–


πŸ¦‹ ARGUMENTS πŸ¦‹

  • inode β€” the inode that owns the block number you're asking about πŸ‘‘ like, whose block is this? this one.
  • block β€” a pointer holding the block you want to find πŸ“ it's a pointer, so yes, it gets written to. keep up bestie.

πŸ’… DESCRIPTION πŸ’…

okay so here's the vibe: bmap takes the value sitting in *block and replaces it with the block number on the device that corresponds to the requested block number in the file. 🫢

basically, if you ask for block 4 of inode 1, the function goes "say less" and swaps that 4 in *block for the actual disk block β€” relative to the start of the disk β€” that holds that block of the file. literally a glow-up from "file block" to "disk block" ✨

on the return situation:

  • if something goes wrong, it returns -EINVAL 😭
  • otherwise it returns 0 🌈
  • and nngh important one: if the mapping falls into a hole, it returns 0 and *block is also set to 0. so like, no block, no problem, but also… the block is zero now, don't forget that πŸ•³οΈ
not me stressing that *block gets mutated in the hole case too β€” fr fr, check it πŸ’€

🌟 SEE ALSO 🌟

buckle up bestie, this list is LONG and honestly it ate πŸ‘‘

Kernel file ./fs/inode.c plus all of these:

like, that's the whole inode friend group and bmap is invited to every party πŸ§šβ€β™€οΈ


and that's the page!! this one lives under ./fs and it's dated October 2026 β€” so mark your calendars bestie πŸ“… mwah, go map some blocks, ily πŸ’œ

πŸ“¦ where this page comes from