forked from bottlerocket-os/bottlerocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0028-gptrepair-fix-status-checking.patch
64 lines (56 loc) · 2.21 KB
/
0028-gptrepair-fix-status-checking.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
From 1edd283385b1c07a0fd88e7db46d89490de0648d Mon Sep 17 00:00:00 2001
From: Michael Marineau <michael.marineau@coreos.com>
Date: Tue, 20 Sep 2016 13:06:05 -0700
Subject: [PATCH] gptrepair: fix status checking
None of these status bit checks were correct. Fix and simplify.
---
grub-core/commands/gptrepair.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/grub-core/commands/gptrepair.c b/grub-core/commands/gptrepair.c
index 38392fd8f..66ac3f7c7 100644
--- a/grub-core/commands/gptrepair.c
+++ b/grub-core/commands/gptrepair.c
@@ -46,8 +46,6 @@ grub_cmd_gptrepair (grub_command_t cmd __attribute__ ((unused)),
grub_device_t dev = NULL;
grub_gpt_t gpt = NULL;
char *dev_name;
- grub_uint32_t primary_crc, backup_crc;
- enum grub_gpt_status old_status;
if (argc != 1 || !grub_strlen(args[0]))
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
@@ -67,29 +65,25 @@ grub_cmd_gptrepair (grub_command_t cmd __attribute__ ((unused)),
if (!gpt)
goto done;
- primary_crc = gpt->primary.crc32;
- backup_crc = gpt->backup.crc32;
- old_status = gpt->status;
-
- if (grub_gpt_repair (dev->disk, gpt))
- goto done;
-
- if (primary_crc == gpt->primary.crc32 &&
- backup_crc == gpt->backup.crc32 &&
- old_status && gpt->status)
+ if ((gpt->status & GRUB_GPT_BOTH_VALID) == GRUB_GPT_BOTH_VALID)
{
grub_printf_ (N_("GPT already valid, %s unmodified.\n"), dev_name);
goto done;
}
- if (grub_gpt_write (dev->disk, gpt))
+ if ((gpt->status & GRUB_GPT_PRIMARY_VALID) != GRUB_GPT_PRIMARY_VALID)
+ grub_printf_ (N_("Found invalid primary GPT on %s\n"), dev_name);
+
+ if ((gpt->status & GRUB_GPT_BACKUP_VALID) != GRUB_GPT_BACKUP_VALID)
+ grub_printf_ (N_("Found invalid backup GPT on %s\n"), dev_name);
+
+ if (grub_gpt_repair (dev->disk, gpt))
goto done;
- if (!(old_status & GRUB_GPT_PRIMARY_VALID))
- grub_printf_ (N_("Primary GPT for %s repaired.\n"), dev_name);
+ if (grub_gpt_write (dev->disk, gpt))
+ goto done;
- if (!(old_status & GRUB_GPT_BACKUP_VALID))
- grub_printf_ (N_("Backup GPT for %s repaired.\n"), dev_name);
+ grub_printf_ (N_("Repaired GPT on %s\n"), dev_name);
done:
if (gpt)