From cd538080ab6e4bf64886b42f0bfa2fa47d44d20d Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 7 Sep 2007 16:54:11 -0400 Subject: [PATCH] e2fsck: If the superblock is corrupt, automatically retry with the backup sb 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" --- e2fsck/unix.c | 11 ++++++++--- tests/f_crashdisk/expect.1 | 1 + tests/f_misstable/expect.1 | 2 +- tests/f_zero_group/expect.1 | 2 +- tests/f_zero_super/expect.1 | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/e2fsck/unix.c b/e2fsck/unix.c index f5d8560..950e2d4 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -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) { diff --git a/tests/f_crashdisk/expect.1 b/tests/f_crashdisk/expect.1 index d12c3da..b6fd71a 100644 --- a/tests/f_crashdisk/expect.1 +++ b/tests/f_crashdisk/expect.1 @@ -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 diff --git a/tests/f_misstable/expect.1 b/tests/f_misstable/expect.1 index ad1a133..93d4e89 100644 --- a/tests/f_misstable/expect.1 +++ b/tests/f_misstable/expect.1 @@ -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 diff --git a/tests/f_zero_group/expect.1 b/tests/f_zero_group/expect.1 index 2079619..577dadd 100644 --- a/tests/f_zero_group/expect.1 +++ b/tests/f_zero_group/expect.1 @@ -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 diff --git a/tests/f_zero_super/expect.1 b/tests/f_zero_super/expect.1 index a7a6b48..029f3f1 100644 --- a/tests/f_zero_super/expect.1 +++ b/tests/f_zero_super/expect.1 @@ -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 -- 1.8.3.1