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

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