From df758a5a5163407c06165730a90a729f45eb7984 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 23 Nov 2020 12:30:12 +0100 Subject: [PATCH] Ext2FS: Clear out the direct block list when an inode is resized to 0 e2fsck was complaining about blocks being allocated in an inode's list of direct blocks while at the same time being free in the block bitmap. It was easy to reproduce by creating a file with non-zero length and then truncating it. This fixes the issue by clearing out the direct block list when resizing a file to 0. --- Kernel/FileSystem/Ext2FileSystem.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 10750282f5..5f6ec4d313 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -227,6 +227,13 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in { LOCKER(m_lock); + if (blocks.is_empty()) { + e2inode.i_blocks = 0; + memset(e2inode.i_block, 0, sizeof(e2inode.i_block)); + write_ext2_inode(inode_index, e2inode); + return true; + } + // NOTE: There is a mismatch between i_blocks and blocks.size() since i_blocks includes meta blocks and blocks.size() does not. auto old_block_count = ceil_div(static_cast(e2inode.i_size), block_size());