libfdisk: (dos) fix logical partitions errors handling

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>
This commit is contained in:
Karel Zak 2015-02-02 12:20:44 +01:00
parent fc14ceba5e
commit eed0e7b9bc
1 changed files with 10 additions and 5 deletions

View 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 {