1 ext4: fix off-by-one fsmap error on 1k block filesystems
3 From: "Darrick J. Wong" <darrick.wong@oracle.com>
5 For 1k-block filesystems, the filesystem starts at block 1, not block 0.
6 This fact is recorded in s_first_data_block, so use that to bump up the
7 start_fsb before we start querying the filesystem for its space map.
8 Without this, ext4/026 fails on 1k block ext4 because various functions
9 (notably ext4_get_group_no_and_offset) don't know what to do with an
10 fsblock that is "before" the start of the filesystem and return garbage
11 results (blockgroup 2^32-1, etc.) that confuse fsmap.
13 Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
14 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
16 fs/ext4/fsmap.c | 4 ++++
17 1 file changed, 4 insertions(+)
19 diff --git a/fs/ext4/fsmap.c b/fs/ext4/fsmap.c
20 index b194360..7ec3408 100644
23 @@ -480,6 +480,7 @@ static int ext4_getfsmap_datadev(struct super_block *sb,
24 struct ext4_sb_info *sbi = EXT4_SB(sb);
25 ext4_fsblk_t start_fsb;
29 ext4_group_t start_ag;
31 @@ -487,9 +488,12 @@ static int ext4_getfsmap_datadev(struct super_block *sb,
32 ext4_grpblk_t last_cluster;
35 + bofs = le32_to_cpu(sbi->s_es->s_first_data_block);
36 eofs = ext4_blocks_count(sbi->s_es);
37 if (keys[0].fmr_physical >= eofs)
39 + else if (keys[0].fmr_physical < bofs)
40 + keys[0].fmr_physical = bofs;
41 if (keys[1].fmr_physical >= eofs)
42 keys[1].fmr_physical = eofs - 1;
43 start_fsb = keys[0].fmr_physical;