probe: Support probing for gpt partition uuid with -q
RFC PATCH 1/1 probe: Support probing for gpt partition uuid with -q
Signed-off-by Jacob Kroon <[email protected]>
--- grub-core/commands/probe.c | 13 +++++++++++++ grub-core/partmap/gpt.c | 7 +++++++ include/grub/partition.h | 3 +++ 3 files changed, 23 insertions(+)
grub-core/commands/probe.c +13 -0
@@ -45,6 +45,7 @@ static const struct grub_arg_option options[] = {"fs", 'f', 0, N_("Determine filesystem type."), 0, 0}, {"fs-uuid", 'u', 0, N_("Determine filesystem UUID."), 0, 0}, {"label", 'l', 0, N_("Determine filesystem label."), 0, 0}, + {"partuuid", 'q', 0, N_("Determine partition PARTUUID."), 0, 0}, {0, 0, 0, 0, 0, 0} };
@@ -154,6 +155,18 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args)grub_device_close (dev);return GRUB_ERR_NONE ; } +if (state[6 ].set) + { +const char *val ="none" ; +if (dev->disk && dev->disk->partition) + val = dev->disk->partition->partuuid; +if (state[0 ].set) +grub_env_set (state[0 ].arg, val); +else +grub_printf ("%s" , val); +grub_device_close (dev); +return GRUB_ERR_NONE ; + }grub_device_close (dev);return grub_error (GRUB_ERR_BAD_ARGUMENT ,"unrecognised target" ); }
grub-core/partmap/gpt.c +7 -0
@@ -108,6 +108,13 @@ grub_gpt_partition_map_iterate (grub_disk_t disk, part.index = last_offset; part.partmap = &grub_gpt_partition_map; part.parent = disk->partition; +grub_gpt_part_guid_t *guid = &entry.guid; +grub_snprintf (part.partuuid,sizeof (part.partuuid), +"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" , + guid->data1, guid->data2, guid->data3, guid->data4[0 ], + guid->data4[1 ], guid->data4[2 ], guid->data4[3 ], + guid->data4[4 ], guid->data4[5 ], guid->data4[6 ], + guid->data4[7 ]); grub_dprintf ("gpt", "GPT entry %d: start=%lld, length=%lld\n", i, (unsigned long long) part.start,
include/grub/partition.h +3 -0
@@ -78,6 +78,9 @@ struct grub_partition/* The index of this partition in the partition table. */ int index; +/* The partition uuid. */ +char partuuid[37 ]; +/* Parent partition (physically contains this partition). */ struct grub_partition *parent;
Signature · 1 line
2.20.1