ext4_free_data(9)
๐ ext4_free_data (kernel API manual, section 9, bestie)
okay so picture this: it's a kernel API manual page, section 9, and the function's whole name is ext4_free_data. That's it, that's the header. Now let's get into it ๐
โจ NAME โจ
ext4_free_data โ the girl whose entire job is freeing a list of data blocks. icon, honestly. she takes the blocks out and lets them go ๐ฆ
๐ธ SYNOPSIS ๐ธ
void ext4_free_data (handle_t *handle , struct inode *inode , struct
buffer_head *this_bh , __le32 *first , __le32 *last );
like literally five arguments, no return value, void as ever. slays quietly ๐
๐ ARGUMENTS ๐
handleโ the handle for this transaction. your backstage pass for this whole operation ๐๏ธinodeโ the inode we're dealing with. the main character of this little story ๐this_bhโ an indirectbuffer_headthat contains*firstand*last. (yes, the asterisks are load-bearing, this is C, bestie ๐ญ)firstโ an array of block numbers ๐งฎlastโ points immediately past the end of that array. not at the last element. past it. classic off-the-end situation ๐
๐ฆ DESCRIPTION ๐ฆ
so what are we even doing here? We're freeing all the blocks that get referred to from that array (and ngl the numbers in it are stored as little-endian 32-bit, that's just the vibe ๐), and we update inode->i_blocks appropriately while we're at it. bookkeeping queen ๐
Here's the cute part: we accumulate contiguous runs of blocks to free. Conveniently โ and I do mean conveniently, this is the good stuff โ if these blocks are contiguous, then releasing them at one time will only affect one or two bitmap blocks (plus group descriptor(s) and superblock), and we won't actually use a lot of journal space. efficiency! we love her! โญ lowkey obsessed with how tidy that is.
heads up ๐ซถ:this_bhwill beNULLiffirstandlastpoint into the inode's direct block pointers. so don't panic when you see aNULLthere, it's intentional, it's giving "different code path" ๐
๐ SEE ALSO ๐
Kernel file ./fs/ext4/indirect.c and honestly the whole friend group:
ext4_block_to_path(9)ext4_get_branch(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_branches(9)ext4_ind_remove_space(9)
go read them, iykyk ๐ฅ
okay that's the whole page, no cap ๐ this one came out of ./fs/ext4 โ that's the source โ and it's dated October 2026, from the Kernel API Manual, periodt. bye bestie, go free some blocks ๐โจ
๐ฆ 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