ext2_get_branch(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 on
  • depth β€” depth of the chain (1 is a direct pointer, etc. β€” you get the pattern)
  • offsets β€” the offsets of the pointers, both in the inode and in the indirect blocks
  • chain β€” the place where we store the result 🫢 that's its whole job
  • err β€” 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].key holds 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].p holds the address of that number β€” and it points into struct inode for i==0, and into the bh->b_data for i>0 ⭐
  • chain[i].bh points to the buffer_head of the i-th indirect block for i>0, and it's NULL for i==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-1 indirect blocks successfully and finds the whole entire chain, all the way down to the data β†’ returns NULL, 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