ext2_alloc_branch(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– ext2_alloc_branch β€” the manual page, but make it cute πŸ’–

okay so this is ext2_alloc_branch from the Kernel API Manual, and bestie, it's giving "block chain construction site" πŸ—οΈβœ¨


🌸 NAME 🌸

ext2_alloc_branch β€” allocate and set up a chain of blocks, no cap πŸ’…


✨ SYNOPSIS ✨

int ext2_alloc_branch (struct inode *inode , int indirect_blks , int
*blks , ext2_fsblk_t goal , int *offsets , Indirect *branch );

like. look at her. iconic signature, zero notes πŸ‘‘


πŸŽ€ ARGUMENTS πŸŽ€

  • inode β€” the owner. the main character whose blocks these are 🫢
  • indirect_blks β€” depth of the chain (number of blocks to allocate). yes that's the actual definition, i'm not making it up πŸ¦‹
  • blks β€” number of allocated direct blocks πŸ’«
  • goal β€” preferred place for allocation. it's a preference, not a promise, so don't come for her if she doesn't land there πŸ™ˆ
  • offsets β€” offsets (in the blocks) to store the pointers to next πŸ”—
  • branch β€” place to store the chain in. this is where the whole finished fit gets modeled πŸ’ƒ

πŸ”₯ DESCRIPTION πŸ”₯

So. This function allocates num blocks, zeroes out all but the last one, links them into a chain, and β€” if we're synchronous β€” writes them to disk. that's the whole vibe check right there ⭐

In other words? it prepares a branch that can be spliced onto the inode. she's literally prepping a whole new limb for the inode and then handing it over for the graft 🧚

She stores all the info about that chain in branch[], in the same format as ext2_get_branch would do β€” consistency queen, we stan πŸ’œ

Timing matters here, so let me spell it out: we're calling it after we've already read the existing part of the chain, and partial points to the last triple of that (one with zero ->key). ngl that "one with zero ->key" detail is the important one, don't skip it πŸ‘€

On exit you get the same picture as after a successful ext2_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. that's your little gap. that's your little open loop. that's the assignment πŸ’€βœ¨

And if allocation fails? she cleans up after herself the whole way down: we free all blocks we've allocated (and forget their buffer_heads) and return the error value from the failed ext2_alloc_block (normally -ENOSPC). not -ENOSPC sometimes, normally -ENOSPC β€” that's the actual deal. otherwise we set the chain as described above and return 0 🌈

πŸ¦‹ SEE ALSO πŸ¦‹

Kernel file ./fs/ext2/inode.c, plus the whole friend group:

iykyk 🫢


okay that's the whole page, go slay πŸ’…

🌟 this one ships from ./fs/ext2 and is dated October 2026 β€” that's the source and the version and the date, all wrapped up with a bow πŸŽ€ ily, bye! πŸ‘‘

πŸ“¦ where this page comes from