]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - libfdisk/src/dos.c
libfdisk: (dos) be more robust about max number of partitions
[thirdparty/util-linux.git] / 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;