Whamcloud - gitweb
mke2fs: allow file systems w/ uninit_bg to be recovered with mke2fs -S
authorTheodore Ts'o <tytso@mit.edu>
Fri, 17 Feb 2012 04:16:34 +0000 (23:16 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 17 Feb 2012 20:28:20 +0000 (15:28 -0500)
The command mke2fs -S is used as a last ditch recovery command to
write new superblock and block group descriptors, but _not_ to destroy
the inode table in hopes of recovering from a badly corrupted file
system.  If the uninit_bg feature is enabled, we need to make sure to
clear the unused inodes count field in the block group descriptors or
else e2fsck -fy will leave the file system completely empty.

Thanks to Akira Fujita for reporting this problem.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
misc/mke2fs.c

index 08789c4..c70c1b4 100644 (file)
@@ -2434,6 +2434,17 @@ int main (int argc, char *argv[])
        if (super_only) {
                fs->super->s_state |= EXT2_ERROR_FS;
                fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY);
+               /* 
+                * The command "mke2fs -S" is used to recover
+                * corrupted file systems, so do not mark any of the
+                * inodes as unused; we want e2fsck to consider all
+                * inodes as potentially containing recoverable data.
+                */
+               if (fs->super->s_feature_ro_compat &
+                   EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
+                       for (i = 1; i < fs->group_desc_count; i++)
+                               ext2fs_bg_itable_unused_set(fs, i, 0);
+               }
        } else {
                /* rsv must be a power of two (64kB is MD RAID sb alignment) */
                blk64_t rsv = 65536 / fs->blocksize;