Skip to contentSkip to conversation

libfdisk: Detect out-of-space when adding new primary partition

PATCH Applied Ian Wienand 2 participants 2 messages Oct 8, 2015 – Oct 9, 2015 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libfdisk: Detect out-of-space when adding new primary partition

I got a bit confused with the interaction below:

Command (m for help): p
Disk /dev/sda: 41 GiB, 43965677568 bytes, 85870464 sectors

    ...
  Device     Boot   Start      End  Sectors  Size Id Type
  /dev/sda1  *       2048  1026047  1024000  500M 83 Linux

/dev/sda2 1026048 85868543 84842496 40.5G 8e Linux LVM

Command (m for help): n
To create more partitions, first replace a primary with an extended partition.

I knew I should have had two primary partitions available, but I did not notice that the disk was seen as full (I was trying to grow it)

This change detects available primary partitions, and if so indicates we are out of space, rather than out of partitions.

---
 libfdisk/src/dos.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
libfdisk/src/dos.c +4 -1
index b337c0b..c04ee71 100644
@@ -1598,8 +1598,11 @@ static int dos_add_partition(struct fdisk_context *cxt,
 			}
 			rc = add_logical(cxt, pa, &res);
 		} else {
+			if (free_primary)
+				fdisk_info(cxt, _("All space for primary partitions is in use."));
+			else
 			/* TRANSLATORS: Try to keep this within 80 characters. */
-			fdisk_info(cxt, _("To create more partitions, first replace "
+				fdisk_info(cxt, _("To create more partitions, first replace "
 					  "a primary with an extended partition."));
 			return -EINVAL;
 		}
Signature · 1 line
2.4.3
maintainer Applied
#1 lore raw
Quoted 2 lines · Ian Wienand
 libfdisk/src/dos.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com