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