mkfs.f2fs: detect small partition by overprovision ratio and # of segments
We should avoid zero overprovision ratio or # of segments caused by too small
device.
Reported-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 6233452..bcb68b8 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -416,6 +416,8 @@
NO_CHECK_TYPE
};
+#define F2FS_MIN_SEGMENTS 9 /* SB + 2 (CP + SIT + NAT) + SSA + MAIN */
+
/*
* Copied from fs/f2fs/segment.h
*/
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 5e083a7..3c13026 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -341,12 +341,11 @@
(2 * (100 / c.overprovision + 1) + 6)
* c.segs_per_sec;
- if ((get_sb(segment_count_main) - 2) <
- c.reserved_segments) {
- MSG(1, "\tError: Device size is not sufficient for F2FS volume, "
- "more segment needed =%u",
- c.reserved_segments -
- (get_sb(segment_count_main) - 2));
+ if (c.overprovision == 0 || c.total_segments < F2FS_MIN_SEGMENTS ||
+ (c.devices[0].total_sectors *
+ c.sector_size < zone_align_start_offset) ||
+ (get_sb(segment_count_main) - 2) < c.reserved_segments) {
+ MSG(0, "\tError: Device size is not sufficient for F2FS volume\n");
return -1;
}