]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) fix logical partitions errors handling
authorKarel Zak <kzak@redhat.com>
Mon, 2 Feb 2015 11:20:44 +0000 (12:20 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 2 Feb 2015 11:20:44 +0000 (12:20 +0100)
The current code in add_partition() de-increment number of partitions
on error when logical partition requested and add_logical() does the
same. The result is mess in partitions array.

The another fixed issue is that add_logical() is called if all primary
partitions are already used although 'pa->start' (the template) is
explicitly defined outside the extended partition. The right behavior
is to end with error message.

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/dos.c

index 3a0a02bde1726f094003bdc6dd31ed39dbf7e1f5..8257d19d8734aa9e0bf766b5b8e8ecfbfc73942d 100644 (file)
@@ -1138,9 +1138,7 @@ static int add_partition(struct fdisk_context *cxt, size_t n,
        limit = get_unused_last(cxt, n, start, first, last);
 
        if (start > limit) {
-               fdisk_info(cxt, _("No free sectors available."));
-               if (n > 4)
-                       cxt->label->nparts_max--;
+               fdisk_warnx(cxt, _("No free sectors available."));
                return -ENOSPC;
        }
 
@@ -1569,10 +1567,17 @@ static int dos_add_partition(struct fdisk_context *cxt,
                DBG(LABEL, ul_debug("DOS: primary impossible, add logical"));
                if (l->ext_offset) {
                        if (!pa || fdisk_partition_has_start(pa)) {
+                               const char *msg;
                                if (!free_primary)
-                                       fdisk_info(cxt, _("All primary partitions are in use."));
+                                       msg = _("All primary partitions are in use.");
                                else if (!free_sectors)
-                                       fdisk_info(cxt, _("All space for primary partitions is in use."));
+                                       msg =  _("All space for primary partitions is in use.");
+
+                               if (pa && fdisk_partition_has_start(pa)) {
+                                       fdisk_warnx(cxt, msg);
+                                       return -EINVAL;
+                               } else
+                                       fdisk_info(cxt, msg);
                        }
                        rc = add_logical(cxt, pa, &res);
                } else {