Files
OpenCellular/cgpt/cgpt_legacy.c
Stefan Reinauer b7b865cfee Support alternative GPT header signature
In order to dual boot Windows and ChromeOS, Windows must
not find a GPT partition table on the disk. So change
ChromeOS to cope with an alternative signature "CHROMEOS"
instead of the standard "EFI PART"

BUG=chrome-os-partner:6108
TEST=rebuild chromeos, install it,
     run cgpt legacy /dev/sda
     dd if=/dev/sda of=/tmp/x bs=1k
     hexdump -C /tmp/X
     see the string CHROMEOS
BRANCH=link
Signed-off-by: Stefan Reinauer <reinauer@chromium.org>

Change-Id: Ia88eff33b9880bd73a78c1b8e026c1f8298c4557
Reviewed-on: https://gerrit.chromium.org/gerrit/31264
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Ready: Stefan Reinauer <reinauer@chromium.org>
Tested-by: Stefan Reinauer <reinauer@chromium.org>
2012-09-19 15:33:30 -07:00

43 lines
1.3 KiB
C

// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cgpt.h"
#include <string.h>
#include "cgptlib_internal.h"
#include "cgpt_params.h"
int cgpt_legacy(CgptLegacyParams *params) {
struct drive drive;
GptHeader *h1, *h2;
if (params == NULL)
return CGPT_FAILED;
if (CGPT_OK != DriveOpen(params->drive_name, &drive, O_RDWR))
return CGPT_FAILED;
h1 = (GptHeader *)drive.gpt.primary_header;
h2 = (GptHeader *)drive.gpt.secondary_header;
if (params->efipart) {
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 {
memcpy(h1->signature, GPT_HEADER_SIGNATURE2, GPT_HEADER_SIGNATURE_SIZE);
memcpy(h2->signature, GPT_HEADER_SIGNATURE2, GPT_HEADER_SIGNATURE_SIZE);
memset(drive.gpt.primary_entries, 0, drive.gpt.sector_bytes);
drive.gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 |
GPT_MODIFIED_HEADER2);
}
UpdateCrc(&drive.gpt);
// Write it all out
return DriveClose(&drive, 1);
}