From: Karel Zak Date: Thu, 16 Apr 2015 15:40:28 +0000 (+0200) Subject: sfdisk: accept empty partitions from dump X-Git-Tag: v2.26.2~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74b5101edf6286417625dd0764e65522c6e57623;p=thirdparty%2Futil-linux.git sfdisk: accept empty partitions from dump Old sfdisk uses: dev/sdc2 : start= 0, size= 0, Id= 0 for undefined MBR partitions. Let's follow this behaviour. Reported-by: Ruediger Meier Signed-off-by: Karel Zak --- diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 874afab49b..35c371d6ab 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -1072,6 +1072,22 @@ static int is_device_used(struct sfdisk *sf) return 0; } +static int ignore_partition(struct fdisk_partition *pa) +{ + /* incomplete partition setting */ + if (!fdisk_partition_has_start(pa) && !fdisk_partition_start_is_default(pa)) + return 1; + if (!fdisk_partition_has_size(pa) && !fdisk_partition_end_is_default(pa)) + return 1; + + /* probably dump from old sfdisk with start=0 size=0 */ + if (fdisk_partition_has_start(pa) && fdisk_partition_get_start(pa) == 0 && + fdisk_partition_has_size(pa) && fdisk_partition_get_size(pa) == 0) + return 1; + + return 0; +} + /* * sfdisk [[-N] ] * @@ -1237,9 +1253,9 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv) assert(pa); - if (!fdisk_partition_has_start(pa) && - !fdisk_partition_start_is_default(pa)) { - fdisk_info(sf->cxt, _("Ignoring partition %zu."), next_partno + 1); + if (ignore_partition(pa)) { + fdisk_info(sf->cxt, _("Ignoring partition.")); + next_partno++; continue; } if (!created) { /* create a new disklabel */