Whamcloud - gitweb
e2fsck: allow to fix some superblock corruptions
authorJan Kara <jack@suse.cz>
Tue, 12 Jun 2018 09:53:23 +0000 (11:53 +0200)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 19 Jun 2018 15:27:27 +0000 (11:27 -0400)
Add a flag to ext2fs_open() which allows to open a filesystem even if
superblock is somewhat inconsistent. Use this flag from e2fsck as a last
resort to try to fix the superblok.

Currently, the flag does nothing. We'll relax checks in ext2fs_open()
once e2fsck is able to handle corresponding corruption gracefully.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/unix.c
lib/ext2fs/ext2fs.h
tests/f_crashdisk/expect.1
tests/f_detect_xfs/expect
tests/f_detect_xfs/expect.nodebugfs
tests/j_ext_dumpe2fs/expect

index cbe5ec5..55e21ea 100644 (file)
@@ -1364,7 +1364,7 @@ int main (int argc, char *argv[])
        const char      *lib_ver_date;
        int             my_ver, lib_ver;
        e2fsck_t        ctx;
-       blk64_t         orig_superblock;
+       blk64_t         orig_superblock = ~(blk64_t)0;
        struct problem_context pctx;
        int flags, run_result, was_changed;
        int journal_size;
@@ -1571,6 +1571,26 @@ failure:
                                             "check of the device.\n"));
 #endif
                else {
+                       /*
+                        * Let's try once more will less consistency checking
+                        * so that we are able to recover from more errors
+                        * (e.g. some tool messing up some value in the sb).
+                        */
+                       if (!(flags & EXT2_FLAG_IGNORE_SB_ERRORS)) {
+                               if (fs)
+                                       ext2fs_close_free(&fs);
+                               log_out(ctx, _("%s: Trying to load superblock "
+                                       "despite errors...\n"),
+                                       ctx->program_name);
+                               flags |= EXT2_FLAG_IGNORE_SB_ERRORS;
+                               /*
+                                * If we tried backup sb, revert to the
+                                * original one now.
+                                */
+                               if (orig_superblock != ~(blk64_t)0)
+                                       ctx->superblock = orig_superblock;
+                               goto restart;
+                       }
                        fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
                        if (retval == EXT2_ET_BAD_MAGIC)
                                check_plausibility(ctx->filesystem_name,
index 6774e32..250fd17 100644 (file)
@@ -195,6 +195,7 @@ typedef struct ext2_file *ext2_file_t;
 #define EXT2_FLAG_DIRECT_IO            0x80000
 #define EXT2_FLAG_SKIP_MMP             0x100000
 #define EXT2_FLAG_IGNORE_CSUM_ERRORS   0x200000
+#define EXT2_FLAG_IGNORE_SB_ERRORS     0x400000
 
 /*
  * Special flag in the ext2 inode i_flag field that means that this is
index 977a469..6898030 100644 (file)
@@ -1,6 +1,10 @@
 ext2fs_open2: The ext2 superblock is corrupt
 ../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
 ../e2fsck/e2fsck: The ext2 superblock is corrupt while trying to open test.img
+../e2fsck/e2fsck: Trying to load superblock despite errors...
+ext2fs_open2: The ext2 superblock is corrupt
+../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
+../e2fsck/e2fsck: The ext2 superblock is corrupt while trying to open test.img
 
 The superblock could not be read or does not describe a valid ext2/ext3/ext4
 filesystem.  If the device is valid and it really contains an ext2/ext3/ext4
index d0ece6a..06de99b 100644 (file)
@@ -2,6 +2,10 @@
 ext2fs_open2: Bad magic number in super-block
 ../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
 ../e2fsck/e2fsck: Bad magic number in super-block while trying to open test.img
+../e2fsck/e2fsck: Trying to load superblock despite errors...
+ext2fs_open2: Bad magic number in super-block
+../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
+../e2fsck/e2fsck: Bad magic number in super-block while trying to open test.img
 
 The superblock could not be read or does not describe a valid ext2/ext3/ext4
 filesystem.  If the device is valid and it really contains an ext2/ext3/ext4
index d3b7935..1a76952 100644 (file)
@@ -1,6 +1,8 @@
 *** e2fsck
 ext2fs_open2: Bad magic number in super-block
 ../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
+ext2fs_open2: Bad magic number in super-block
+../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
 ../e2fsck/e2fsck: Bad magic number in super-block while trying to open test.img
 
 The superblock could not be read or does not describe a valid ext2/ext3/ext4
index db77a36..a703bcf 100644 (file)
@@ -1,5 +1,7 @@
 e2fsck external journal
 ../e2fsck/e2fsck: Filesystem has unsupported feature(s) while trying to open test.img
+../e2fsck/e2fsck: Trying to load superblock despite errors...
+../e2fsck/e2fsck: Filesystem has unsupported feature(s) while trying to open test.img
 
 The superblock could not be read or does not describe a valid ext2/ext3/ext4
 filesystem.  If the device is valid and it really contains an ext2/ext3/ext4