ext2_alloc_branch(9)
π 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 theirbuffer_heads) and return the error value from the failedext2_alloc_block(normally-ENOSPC). not-ENOSPCsometimes, normally-ENOSPCβ that's the actual deal. otherwise we set the chain as described above and return0π
π¦ SEE ALSO π¦
Kernel file ./fs/ext2/inode.c, plus the whole friend group:
ext2_block_to_path(9)ext2_get_branch(9)ext2_find_near(9)ext2_find_goal(9)ext2_blks_to_allocate(9)ext2_alloc_blocks(9)ext2_splice_branch(9)ext2_find_shared(9)ext2_free_data(9)ext2_free_branches(9)
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
- 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