From eed0e7b9bc01884140807bebe4720004d224652c Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 2 Feb 2015 12:20:44 +0100 Subject: [PATCH] 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 --- libfdisk/src/dos.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 3a0a02bde1..8257d19d87 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -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 { -- 2.47.2