Skip to content

Commit 9f701f6

Browse files
qiuyangsJaegeuk Kim
authored andcommitted
f2fs: check total_segments from devices in raw_super
For multi-device F2FS, we should check if the sum of total_segments from all devices matches segment_count. Signed-off-by: Qiuyang Sun <sunqiuyang@huawei.com> Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 46d9ce1 commit 9f701f6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

fs/f2fs/super.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,21 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
26042604
return -EFSCORRUPTED;
26052605
}
26062606

2607+
if (RDEV(0).path[0]) {
2608+
block_t dev_seg_count = le32_to_cpu(RDEV(0).total_segments);
2609+
int i = 1;
2610+
2611+
while (i < MAX_DEVICES && RDEV(i).path[0]) {
2612+
dev_seg_count += le32_to_cpu(RDEV(i).total_segments);
2613+
i++;
2614+
}
2615+
if (segment_count != dev_seg_count) {
2616+
f2fs_info(sbi, "Segment count (%u) mismatch with total segments from devices (%u)",
2617+
segment_count, dev_seg_count);
2618+
return -EFSCORRUPTED;
2619+
}
2620+
}
2621+
26072622
if (secs_per_zone > total_sections || !secs_per_zone) {
26082623
f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)",
26092624
secs_per_zone, total_sections);

0 commit comments

Comments
 (0)