From: Theodore Ts'o Date: Fri, 7 Sep 2007 20:54:11 +0000 (-0400) Subject: e2fsck: If the superblock is corrupt, automatically retry with the backup sb X-Git-Tag: v1.40.3~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd538080ab6e4bf64886b42f0bfa2fa47d44d20d;p=thirdparty%2Fe2fsprogs.git 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" --- diff --git a/e2fsck/unix.c b/e2fsck/unix.c index f5d856046..950e2d4b0 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 d12c3dacc..b6fd71a86 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 ad1a1336d..93d4e8996 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 20796198d..577dadd46 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 a7a6b480d..029f3f149 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