summaryrefslogtreecommitdiff
path: root/cgpt
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2016-04-20 13:05:53 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-04-25 15:15:32 -0700
commit8228f47dfd24448a4c959c93d064a0887c4762d1 (patch)
treeba1564a8e37c18bc1695133bb05e3e742fc0c1b7 /cgpt
parent39910d062dffcd16683e0626dac1e7064991c7e5 (diff)
downloadvboot-8228f47dfd24448a4c959c93d064a0887c4762d1.tar.gz
cgpt: Add cgpt legacy parameter to set primary GPT signature to IGNOREMEstabilize-8249.B
Now that we have support for the IGNOREME signature in cgpt, we need a way to set it on an existing disk. The easiest option is to shoehorn this into the cgpt legacy command, because that's already made to modify GPT header signatures (really, it would be nice to rename it to cgpt signature or something, but let's not break existing uses for now). BRANCH=None BUG=chrome-os-partner:52595 TEST=unit tests Change-Id: If2835fec28a9c39373abd050e2e057f73e5ec700 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/340073 Reviewed-by: Nam Nguyen <namnguyen@google.com>
Diffstat (limited to 'cgpt')
-rw-r--r--cgpt/cgpt_legacy.c21
-rw-r--r--cgpt/cmd_legacy.c17
2 files changed, 34 insertions, 4 deletions
diff --git a/cgpt/cgpt_legacy.c b/cgpt/cgpt_legacy.c
index b7582123..d5df34d5 100644
--- a/cgpt/cgpt_legacy.c
+++ b/cgpt/cgpt_legacy.c
@@ -10,6 +10,7 @@
int CgptLegacy(CgptLegacyParams *params) {
struct drive drive;
+ int gpt_retval;
GptHeader *h1, *h2;
if (params == NULL)
@@ -19,14 +20,32 @@ int CgptLegacy(CgptLegacyParams *params) {
params->drive_size))
return CGPT_FAILED;
+ if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) {
+ Error("GptSanityCheck() returned %d: %s\n",
+ gpt_retval, GptError(gpt_retval));
+ return CGPT_FAILED;
+ }
+
h1 = (GptHeader *)drive.gpt.primary_header;
h2 = (GptHeader *)drive.gpt.secondary_header;
- if (params->efipart) {
+ if (params->mode == CGPT_LEGACY_MODE_EFIPART) {
+ drive.gpt.ignored = MASK_NONE;
memcpy(h1->signature, GPT_HEADER_SIGNATURE, GPT_HEADER_SIGNATURE_SIZE);
memcpy(h2->signature, GPT_HEADER_SIGNATURE, GPT_HEADER_SIGNATURE_SIZE);
RepairEntries(&drive.gpt, MASK_SECONDARY);
drive.gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 |
GPT_MODIFIED_HEADER2);
+ } else if (params->mode == CGPT_LEGACY_MODE_IGNORE_PRIMARY) {
+ if (!(drive.gpt.valid_headers & MASK_SECONDARY) ||
+ !(drive.gpt.valid_entries & MASK_SECONDARY) ||
+ drive.gpt.ignored & MASK_SECONDARY) {
+ Error("Refusing to mark primary GPT ignored unless secondary is valid.");
+ return CGPT_FAILED;
+ }
+ memset(h1, 0, sizeof(*h1));
+ memcpy(h1->signature, GPT_HEADER_SIGNATURE_IGNORED,
+ GPT_HEADER_SIGNATURE_SIZE);
+ drive.gpt.modified |= GPT_MODIFIED_HEADER1;
} else {
memcpy(h1->signature, GPT_HEADER_SIGNATURE2, GPT_HEADER_SIGNATURE_SIZE);
memcpy(h2->signature, GPT_HEADER_SIGNATURE2, GPT_HEADER_SIGNATURE_SIZE);
diff --git a/cgpt/cmd_legacy.c b/cgpt/cmd_legacy.c
index 5fd742cc..e45b305c 100644
--- a/cgpt/cmd_legacy.c
+++ b/cgpt/cmd_legacy.c
@@ -19,6 +19,7 @@ static void Usage(void)
" default 0, meaning partitions and GPT structs are\n"
" both on DRIVE\n"
" -e Switch GPT header signature back to \"EFI PART\"\n"
+ " -p Switch primary GPT header signature to \"IGNOREME\"\n"
"\n", progname);
}
@@ -31,7 +32,7 @@ int cmd_legacy(int argc, char *argv[]) {
int errorcnt = 0;
opterr = 0; // quiet, you
- while ((c=getopt(argc, argv, ":heD:")) != -1)
+ while ((c=getopt(argc, argv, ":hepD:")) != -1)
{
switch (c)
{
@@ -44,9 +45,19 @@ int cmd_legacy(int argc, char *argv[]) {
}
break;
case 'e':
- params.efipart = 1;
+ if (params.mode) {
+ Error("Incompatible flags, pick either -e or -p\n");
+ errorcnt++;
+ }
+ params.mode = CGPT_LEGACY_MODE_EFIPART;
+ break;
+ case 'p':
+ if (params.mode) {
+ Error("Incompatible flags, pick either -e or -p\n");
+ errorcnt++;
+ }
+ params.mode = CGPT_LEGACY_MODE_IGNORE_PRIMARY;
break;
-
case 'h':
Usage();
return CGPT_OK;