bmap(9)
π« 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
0and*blockis also set to0. 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:
inode_init_always_gfp(9)alloc_inode(9)drop_nlink(9)clear_nlink(9)set_nlink(9)inc_nlink(9)inode_sb_list_add(9)__insert_inode_hash(9)__remove_inode_hash(9)evict_inodes(9)new_inode(9)unlock_new_inode(9)lock_two_nondirectories(9)unlock_two_nondirectories(9)inode_insert5(9)iget5_locked(9)iget5_locked_rcu(9)iget_locked(9)iunique(9)ihold(9)ilookup5_nowait(9)ilookup5(9)ilookup(9)find_inode_nowait(9)find_inode_rcu(9)find_inode_by_ino_rcu(9)iput(9)iput_not_last(9)inode_update_time(9)generic_update_time(9)atime_needs_update(9)file_remove_privs(9)current_time(9)file_update_time(9)file_modified_flags(9)file_modified(9)kiocb_modified(9)inode_init_owner(9)inode_owner_or_capable(9)inode_dio_wait(9)timestamp_truncate(9)inode_set_ctime_current(9)inode_set_ctime_deleg(9)in_group_or_capable(9)mode_strip_sgid(9)dump_inode(9)
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
- 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