[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 01/16] partmap/gpt: Add grub_gpt_partition_get_uuid()
From: |
Vitaly Kuzmichev |
Subject: |
[PATCH v5 01/16] partmap/gpt: Add grub_gpt_partition_get_uuid() |
Date: |
Tue, 22 Aug 2023 23:39:09 +0200 |
This patch adds a function to provide partition PARTUUID on GPT
formatted disks by extracting 16 bytes GUID from corresponding GPT
entry and formatting it similarly to 'blkid' output.
Signed-off-by: Vitaly Kuzmichev <vitaly.kuzmichev@rtsoft.de>
---
grub-core/partmap/gpt.c | 36 ++++++++++++++++++++++++++++++++++++
include/grub/gpt_partition.h | 2 ++
2 files changed, 38 insertions(+)
diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c
index 877ceefc3..b43f46987 100644
--- a/grub-core/partmap/gpt.c
+++ b/grub-core/partmap/gpt.c
@@ -22,6 +22,7 @@
#include <grub/mm.h>
#include <grub/partition.h>
#include <grub/dl.h>
+#include <grub/charset.h>
#include <grub/msdos_partition.h>
#include <grub/gpt_partition.h>
#include <grub/i18n.h>
@@ -49,6 +50,41 @@ static struct grub_partition_map grub_gpt_partition_map;
+char *
+grub_gpt_partition_get_uuid (grub_device_t dev)
+{
+ struct grub_gpt_partentry gptdata;
+ grub_disk_t disk;
+ grub_partition_t pt;
+ grub_guid_t *guid;
+ char *part_uuid = NULL;
+
+ if (dev && dev->disk && dev->disk->partition &&
dev->disk->partition->partmap)
+ {
+ pt = dev->disk->partition;
+ if (grub_strcmp (pt->partmap->name, "gpt") == 0)
+ {
+ disk = grub_disk_open (dev->disk->name);
+ if (disk && grub_disk_read (disk, pt->offset, pt->index,
+ sizeof (gptdata), &gptdata) == 0)
+ {
+ guid = &gptdata.guid;
+ guid->data1 = grub_le_to_cpu32 (guid->data1);
+ guid->data2 = grub_le_to_cpu16 (guid->data2);
+ guid->data3 = grub_le_to_cpu16 (guid->data3);
+ part_uuid = grub_xasprintf ("%pG", guid);
+ }
+ if (!part_uuid)
+ grub_error_push ();
+ grub_disk_close (disk);
+ if (!part_uuid)
+ grub_error_pop ();
+ }
+ }
+
+ return part_uuid;
+}
+
grub_err_t
grub_gpt_partition_map_iterate (grub_disk_t disk,
grub_partition_iterate_hook_t hook,
diff --git a/include/grub/gpt_partition.h b/include/grub/gpt_partition.h
index 020e71920..e52834ac2 100644
--- a/include/grub/gpt_partition.h
+++ b/include/grub/gpt_partition.h
@@ -74,5 +74,7 @@ grub_gpt_partition_map_iterate (grub_disk_t disk,
grub_partition_iterate_hook_t hook,
void *hook_data);
+char *
+grub_gpt_partition_get_uuid (grub_device_t dev);
#endif /* ! GRUB_GPT_PARTITION_HEADER */
--
2.34.1
- [PATCH v5 00/16] Support searching by PARTUUID and PARTLABEL, Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 03/16] commands/probe: Simplify 'probe --part-uuid' command, Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 11/16] commands/probe: Add command option to display partition PARTLABEL, Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 12/16] docs/grub.texi: Update documentation for 'probe' and 'search' commands, Vitaly Kuzmichev, 2023/08/22
- [PATCH v5 04/16] include/grub/misc.h: Fix edge case in grub_uuidcasecmp(), Vitaly Kuzmichev, 2023/08/22