mkfs.f2fs: set segment_count in super block correctly
authorFan Li <fanofcode.li@samsung.com>
Wed, 16 Mar 2016 02:25:36 +0000 (10:25 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 16 Mar 2016 19:46:13 +0000 (12:46 -0700)
Now f2fs will check statistics recorded in super block in
sanity_check_area_boundary() during mount. If the number of segments
per zone is greater than 1, and the disk space isn't aligned with zone,
mount will fail due to following condition:

main_blkaddr + (segment_count_main << log_blocks_per_seg) !=
segment0_blkaddr + (segment_count << log_blocks_per_seg)

This is because when the length of main area isn't aligned with zone,
mkfs doesn't add those excess segments to segment_count_main, but adds
them to segment_count.

Here align segment_count with zone size as well as segment_count_main
to prevent such problem.

Signed-off-by: Fan Li <fanofcode.li@samsung.com>
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
mkfs/f2fs_format.c

index 4f38f03..960031e 100644 (file)
@@ -175,7 +175,8 @@ static int f2fs_prepare_super_block(void)
        }
 
        set_sb(segment_count, (config.total_sectors * config.sector_size -
-                               zone_align_start_offset) / segment_size_bytes);
+                               zone_align_start_offset) / segment_size_bytes /
+                               config.segs_per_zone * config.segs_per_zone);
 
        set_sb(segment0_blkaddr, zone_align_start_offset / blk_size_bytes);
        sb->cp_blkaddr = sb->segment0_blkaddr;