Whamcloud - gitweb
e2fsck: If the superblock is corrupt, automatically retry with the backup sb
authorTheodore Ts'o <tytso@mit.edu>
Fri, 7 Sep 2007 20:54:11 +0000 (16:54 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 7 Sep 2007 20:54:11 +0000 (16:54 -0400)
E2fsck currently only retries with the backup superblock if the
primary superblock is missing (e.g., overwritten with garbage).  If
the superblock is just corrupted enough that it looks like ext2/3/4
superblock, but it is corrupt enough that ext2fs_open2() returns an
error, e2fsck stops without retrying.  Let's fix this oversight.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck/unix.c
tests/f_crashdisk/expect.1
tests/f_misstable/expect.1
tests/f_zero_group/expect.1
tests/f_zero_super/expect.1

index f5d8560..950e2d4 100644 (file)
@@ -866,7 +866,7 @@ static const char *my_ver_date = E2FSPROGS_DATE;
                                        
 int main (int argc, char *argv[])
 {
-       errcode_t       retval = 0;
+       errcode_t       retval = 0, orig_retval = 0;
        int             exit_value = FSCK_OK;
        ext2_filsys     fs = 0;
        io_manager      io_ptr;
@@ -966,18 +966,23 @@ restart:
        if (!ctx->superblock && !(ctx->options & E2F_OPT_PREEN) &&
            !(ctx->flags & E2F_FLAG_SB_SPECIFIED) &&
            ((retval == EXT2_ET_BAD_MAGIC) ||
+            (retval == EXT2_ET_CORRUPT_SUPERBLOCK) ||
             ((retval == 0) && ext2fs_check_desc(fs)))) {
                if (!fs || (fs->group_desc_count > 1)) {
-                       printf(_("%s trying backup blocks...\n"),
-                              retval ? _("Couldn't find ext2 superblock,") :
+                       printf(_("%s: %s trying backup blocks...\n"),
+                              ctx->program_name, 
+                              retval ? _("Superblock invalid,") :
                               _("Group descriptors look bad..."));
                        get_backup_sb(ctx, fs, ctx->filesystem_name, io_ptr);
                        if (fs)
                                ext2fs_close(fs);
+                       orig_retval = retval;
                        goto restart;
                }
        }
        if (retval) {
+               if (orig_retval)
+                       retval = orig_retval;
                com_err(ctx->program_name, retval, _("while trying to open %s"),
                        ctx->filesystem_name);
                if (retval == EXT2_ET_REV_TOO_HIGH) {
index d12c3da..b6fd71a 100644 (file)
@@ -1,3 +1,4 @@
+../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 correct ext2
index ad1a133..93d4e89 100644 (file)
@@ -1,4 +1,4 @@
-Group descriptors look bad... trying backup blocks...
+../e2fsck/e2fsck: Group descriptors look bad... trying backup blocks...
 Inode table for group 1 is not in group.  (block 0)
 WARNING: SEVERE DATA LOSS POSSIBLE.
 Relocate? yes
index 2079619..577dadd 100644 (file)
@@ -1,4 +1,4 @@
-Group descriptors look bad... trying backup blocks...
+../e2fsck/e2fsck: Group descriptors look bad... trying backup blocks...
 Pass 1: Checking inodes, blocks, and sizes
 Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
index a7a6b48..029f3f1 100644 (file)
@@ -1,4 +1,4 @@
-Couldn't find ext2 superblock, trying backup blocks...
+../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
 Pass 1: Checking inodes, blocks, and sizes
 Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity