[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 5/7] partmap/gpt: add print function for guids
From: |
Oliver Steffen |
Subject: |
[PATCH v2 5/7] partmap/gpt: add print function for guids |
Date: |
Mon, 20 Feb 2023 19:56:28 +0100 |
Code to print gpt patition guids has been duplicated in multiple places.
Add a common function for that.
Signed-off-by: Oliver Steffen <osteffen@redhat.com>
---
grub-core/partmap/gpt.c | 13 +++++++++++++
include/grub/gpt_partition.h | 6 ++++++
2 files changed, 19 insertions(+)
diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c
index 075cc96f1..e0da7e885 100644
--- a/grub-core/partmap/gpt.c
+++ b/grub-core/partmap/gpt.c
@@ -227,6 +227,19 @@ static struct grub_partition_map grub_gpt_partition_map =
#endif
};
+int
+grub_gpt_part_guid_snprint (char *str, grub_size_t n, const
grub_gpt_part_guid_t *guid)
+{
+ return grub_snprintf (str, n,
+ GRUB_PRIxGPT_GUID,
+ 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]);
+}
+
GRUB_MOD_INIT(part_gpt)
{
grub_partition_map_register (&grub_gpt_partition_map);
diff --git a/include/grub/gpt_partition.h b/include/grub/gpt_partition.h
index 7a93f4329..9b1660322 100644
--- a/include/grub/gpt_partition.h
+++ b/include/grub/gpt_partition.h
@@ -50,6 +50,9 @@ typedef struct grub_gpt_part_guid grub_gpt_part_guid_t;
{ 0x85, 0xD2, 0xE1, 0xE9, 0x04, 0x34, 0xCF, 0xB3 } \
}
+#define GRUB_PRIxGPT_GUID "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"
+#define GRUB_GPT_GUID_STR_LEN 36
+
struct grub_gpt_header
{
grub_uint8_t magic[8];
@@ -83,5 +86,8 @@ grub_gpt_partition_map_iterate (grub_disk_t disk,
grub_partition_iterate_hook_t hook,
void *hook_data);
+int
+grub_gpt_part_guid_snprint (char *str, grub_size_t n,
+ const grub_gpt_part_guid_t *guid);
#endif /* ! GRUB_GPT_PARTITION_HEADER */
--
2.39.2
- [PATCH v2 1/7] efi: add grub_efi_set_variable_with_attributes, (continued)
- [PATCH v2 1/7] efi: add grub_efi_set_variable_with_attributes, Oliver Steffen, 2023/02/20
- [PATCH v2 4/7] util/grub.d: activate bli module on EFI, Oliver Steffen, 2023/02/20
- [PATCH v2 2/7] efi: check for integer overflow in string conversion, Oliver Steffen, 2023/02/20
- [PATCH v2 7/7] commands/bli: use grub_gpt_part_guid_snprint, Oliver Steffen, 2023/02/20
- [PATCH v2 6/7] commands/probe: use grub_gpt_part_guid_snprint, Oliver Steffen, 2023/02/20
- [PATCH v2 5/7] partmap/gpt: add print function for guids,
Oliver Steffen <=