forked from bottlerocket-os/bottlerocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0027-gpt-add-helper-for-picking-a-valid-header.patch
71 lines (62 loc) · 2.02 KB
/
0027-gpt-add-helper-for-picking-a-valid-header.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
From 974f79ff5cfff8b37f6377d55c2e090f9c5c6251 Mon Sep 17 00:00:00 2001
From: Vito Caputo <vito.caputo@coreos.com>
Date: Thu, 25 Aug 2016 17:21:18 -0700
Subject: [PATCH] gpt: add helper for picking a valid header
Eliminate some repetition in primary vs. backup header acquisition.
---
grub-core/lib/gpt.c | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/grub-core/lib/gpt.c b/grub-core/lib/gpt.c
index f0c71bd..2550ed8 100644
--- a/grub-core/lib/gpt.c
+++ b/grub-core/lib/gpt.c
@@ -108,21 +108,32 @@ grub_gpt_part_uuid (grub_device_t device, char **uuid)
return GRUB_ERR_NONE;
}
+static struct grub_gpt_header *
+grub_gpt_get_header (grub_gpt_t gpt)
+{
+ if (gpt->status & GRUB_GPT_PRIMARY_HEADER_VALID)
+ return &gpt->primary;
+ else if (gpt->status & GRUB_GPT_BACKUP_HEADER_VALID)
+ return &gpt->backup;
+
+ grub_error (GRUB_ERR_BUG, "No valid GPT header");
+ return NULL;
+}
+
grub_err_t
grub_gpt_disk_uuid (grub_device_t device, char **uuid)
{
+ struct grub_gpt_header *header;
+
grub_gpt_t gpt = grub_gpt_read (device->disk);
if (!gpt)
goto done;
- grub_errno = GRUB_ERR_NONE;
+ header = grub_gpt_get_header (gpt);
+ if (!header)
+ goto done;
- if (gpt->status & GRUB_GPT_PRIMARY_HEADER_VALID)
- *uuid = grub_gpt_guid_to_str (&gpt->primary.guid);
- else if (gpt->status & GRUB_GPT_BACKUP_HEADER_VALID)
- *uuid = grub_gpt_guid_to_str (&gpt->backup.guid);
- else
- grub_errno = grub_error (GRUB_ERR_BUG, "No valid GPT header");
+ *uuid = grub_gpt_guid_to_str (&header->guid);
done:
grub_gpt_free (gpt);
@@ -559,11 +570,8 @@ grub_gpt_get_partentry (grub_gpt_t gpt, grub_uint32_t n)
struct grub_gpt_header *header;
grub_size_t offset;
- if (gpt->status & GRUB_GPT_PRIMARY_HEADER_VALID)
- header = &gpt->primary;
- else if (gpt->status & GRUB_GPT_BACKUP_HEADER_VALID)
- header = &gpt->backup;
- else
+ header = grub_gpt_get_header (gpt);
+ if (!header)
return NULL;
if (n >= grub_le_to_cpu32 (header->maxpart))
--
2.21.3