diff --git a/grub-core/commands/gptprio.c b/grub-core/commands/gptprio.c index 29bd11d68..ce5840b4e 100644 --- a/grub-core/commands/gptprio.c +++ b/grub-core/commands/gptprio.c @@ -141,20 +141,8 @@ grub_find_next (const char *disk_name, if (!*part_name) goto done; - *part_guid = - grub_xasprintf ("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - grub_le_to_cpu32 (part_found->guid.data1), - grub_le_to_cpu16 (part_found->guid.data2), - grub_le_to_cpu16 (part_found->guid.data3), - part_found->guid.data4[0], - part_found->guid.data4[1], - part_found->guid.data4[2], - part_found->guid.data4[3], - part_found->guid.data4[4], - part_found->guid.data4[5], - part_found->guid.data4[6], - part_found->guid.data4[7]); - if (!*part_name) + *part_guid = grub_gpt_guid_to_str (&part_found->guid); + if (!*part_guid) goto done; grub_errno = GRUB_ERR_NONE; diff --git a/grub-core/lib/gpt.c b/grub-core/lib/gpt.c index 198234071..9a1835b84 100644 --- a/grub-core/lib/gpt.c +++ b/grub-core/lib/gpt.c @@ -31,6 +31,19 @@ GRUB_MOD_LICENSE ("GPLv3+"); static grub_uint8_t grub_gpt_magic[] = GRUB_GPT_HEADER_MAGIC; +char * +grub_gpt_guid_to_str (grub_gpt_guid_t *guid) +{ + return grub_xasprintf ("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + grub_le_to_cpu32 (guid->data1), + grub_le_to_cpu16 (guid->data2), + grub_le_to_cpu16 (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]); +} + static grub_uint64_t grub_gpt_size_to_sectors (grub_gpt_t gpt, grub_size_t size) { diff --git a/include/grub/gpt_partition.h b/include/grub/gpt_partition.h index 50592d6d0..166fd4b55 100644 --- a/include/grub/gpt_partition.h +++ b/include/grub/gpt_partition.h @@ -33,6 +33,10 @@ struct grub_gpt_guid typedef struct grub_gpt_guid grub_gpt_guid_t; typedef struct grub_gpt_guid grub_gpt_part_type_t; +/* Format the raw little-endian GUID as a newly allocated string. */ +char * grub_gpt_guid_to_str (grub_gpt_guid_t *guid); + + #define GRUB_GPT_GUID_INIT(a, b, c, d1, d2, d3, d4, d5, d6, d7, d8) \ { \ grub_cpu_to_le32_compile_time (a), \