ext2_get_branch(9)
π ext2_get_branch β Kernel API Manual π
okay so bestie, welcome to ext2_get_branch(9), the little function that goes digging through the indirect block rabbit hole to find your data. iykyk. β¨
πΈ NAME πΈ
ext2_get_branch β literally just reads the chain of indirect blocks that lead to your data π¦
β¨ SYNOPSIS β¨
Indirect * ext2_get_branch (struct inode *inode , int depth , int *offsets , Indirect chain[4] , int *err );
that's the whole vibe, no cap. π
π ARGUMENTS π
inodeβ the inode in question π like, the one we're snooping ondepthβ depth of the chain (1is a direct pointer, etc. β you get the pattern)offsetsβ the offsets of the pointers, both in the inode and in the indirect blockschainβ the place where we store the result π«Ά that's its whole joberrβ and here's where we stash the error value, bestie
π DESCRIPTION π
so basically the function fills up an array of triples <key, p, bh>, and then it returns NULL if everything went OK β¨ β or, if it didn't, the pointer to the last filled triple (the incomplete one). either way you're getting something back, she's not leaving you on read. π
when it comes back to you, here's what's in each triple, no cap:
chain[i].keyholds the number of the(i+1)-th block in the chain β exactly as it's stored in memory, i.e. little-endian 32-bit π§chain[i].pholds the address of that number β and it points intostruct inodefori==0, and into thebh->b_datafori>0βchain[i].bhpoints to thebuffer_headof thei-th indirect block fori>0, and it'sNULLfori==0π
in other words (love an "in other words" moment), it holds the block numbers of the chain, the addresses they were taken from (which is also where we can verify that the chain did not change π€), and the buffer_heads hosting these numbers. iconic little trio honestly. π₯
now here's the tea on when it stops π« β she stops in any of these cases:
- it stumbles upon a zero pointer (an absent block) β pointer to the last triple is returned, and
*err == 0π - it gets an IO error reading an indirect block β ditto, and
*err == -EIOπ - it notices the chain had been changed while it was reading β ditto, and
*err == -EAGAINπ - it reads all
depth-1indirect blocks successfully and finds the whole entire chain, all the way down to the data β returnsNULL, and*err == 0πβ¨
π¦ SEE ALSO π¦
Kernel file ./fs/ext2/inode.c β and the whole friend group: ext2_block_to_path(9), ext2_find_near(9), ext2_find_goal(9), ext2_blks_to_allocate(9), ext2_alloc_blocks(9), ext2_alloc_branch(9), ext2_splice_branch(9), ext2_find_shared(9), ext2_free_data(9), ext2_free_branches(9) π
and that's the page!! brought to you by ./fs/ext2, dated October 2026 ποΈπΈ mwah, go read some inode code bestie, you've got this π«Άπ
π¦ 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