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" <tytso@mit.edu>
This commit is contained in:
Theodore Ts'o 2007-09-07 16:54:11 -04:00
parent ba9d929d91
commit cd538080ab
5 changed files with 12 additions and 6 deletions

View 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) {

View 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

View 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

View 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

View 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