소스 검색

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.
Andreas Kling 4 년 전
부모
커밋
df758a5a51
1개의 변경된 파일7개의 추가작업 그리고 0개의 파일을 삭제
  1. 7 0
      Kernel/FileSystem/Ext2FileSystem.cpp

+ 7 - 0
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<size_t>(e2inode.i_size), block_size());