From daceb2d6a76a66254168effcc2cd0d5f4fadf946 Mon Sep 17 00:00:00 2001 From: Arvin Schnell Date: Thu, 28 Jul 2022 09:20:09 +0000 Subject: 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 --- parted/parted.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'parted/parted.c') 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) -- cgit v1.2.1