forked from bottlerocket-os/bottlerocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0010-gpt-split-out-checksum-recomputation.patch
89 lines (78 loc) · 3.1 KB
/
0010-gpt-split-out-checksum-recomputation.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
78
79
80
81
82
83
84
85
86
87
88
From f6e5e2723069e684b13bc90c7d252f49037e505e Mon Sep 17 00:00:00 2001
From: Michael Marineau <[email protected]>
Date: Sat, 15 Nov 2014 13:27:13 -0800
Subject: [PATCH] gpt: split out checksum recomputation
For basic data modifications the full repair function is overkill.
---
grub-core/lib/gpt.c | 30 ++++++++++++++++++++----------
include/grub/gpt_partition.h | 3 +++
2 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/grub-core/lib/gpt.c b/grub-core/lib/gpt.c
index 67ffdf7..1982340 100644
--- a/grub-core/lib/gpt.c
+++ b/grub-core/lib/gpt.c
@@ -293,7 +293,6 @@ grub_err_t
grub_gpt_repair (grub_disk_t disk, grub_gpt_t gpt)
{
grub_uint64_t backup_header, backup_entries;
- grub_uint32_t crc;
if (disk->log_sector_size != gpt->log_sector_size)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
@@ -331,13 +330,32 @@ grub_gpt_repair (grub_disk_t disk, grub_gpt_t gpt)
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;
+
+ /* Sanity check. */
+ if (grub_gpt_header_check (&gpt->primary, gpt->log_sector_size))
+ return grub_error (GRUB_ERR_BUG, "Generated invalid GPT primary header");
+
+ if (grub_gpt_header_check (&gpt->backup, gpt->log_sector_size))
+ return grub_error (GRUB_ERR_BUG, "Generated invalid GPT backup header");
+
+ gpt->status |= GRUB_GPT_BOTH_VALID;
+ return GRUB_ERR_NONE;
+}
+
+grub_err_t
+grub_gpt_update_checksums (grub_gpt_t gpt)
+{
+ grub_uint32_t crc;
+
/* Writing headers larger than our header structure are unsupported. */
gpt->primary.headersize =
grub_cpu_to_le32_compile_time (sizeof (gpt->primary));
gpt->backup.headersize =
grub_cpu_to_le32_compile_time (sizeof (gpt->backup));
- /* Recompute checksums. */
if (grub_gpt_lecrc32 (gpt->entries, gpt->entries_size, &crc))
return grub_errno;
@@ -350,14 +368,6 @@ grub_gpt_repair (grub_disk_t disk, grub_gpt_t gpt)
if (grub_gpt_header_lecrc32 (&gpt->backup, &gpt->backup.crc32))
return grub_errno;
- /* Sanity check. */
- if (grub_gpt_header_check (&gpt->primary, gpt->log_sector_size))
- return grub_error (GRUB_ERR_BUG, "Generated invalid GPT primary header");
-
- if (grub_gpt_header_check (&gpt->backup, gpt->log_sector_size))
- return grub_error (GRUB_ERR_BUG, "Generated invalid GPT backup header");
-
- gpt->status |= GRUB_GPT_BOTH_VALID;
return GRUB_ERR_NONE;
}
diff --git a/include/grub/gpt_partition.h b/include/grub/gpt_partition.h
index fc4f0f5..7fbdf4c 100644
--- a/include/grub/gpt_partition.h
+++ b/include/grub/gpt_partition.h
@@ -200,6 +200,9 @@ grub_gpt_t grub_gpt_read (grub_disk_t disk);
/* Sync up primary and backup headers, recompute checksums. */
grub_err_t grub_gpt_repair (grub_disk_t disk, grub_gpt_t gpt);
+/* Recompute checksums, must be called after modifying GPT data. */
+grub_err_t grub_gpt_update_checksums (grub_gpt_t gpt);
+
/* Write headers and entry tables back to disk. */
grub_err_t grub_gpt_write (grub_disk_t disk, grub_gpt_t gpt);
--
2.21.3