]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: detect correct superblock adjustments when loading backup groups
authorDarrick J. Wong <darrick.wong@oracle.com>
Sat, 11 Jan 2014 18:54:57 +0000 (13:54 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 11 Jan 2014 18:55:20 +0000 (13:55 -0500)
If ext2fs_descriptor_block_loc2() is called with a meta_bg filesystem
and group_block is not the normal value, the function will return the
location of the backup group descriptor block in the next block group.
Unfortunately, it fails to account for the possibility that the backup
group contains a backup superblock but the regular superblock does
not.  This is the case with block groups 48-49 on a meta_bg fs with 1k
blocks; in this case, libext2fs will fail to open the filesystem.

Therefore, teach the function to adjust for superblocks in the backup
group, if necessary.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/openfs.c

index 4cdbde16d9bae1b0a92b9a1ad21cb68c124755cc..aac8894e1353c6ea21ddc6caab2f27a8f5af5d48 100644 (file)
@@ -47,7 +47,7 @@ blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs, blk64_t group_block,
        bg = EXT2_DESC_PER_BLOCK(fs->super) * i;
        if (ext2fs_bg_has_super(fs, bg))
                has_super = 1;
-       ret_blk = ext2fs_group_first_block2(fs, bg) + has_super;
+       ret_blk = ext2fs_group_first_block2(fs, bg);
        /*
         * If group_block is not the normal value, we're trying to use
         * the backup group descriptors and superblock --- so use the
@@ -57,10 +57,21 @@ blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs, blk64_t group_block,
         * have the infrastructure in place to do that.
         */
        if (group_block != fs->super->s_first_data_block &&
-           ((ret_blk + fs->super->s_blocks_per_group) <
-            ext2fs_blocks_count(fs->super)))
+           ((ret_blk + has_super + fs->super->s_blocks_per_group) <
+            ext2fs_blocks_count(fs->super))) {
                ret_blk += fs->super->s_blocks_per_group;
-       return ret_blk;
+
+               /*
+                * If we're going to jump forward a block group, make sure
+                * that we adjust has_super to account for the next group's
+                * backup superblock (or lack thereof).
+                */
+               if (ext2fs_bg_has_super(fs, bg + 1))
+                       has_super = 1;
+               else
+                       has_super = 0;
+       }
+       return ret_blk + has_super;
 }
 
 blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i)