Blame SOURCES/e2fsprogs-1.42.9-libext2fs-detect-correct-superblock-adjustments-when.patch

68923e
From 35da59eaf201d5935d7047657355f129f3791d9a Mon Sep 17 00:00:00 2001
68923e
From: "Darrick J. Wong" <darrick.wong@oracle.com>
68923e
Date: Sat, 11 Jan 2014 13:54:57 -0500
68923e
Subject: [PATCH 1/2] libext2fs: detect correct superblock adjustments when
68923e
 loading backup groups
68923e
68923e
If ext2fs_descriptor_block_loc2() is called with a meta_bg filesystem
68923e
and group_block is not the normal value, the function will return the
68923e
location of the backup group descriptor block in the next block group.
68923e
Unfortunately, it fails to account for the possibility that the backup
68923e
group contains a backup superblock but the regular superblock does
68923e
not.  This is the case with block groups 48-49 on a meta_bg fs with 1k
68923e
blocks; in this case, libext2fs will fail to open the filesystem.
68923e
68923e
Therefore, teach the function to adjust for superblocks in the backup
68923e
group, if necessary.
68923e
68923e
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
68923e
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
68923e
---
68923e
 lib/ext2fs/openfs.c | 19 +++++++++++++++----
68923e
 1 file changed, 15 insertions(+), 4 deletions(-)
68923e
68923e
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
68923e
index 2c6e10e..b27bf19 100644
68923e
--- a/lib/ext2fs/openfs.c
68923e
+++ b/lib/ext2fs/openfs.c
68923e
@@ -47,7 +47,7 @@ blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs, blk64_t group_block,
68923e
 	bg = EXT2_DESC_PER_BLOCK(fs->super) * i;
68923e
 	if (ext2fs_bg_has_super(fs, bg))
68923e
 		has_super = 1;
68923e
-	ret_blk = ext2fs_group_first_block2(fs, bg) + has_super;
68923e
+	ret_blk = ext2fs_group_first_block2(fs, bg);
68923e
 	/*
68923e
 	 * If group_block is not the normal value, we're trying to use
68923e
 	 * the backup group descriptors and superblock --- so use the
68923e
@@ -57,10 +57,21 @@ blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs, blk64_t group_block,
68923e
 	 * have the infrastructure in place to do that.
68923e
 	 */
68923e
 	if (group_block != fs->super->s_first_data_block &&
68923e
-	    ((ret_blk + fs->super->s_blocks_per_group) <
68923e
-	     ext2fs_blocks_count(fs->super)))
68923e
+	    ((ret_blk + has_super + fs->super->s_blocks_per_group) <
68923e
+	     ext2fs_blocks_count(fs->super))) {
68923e
 		ret_blk += fs->super->s_blocks_per_group;
68923e
-	return ret_blk;
68923e
+
68923e
+		/*
68923e
+		 * If we're going to jump forward a block group, make sure
68923e
+		 * that we adjust has_super to account for the next group's
68923e
+		 * backup superblock (or lack thereof).
68923e
+		 */
68923e
+		if (ext2fs_bg_has_super(fs, bg + 1))
68923e
+			has_super = 1;
68923e
+		else
68923e
+			has_super = 0;
68923e
+	}
68923e
+	return ret_blk + has_super;
68923e
 }
68923e
 
68923e
 blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i)
68923e
-- 
68923e
2.17.1
68923e