summaryrefslogtreecommitdiffstats
path: root/disk-utils/sfdisk.c
diff options
context:
space:
mode:
authorKarel Zak2016-11-30 12:43:10 +0100
committerKarel Zak2016-11-30 13:01:33 +0100
commit35ca51182782193f555fbdcb06bb10766550d017 (patch)
treee790c87db174462db010ed6c8ea32e7a7506df0f /disk-utils/sfdisk.c
parentsfdisk: cleanup --dump error messages (diff)
downloadkernel-qcow2-util-linux-35ca51182782193f555fbdcb06bb10766550d017.tar.gz
kernel-qcow2-util-linux-35ca51182782193f555fbdcb06bb10766550d017.tar.xz
kernel-qcow2-util-linux-35ca51182782193f555fbdcb06bb10766550d017.zip
sfdisk: support empty label use-case
By default sfdisk creates partition table when a first partition is specified, otherwise the device is not modified. This force users to create at least one partition. This commit allows to create empty label without partitions if "label: <name>" header line is specified by script. The commit also modifies "New situation:" output to list label name and label identifier. Addresses: https://github.com/karelzak/util-linux/issues/374 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/sfdisk.c')
-rw-r--r--disk-utils/sfdisk.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c
index 10307ad14..2d6597434 100644
--- a/disk-utils/sfdisk.c
+++ b/disk-utils/sfdisk.c
@@ -1766,8 +1766,25 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
}
} while (1);
+ /* create empty disk label if label, but no partition specified */
+ if (rc == SFDISK_DONE_EOF && created == 0
+ && fdisk_script_has_force_label(dp) == 1
+ && fdisk_table_get_nents(tb) == 0
+ && fdisk_script_get_header(dp, "label")) {
+
+ int xrc = fdisk_apply_script_headers(sf->cxt, dp);
+ created = !xrc;
+ if (xrc) {
+ fdisk_warnx(sf->cxt, _(
+ "Failed to apply script headers, "
+ "disk label not created."));
+ rc = SFDISK_DONE_ABORT;
+ }
+ }
+
if (!sf->quiet && rc != SFDISK_DONE_ABORT) {
fdisk_info(sf->cxt, _("\nNew situation:"));
+ list_disk_identifier(sf->cxt);
list_disklabel(sf->cxt);
}