Sfoglia il codice sorgente

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 anni fa
parent
commit
df758a5a51
1 ha cambiato i file con 7 aggiunte e 0 eliminazioni
  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);
     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.
     // 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());
     auto old_block_count = ceil_div(static_cast<size_t>(e2inode.i_size), block_size());