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

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