From: Karel Zak Date: Thu, 27 Jan 2022 12:38:59 +0000 (+0100) Subject: libfdisk: don't use too small free segments by default X-Git-Tag: v2.38-rc1~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a64e99118d3378efec9b77bc44e07436bd8fd600;p=thirdparty%2Futil-linux.git libfdisk: don't use too small free segments by default Signed-off-by: Karel Zak --- diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index c937ab7b96..72370a19a7 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -2297,7 +2297,7 @@ static int gpt_verify_disklabel(struct fdisk_context *cxt) P_("A total of %ju free sectors is available in %u segment.", "A total of %ju free sectors is available in %u segments " "(the largest is %s).", nsegments), - free_sectors, nsegments, strsz); + free_sectors, nsegments, strsz ? : "0 B"); free(strsz); } else @@ -2428,6 +2428,14 @@ static int gpt_add_partition( dflt_f = find_first_in_largest(gpt); dflt_l = find_last_free(gpt, dflt_f); + /* don't offer too small free space by default, this is possible to + * bypass by sfdisk script */ + if ((!pa || !fdisk_partition_has_start(pa)) + && dflt_l - dflt_f + 1 < cxt->grain / cxt->sector_size) { + fdisk_warnx(cxt, _("No enough free sectors available.")); + return -ENOSPC; + } + /* align the default in range */ dflt_f = fdisk_align_lba_in_range(cxt, dflt_f, dflt_f, dflt_l);