summaryrefslogtreecommitdiff
path: root/parted
diff options
context:
space:
mode:
authorArvin Schnell <aschnell@suse.com>2022-07-28 09:20:09 +0000
committerBrian C. Lane <bcl@redhat.com>2022-09-30 15:22:07 -0700
commitdaceb2d6a76a66254168effcc2cd0d5f4fadf946 (patch)
tree71cad18480aa44462782ec02302b007059a40368 /parted
parent8f37b28825933af9bbbac7f00cc7e23f916c7018 (diff)
downloadparted-daceb2d6a76a66254168effcc2cd0d5f4fadf946.tar.gz
parted: Add display of GPT UUIDs in JSON output
This adds 2 new disk type features, one for the whole disk UUID and another for the per-partition UUID. It adds ped_disk_get_uuid and ped_partition_get_uuid functions to retrieve them. It adds them to the JSON output on GPT disklabeled disks as "uuid" in the disk and partitions sections of the JSON output. Signed-off-by: Brian C. Lane <bcl@redhat.com>
Diffstat (limited to 'parted')
-rw-r--r--parted/parted.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/parted/parted.c b/parted/parted.c
index 36c39c7..84187b7 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1215,6 +1215,14 @@ _print_disk_info (const PedDevice *dev, const PedDisk *diskp)
ul_jsonwrt_value_u64 (&json, "physical-sector-size", dev->phys_sector_size);
ul_jsonwrt_value_s (&json, "label", pt_name);
if (diskp) {
+ bool has_disk_uuid = ped_disk_type_check_feature (diskp->type, PED_DISK_TYPE_DISK_UUID);
+ if (has_disk_uuid) {
+ uint8_t* uuid = ped_disk_get_uuid (diskp);
+ static char buf[UUID_STR_LEN];
+ uuid_unparse_lower (uuid, buf);
+ ul_jsonwrt_value_s (&json, "uuid", buf);
+ free (uuid);
+ }
ul_jsonwrt_value_u64 (&json, "max-partitions",
ped_disk_get_max_primary_partition_count(diskp));
disk_print_flags_json (diskp);
@@ -1360,6 +1368,8 @@ do_print (PedDevice** dev, PedDisk** diskp)
PED_DISK_TYPE_PARTITION_TYPE_ID);
bool has_type_uuid = ped_disk_type_check_feature ((*diskp)->type,
PED_DISK_TYPE_PARTITION_TYPE_UUID);
+ bool has_part_uuid = ped_disk_type_check_feature ((*diskp)->type,
+ PED_DISK_TYPE_PARTITION_UUID);
PedPartition* part;
if (opt_output_mode == HUMAN) {
@@ -1512,6 +1522,14 @@ do_print (PedDevice** dev, PedDisk** diskp)
free (type_uuid);
}
+ if (has_part_uuid) {
+ uint8_t* uuid = ped_partition_get_uuid (part);
+ static char buf[UUID_STR_LEN];
+ uuid_unparse_lower (uuid, buf);
+ ul_jsonwrt_value_s (&json, "uuid", buf);
+ free (uuid);
+ }
+
if (has_name) {
name = ped_partition_get_name (part);
if (strcmp (name, "") != 0)