]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: don't use too small free segments by default
authorKarel Zak <kzak@redhat.com>
Thu, 27 Jan 2022 12:38:59 +0000 (13:38 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 27 Jan 2022 12:38:59 +0000 (13:38 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/gpt.c

index c937ab7b96570c219c29f25a250edb81d1494503..72370a19a7b8093bf654724000d59bda3f5efb11 100644 (file)
@@ -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,dflt_l>*/
        dflt_f = fdisk_align_lba_in_range(cxt, dflt_f, dflt_f, dflt_l);