Blob Blame History Raw
From 3275c1ac6d28c2257eb031277510bc9da99deedd Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Mon, 13 Apr 2015 12:08:50 +0200
Subject: [PATCH 3/5] sfdisk: improve -N warnings

Signed-off-by: Karel Zak <kzak@redhat.com>
---
 disk-utils/sfdisk.8 | 9 ++++++++-
 disk-utils/sfdisk.c | 9 +++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/disk-utils/sfdisk.8 b/disk-utils/sfdisk.8
index 66a8f99..0d63b6b 100644
--- a/disk-utils/sfdisk.8
+++ b/disk-utils/sfdisk.8
@@ -57,7 +57,14 @@ input format.  If standard input is a terminal, then \fBsfdisk\fR starts an
 interactive session.
 .sp
 If the option \fB\-N\fR is specified, then the changes are applied to
-the partition addressed by \fIpartition-number\fR.
+the partition addressed by \fIpartition-number\fR. The unspecified fields
+of the partition are not modified.
+.sp
+Note that it's possible to address unused partition by \fB\-N\fR. For example
+MBR always contains 4 partitions, but the number of the used partitions may be
+smaller.  In this case sfdisk follows the default values from the partition
+table and it does not use built-in defaults for the unused partition specified
+by \fB\-N\fR. See also \fB\---append\fR.
 .TP
 .BR \-a , " \-\-activate \fIdevice\fR [" \fIpartition-number\fR...]
 Switch on the bootable flag.  If no \fIpartition-number\fR is specified,
diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c
index 2e89d94..8846df8 100644
--- a/disk-utils/sfdisk.c
+++ b/disk-utils/sfdisk.c
@@ -1109,16 +1109,21 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
 	 */
 	if (partno >= 0) {
 		size_t n;
+
 		if (!fdisk_has_label(sf->cxt))
 			errx(EXIT_FAILURE, _("%s: cannot modify partition %d: "
 					     "no partition table was found"),
-					devname, partno);
+					devname, partno + 1);
 		n = fdisk_get_npartitions(sf->cxt);
 		if ((size_t) partno > n)
 			errx(EXIT_FAILURE, _("%s: cannot modify partition %d: "
 					     "partition table contains only %zu "
 					     "partitions"),
-					devname, partno, n);
+					devname, partno + 1, n);
+
+		if (!fdisk_is_partition_used(sf->cxt, partno))
+			fdisk_warnx(sf->cxt, _("warning: %s: partition %d is not defined yet"),
+					devname, partno + 1);
 		created = 1;
 		next_partno = partno;
 	}
-- 
2.1.0