ext4_get_branch(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– ext4_get_branch β€” bestie's guide to the kernel API manual ✨

okay so like, this is ext4_get_branch(9) from the Kernel API Manual, and honestly? she's a baddie. let's get into it πŸŽ€


🌸 NAME 🌸

ext4_get_branch β€” read the chain of indirect blocks leading to data πŸ¦‹

like, the whole vibe is: follow the chain of indirect blocks until you find the actual data. it's giving treasure map energy iykyk πŸ’…


✨ SYNOPSIS ✨

Indirect * ext4_get_branch (struct inode *inode , int depth ,
       ext4_lblk_t *offsets , Indirect chain[4] , int *err );

no cap, that's the exact signature, don't come for me 😭


🫢 ARGUMENTS 🫢

  • inode β€” the inode in question, aka the main character πŸ‘‘
  • depth β€” depth of the chain (1 - direct pointer, etc.) β€” yes, that's literally how it's written, 1 - direct pointer, etc. 🧚
  • offsets β€” offsets of pointers in inode/indirect blocks
  • chain β€” place to store the result (she's the one holding everything together fr fr)
  • err β€” here we store the error value πŸ’€

πŸ”₯ DESCRIPTION πŸ”₯

so the function fills the array of triples <key, p, bh> and returns NULL if everything went OK, or the pointer to the last filled triple (the incomplete one) otherwise. periodt.

upon the return:

  • chain[i].key contains the number of (i+1)-th block in the chain (as it is stored in memory, i.e. little-endian 32-bit) β€” don't ask me why little-endian, that's just the lore πŸ¦‹
  • chain[i].p contains the address of that number (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 i-th indirect block for i>0 and NULL for i==0

in other words, it holds the block numbers of the chain, addresses they were taken from (and where we can verify that chain did not change) and buffer_heads hosting these numbers. literally the receipts for everything πŸ’…


πŸŽ€ when does she stop πŸŽ€

  • when it stumbles upon zero pointer (absent block) β†’ pointer to last triple returned, *err == 0
  • when it gets an IO error reading an indirect block β†’ ditto, *err == -EIO 😭
  • when it reads all depth-1 indirect blocks successfully and finds the whole chain, all way to the data β†’ returns NULL, *err == 0 slay ✨

⚠️ ok bestie listen: need to be called with down_read(EXT4_I(inode)->i_data_sem) β€” do NOT skip this, it's not optional, it's the vibe check 🌈

🌟 SEE ALSO 🌟

Kernel file ./fs/ext4/indirect.c:

ext4_block_to_path(9), ext4_find_near(9), ext4_find_goal(9), ext4_blks_to_allocate(9), ext4_alloc_branch(9), ext4_splice_branch(9), ext4_find_shared(9), ext4_free_data(9), ext4_free_branches(9), ext4_ind_remove_space(9)

the whole friend group fr, go read them too 🫢


and that's the page!! this icon came from ./fs/ext4, dated October 2026, and it's part of the ext4_get_branch(9) kernel API manual β€” mwah, love u, go read your indirect blocks responsibly πŸ’œπŸ₯°πŸ“

πŸ“¦ where this page comes from