Skip to content

Commit f99ba9a

Browse files
Wang XiaojunJaegeuk Kim
authored andcommitted
f2fs: fix wrong total_sections check and fsmeta check
Meta area is not included in section_count computation. So the minimum number of total_sections is 1 meanwhile it cannot be greater than segment_count_main. The minimum number of meta segments is 8 (SB + 2 (CP + SIT + NAT) + SSA). Signed-off-by: Wang Xiaojun <wangxiaojun11@huawei.com> Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent d89f589 commit f99ba9a

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎fs/f2fs/segment.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define DEF_MAX_RECLAIM_PREFREE_SEGMENTS 4096 /* 8GB in maximum */
1717

1818
#define F2FS_MIN_SEGMENTS 9 /* SB + 2 (CP + SIT + NAT) + SSA + MAIN */
19+
#define F2FS_MIN_META_SEGMENTS 8 /* SB + 2 (CP + SIT + NAT) + SSA */
1920

2021
/* L: Logical segment # in volume, R: Relative segment # in main area */
2122
#define GET_L2R_SEGNO(free_i, segno) ((segno) - (free_i)->start_segno)

‎fs/f2fs/super.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,7 +2741,7 @@ static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
27412741
static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
27422742
struct buffer_head *bh)
27432743
{
2744-
block_t segment_count, segs_per_sec, secs_per_zone;
2744+
block_t segment_count, segs_per_sec, secs_per_zone, segment_count_main;
27452745
block_t total_sections, blocks_per_seg;
27462746
struct f2fs_super_block *raw_super = (struct f2fs_super_block *)
27472747
(bh->b_data + F2FS_SUPER_OFFSET);
@@ -2812,6 +2812,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
28122812
}
28132813

28142814
segment_count = le32_to_cpu(raw_super->segment_count);
2815+
segment_count_main = le32_to_cpu(raw_super->segment_count_main);
28152816
segs_per_sec = le32_to_cpu(raw_super->segs_per_sec);
28162817
secs_per_zone = le32_to_cpu(raw_super->secs_per_zone);
28172818
total_sections = le32_to_cpu(raw_super->section_count);
@@ -2825,8 +2826,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
28252826
return -EFSCORRUPTED;
28262827
}
28272828

2828-
if (total_sections > segment_count ||
2829-
total_sections < F2FS_MIN_SEGMENTS ||
2829+
if (total_sections > segment_count_main || total_sections < 1 ||
28302830
segs_per_sec > segment_count || !segs_per_sec) {
28312831
f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)",
28322832
segment_count, total_sections, segs_per_sec);
@@ -2939,7 +2939,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
29392939
ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
29402940
reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
29412941

2942-
if (unlikely(fsmeta < F2FS_MIN_SEGMENTS ||
2942+
if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
29432943
ovp_segments == 0 || reserved_segments == 0)) {
29442944
f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
29452945
return 1;

0 commit comments

Comments
 (0)