diff options
author | Karel Zak | 2016-11-30 12:43:10 +0100 |
---|---|---|
committer | Karel Zak | 2016-11-30 13:01:33 +0100 |
commit | 35ca51182782193f555fbdcb06bb10766550d017 (patch) | |
tree | e790c87db174462db010ed6c8ea32e7a7506df0f /disk-utils/fdisk-list.c | |
parent | sfdisk: cleanup --dump error messages (diff) | |
download | kernel-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/fdisk-list.c')
-rw-r--r-- | disk-utils/fdisk-list.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/disk-utils/fdisk-list.c b/disk-utils/fdisk-list.c index e6b2033e7..c9560f42b 100644 --- a/disk-utils/fdisk-list.c +++ b/disk-utils/fdisk-list.c @@ -34,10 +34,23 @@ static int is_ide_cdrom_or_tape(char *device) return ret; } +void list_disk_identifier(struct fdisk_context *cxt) +{ + struct fdisk_label *lb = fdisk_get_label(cxt, NULL); + char *id = NULL; + + if (fdisk_has_label(cxt)) + fdisk_info(cxt, _("Disklabel type: %s"), + fdisk_label_get_name(lb)); + + if (!fdisk_is_details(cxt) && fdisk_get_disklabel_id(cxt, &id) == 0 && id) { + fdisk_info(cxt, _("Disk identifier: %s"), id); + free(id); + } +} void list_disk_geometry(struct fdisk_context *cxt) { - char *id = NULL; struct fdisk_label *lb = fdisk_get_label(cxt, NULL); uint64_t bytes = fdisk_get_nsectors(cxt) * fdisk_get_sector_size(cxt); char *strsz = size_to_human_string(SIZE_SUFFIX_SPACE @@ -71,14 +84,8 @@ void list_disk_geometry(struct fdisk_context *cxt) if (fdisk_get_alignment_offset(cxt)) fdisk_info(cxt, _("Alignment offset: %lu bytes"), fdisk_get_alignment_offset(cxt)); - if (fdisk_has_label(cxt)) - fdisk_info(cxt, _("Disklabel type: %s"), - fdisk_label_get_name(lb)); - if (!fdisk_is_details(cxt) && fdisk_get_disklabel_id(cxt, &id) == 0 && id) { - fdisk_info(cxt, _("Disk identifier: %s"), id); - free(id); - } + list_disk_identifier(cxt); } void list_disklabel(struct fdisk_context *cxt) |