summaryrefslogtreecommitdiff
path: root/e2fsck
diff options
context:
space:
mode:
authorDaniel Drake <d.drake@mmm.com>2007-05-31 11:56:17 -0400
committerTheodore Ts'o <tytso@mit.edu>2007-05-31 11:56:17 -0400
commite7b5d3c0b2bb1bafc5be57796ac1b68b1ac8e983 (patch)
treecb6bec2899c2b93ac611908690af59601bd9231d /e2fsck
parent8f234d9650eb6f6a897148d5136cb27f373de4a7 (diff)
downloade2fsprogs-e7b5d3c0b2bb1bafc5be57796ac1b68b1ac8e983.tar.gz
e2fsck: Add blocksize sanity check when finding a backup superblock
I've been investigating why e2fsck refuses to restore the backup superblock of a partition with a broken primary superblock. The partition in question has a block size of 4096, and mke2fs reports that backup superblocks were created on blocks 32768, 98304, 163840, ... When running e2fsck, get_backup_sb starts by guessing a block size of 1024 and backup superblock at block 8193. I'm not sure why, but it actually finds a superblock at this location, so returns a context with superblock 8193, blocksize 1024. Later on, ext2fs_open2() tries to process this superblock. It then realises that the block size value stored in the superblock (4096) does not match what it was told (1024), so it bails out with EXT2_ET_UNEXPECTED_BLOCK_SIZE. fsck aborts without fixing the partition. The following patch solves the problem by discounting superblocks which do not meet the currently-sought block size. As a result, block 32768 (blocksize=4096) is now used to restore the backup, which agrees with the first location that mke2fs listed. Signed-off-by: Daniel Drake <d.drake@mmm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'e2fsck')
-rw-r--r--e2fsck/ChangeLog3
-rw-r--r--e2fsck/util.c3
2 files changed, 5 insertions, 1 deletions
diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog
index e6b0fdfe..a6df3618 100644
--- a/e2fsck/ChangeLog
+++ b/e2fsck/ChangeLog
@@ -1,5 +1,8 @@
2007-05-31 Theodore Tso <tytso@mit.edu>
+ * util.c (get_backup_sb): Do basic sanity checking to make sure
+ the blocksize of the superblock passes muster.
+
* profile.c (profile_node_iterator): Avoid potential null
dereference bug.
diff --git a/e2fsck/util.c b/e2fsck/util.c
index 2ff3c6f6..f761ebba 100644
--- a/e2fsck/util.c
+++ b/e2fsck/util.c
@@ -455,7 +455,8 @@ blk_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, const char *name,
if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
ext2fs_swap_super(sb);
#endif
- if (sb->s_magic == EXT2_SUPER_MAGIC) {
+ if ((sb->s_magic == EXT2_SUPER_MAGIC) &&
+ (EXT2_BLOCK_SIZE(sb) == blocksize)) {
ret_sb = superblock;
if (ctx) {
ctx->superblock = superblock;