From 39569a5ae8ca10160e9f62ffba70cc9e465b2295 Mon Sep 17 00:00:00 2001 From: Chaoqun Zheng Date: Thu, 29 Jan 2026 21:55:49 +0800 Subject: [PATCH] Remove allocating blocks operation from `InodeImpl::expand`. This is done to implement `fallocate`'s lazy file size expansion, meaning that the expanded trailing blocks are only actually allocated when they are written. --- kernel/src/fs/ext2/inode.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/kernel/src/fs/ext2/inode.rs b/kernel/src/fs/ext2/inode.rs index 27f4113de..7bf4fd6fa 100644 --- a/kernel/src/fs/ext2/inode.rs +++ b/kernel/src/fs/ext2/inode.rs @@ -1555,18 +1555,8 @@ impl InodeImpl { /// After a successful expansion, the size will be enlarged to `new_size`, /// which may result in an increased block count. fn expand(&mut self, new_size: usize) -> Result<()> { - let new_blocks = self.desc.size_to_blocks(new_size); - let old_blocks = self.desc.size_in_blocks(); - - // Expands block count if necessary - if new_blocks > old_blocks { - if new_blocks - old_blocks > self.fs().super_block().free_blocks_count() { - return_errno_with_message!(Errno::ENOSPC, "not enough free blocks"); - } - self.alloc_range_blocks(old_blocks..new_blocks)?; - } - - // Expands the size + // Only update the size, creating sparse blocks. + // Actual disk blocks will be allocated on-demand during writes. self.update_size(new_size); Ok(()) }