diff options
author | Karel Zak | 2015-02-02 12:20:44 +0100 |
---|---|---|
committer | Karel Zak | 2015-02-02 12:20:44 +0100 |
commit | eed0e7b9bc01884140807bebe4720004d224652c (patch) | |
tree | bae8a8ab6969780f398490cb6870cb4a38b4ec0a /libfdisk/src/dos.c | |
parent | textual: grammarize and harmonize the stat error message (diff) | |
download | kernel-qcow2-util-linux-eed0e7b9bc01884140807bebe4720004d224652c.tar.gz kernel-qcow2-util-linux-eed0e7b9bc01884140807bebe4720004d224652c.tar.xz kernel-qcow2-util-linux-eed0e7b9bc01884140807bebe4720004d224652c.zip |
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>
Diffstat (limited to 'libfdisk/src/dos.c')
-rw-r--r-- | libfdisk/src/dos.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 3a0a02bde..8257d19d8 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 { |