ext4_alloc_branch(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… ext4_alloc_branch(9) πŸŽ€

okay bestie, quick vibe check β€” this is a page from the Kernel API Manual, and we're talking about ext4_alloc_branch, which is literally the glow-up artist for block chains ✨


🌸 NAME 🌸

ext4_alloc_branch β€” allocate and set up a chain of blocks πŸ’–


✨ SYNOPSIS ✨

int ext4_alloc_branch (handle_t *handle , struct ext4_allocation_request
*ar , int indirect_blks , ext4_lblk_t *offsets , Indirect *branch );

like, yes, that signature is a whole meal πŸ“


πŸ¦‹ ARGUMENTS πŸ¦‹

  • handle β€” the handle for this transaction, iykyk 🫢
  • ar β€” the structure describing the allocation request
  • indirect_blks β€” the number of allocated indirect blocks
  • offsets β€” the offsets (in the blocks) where we stash the pointers to next. lowkey crucial.
  • branch β€” the place to store the chain in πŸ‘‘

πŸ’… DESCRIPTION πŸ’…

okay so here's the lore 🧚 this function allocates blocks, zeroes out all but the last one, links them into a chain, and β€” if we are synchronous β€” writes them to disk. no cap. in other words, it prepares a branch that can be spliced onto the inode, main character energy fr fr πŸ”₯

it stores the information about that chain in the branch[], in the same format as ext4_get_branch would do. we are calling it after we had read the existing part of the chain and partial points to the last triple of that (the one with zero ->key). upon exit we have the same picture as after the successful ext4_get_block, except that in one place the chain is disconnected β€” *branch->p is still zero (we did not set the last link), but branch->key contains the number that should be placed into *branch->p to fill that gap. it's giving "almost done, one tiny thing left" 😭

if allocation fails we free all the blocks we've allocated (and forget their buffer_heads) and return the error value from the failed ext4_alloc_block (normally -ENOSPC). otherwise we set the chain as described above and return 0. periodt. πŸ’€

🌈 SEE ALSO 🌈

kernel file ./fs/ext4/indirect.c β€” plus the whole squad:


that's the whole page bestie, go slay some indirect blocks πŸ’œ

signed off with love from ./fs/ext4 β€” dated October 2026 β€” and yeah, this was ext4_alloc_branch(9) the whole time πŸŽ€

πŸ“¦ where this page comes from