]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) be more robust about max number of partitions
authorKarel Zak <kzak@redhat.com>
Mon, 18 May 2020 12:13:33 +0000 (14:13 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 18 May 2020 12:13:33 +0000 (14:13 +0200)
It seems the previous MAXIMUM_PARTS bug fix has not been generic
enough. Let's use the check for all dos_add_partition().

This patch also remove libfdisk attempt to be smart and search for
unused primary partition. If you need more than 60 partition in MBR
than you have a different problem that cannot be solved by libfdisk
...

References: http://github.com/karelzak/util-linux/commit/b80fb30a5b79ce2cc8c7486e1435ec061aa79e2f
Addresses: https://github.com/karelzak/util-linux/issues/1022
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/dos.c

index 6268d2f3afec68c6bc7cfa79343f92ff6f37511f..b30835897b149d1e0078d83562f3c2641a8cc5ce 100644 (file)
@@ -1658,6 +1658,13 @@ static int dos_add_partition(struct fdisk_context *cxt,
        DBG(LABEL, ul_debug("DOS: new partition wanted"));
 
        l = self_label(cxt);
+
+       if (cxt->label->nparts_max >= MAXIMUM_PARTS) {
+               fdisk_warnx(cxt, _("The maximum number of partitions has "
+                                 "been created."));
+               return -EINVAL;
+       }
+
        ext_pe = l->ext_offset ? self_pte(cxt, l->ext_index) : NULL;
 
        /*
@@ -1759,11 +1766,6 @@ static int dos_add_partition(struct fdisk_context *cxt,
        if (last + grain < cxt->total_sectors - 1)
                free_sectors = 1;
 
-       if (cxt->label->nparts_max >= MAXIMUM_PARTS) {
-               fdisk_warnx(cxt, _("The maximum number of partitions has "
-                                 "been created."));
-               return -EINVAL;
-       }
 
        if (!free_primary || !free_sectors) {
                DBG(LABEL, ul_debug("DOS: primary impossible, add logical"));
@@ -1793,12 +1795,6 @@ static int dos_add_partition(struct fdisk_context *cxt,
                                          "a primary with an extended partition."));
                        return -EINVAL;
                }
-       } else if (cxt->label->nparts_max >= MAXIMUM_PARTS) {
-               fdisk_info(cxt, _("All logical partitions are in use. "
-                                 "Adding a primary partition."));
-               rc = get_partition_unused_primary(cxt, pa, &res);
-               if (rc == 0)
-                       rc = add_partition(cxt, res, pa);
        } else {
                char hint[BUFSIZ];
                struct fdisk_ask *ask;