forked from bottlerocket-os/bottlerocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0034-gpt-selectively-update-fields-during-repair.patch
78 lines (71 loc) · 2.92 KB
/
0034-gpt-selectively-update-fields-during-repair.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
71
72
73
74
75
76
77
From d1eb127676eb180eaf211d3a6cd9806a3e30c734 Mon Sep 17 00:00:00 2001
From: Michael Marineau <michael.marineau@coreos.com>
Date: Wed, 21 Sep 2016 14:33:48 -0700
Subject: [PATCH] gpt: selectively update fields during repair
Just a little cleanup/refactor to skip touching data we don't need to.
---
grub-core/lib/gpt.c | 28 ++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)
diff --git a/grub-core/lib/gpt.c b/grub-core/lib/gpt.c
index 35e65d8..03e807b 100644
--- a/grub-core/lib/gpt.c
+++ b/grub-core/lib/gpt.c
@@ -584,8 +584,6 @@ grub_gpt_get_partentry (grub_gpt_t gpt, grub_uint32_t n)
grub_err_t
grub_gpt_repair (grub_disk_t disk, grub_gpt_t gpt)
{
- grub_uint64_t backup_header, backup_entries;
-
/* Skip if there is nothing to do. */
if (grub_gpt_both_valid (gpt))
return GRUB_ERR_NONE;
@@ -598,6 +596,8 @@ grub_gpt_repair (grub_disk_t disk, grub_gpt_t gpt)
if (grub_gpt_primary_valid (gpt))
{
+ grub_uint64_t backup_header;
+
grub_dprintf ("gpt", "primary GPT is valid\n");
/* Relocate backup to end if disk if the disk has grown. */
@@ -608,32 +608,28 @@ grub_gpt_repair (grub_disk_t disk, grub_gpt_t gpt)
backup_header = disk->total_sectors - 1;
grub_dprintf ("gpt", "backup GPT header relocated to 0x%llx\n",
(unsigned long long) backup_header);
+
+ gpt->primary.alternate_lba = grub_cpu_to_le64 (backup_header);
}
grub_memcpy (&gpt->backup, &gpt->primary, sizeof (gpt->backup));
+ gpt->backup.header_lba = gpt->primary.alternate_lba;
+ gpt->backup.alternate_lba = gpt->primary.header_lba;
+ gpt->backup.partitions = grub_cpu_to_le64 (backup_header -
+ grub_gpt_size_to_sectors (gpt, gpt->entries_size));
}
else if (grub_gpt_backup_valid (gpt))
{
grub_dprintf ("gpt", "backup GPT is valid\n");
- backup_header = grub_le_to_cpu64 (gpt->backup.header_lba);
+
grub_memcpy (&gpt->primary, &gpt->backup, sizeof (gpt->primary));
+ gpt->primary.header_lba = gpt->backup.alternate_lba;
+ gpt->primary.alternate_lba = gpt->backup.header_lba;
+ gpt->primary.partitions = grub_cpu_to_le64_compile_time (2);
}
else
return grub_error (GRUB_ERR_BUG, "No valid GPT");
- backup_entries = backup_header -
- grub_gpt_size_to_sectors (gpt, gpt->entries_size);
- grub_dprintf ("gpt", "backup GPT entries will be located at 0x%llx\n",
- (unsigned long long) backup_entries);
-
- /* Update/fixup header and partition table locations. */
- gpt->primary.header_lba = grub_cpu_to_le64_compile_time (1);
- gpt->primary.alternate_lba = grub_cpu_to_le64 (backup_header);
- gpt->primary.partitions = grub_cpu_to_le64_compile_time (2);
- gpt->backup.header_lba = gpt->primary.alternate_lba;
- gpt->backup.alternate_lba = gpt->primary.header_lba;
- gpt->backup.partitions = grub_cpu_to_le64 (backup_entries);
-
/* Recompute checksums. */
if (grub_gpt_update_checksums (gpt))
return grub_errno;
--
2.21.3