Skip to content

Commit 5a28184

Browse files
Jaegeuk Kimpundiramit
authored andcommitted
f2fs: detect wrong layout
commit 2040fce83fe17763b07c97c1f691da2bb85e4135 upstream. Previous mkfs.f2fs allows small partition inappropriately, so f2fs should detect that as well. Refer this in f2fs-tools. mkfs.f2fs: detect small partition by overprovision ratio and # of segments Reported-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 323d6b4 commit 5a28184

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

fs/f2fs/segment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#define DEF_RECLAIM_PREFREE_SEGMENTS 5 /* 5% over total segments */
1919
#define DEF_MAX_RECLAIM_PREFREE_SEGMENTS 4096 /* 8GB in maximum */
2020

21+
#define F2FS_MIN_SEGMENTS 9 /* SB + 2 (CP + SIT + NAT) + SSA + MAIN */
22+
2123
/* L: Logical segment # in volume, R: Relative segment # in main area */
2224
#define GET_L2R_SEGNO(free_i, segno) (segno - free_i->start_segno)
2325
#define GET_R2L_SEGNO(free_i, segno) (segno + free_i->start_segno)

fs/f2fs/super.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,7 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi)
14531453
unsigned int total, fsmeta;
14541454
struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
14551455
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1456+
unsigned int ovp_segments, reserved_segments;
14561457

14571458
total = le32_to_cpu(raw_super->segment_count);
14581459
fsmeta = le32_to_cpu(raw_super->segment_count_ckpt);
@@ -1464,6 +1465,16 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi)
14641465
if (unlikely(fsmeta >= total))
14651466
return 1;
14661467

1468+
ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
1469+
reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
1470+
1471+
if (unlikely(fsmeta < F2FS_MIN_SEGMENTS ||
1472+
ovp_segments == 0 || reserved_segments == 0)) {
1473+
f2fs_msg(sbi->sb, KERN_ERR,
1474+
"Wrong layout: check mkfs.f2fs version");
1475+
return 1;
1476+
}
1477+
14671478
if (unlikely(f2fs_cp_error(sbi))) {
14681479
f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck");
14691480
return 1;

0 commit comments

Comments
 (0)