blob: b7582123abfa73f5fae39c97a4067742c01a215d [file] [log] [blame]
Stefan Reinauerb7b865c2012-08-23 15:06:25 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Stefan Reinauerb7b865c2012-08-23 15:06:25 -07005#include <string.h>
6
Bill Richardson0c3ba242013-03-29 11:09:30 -07007#include "cgpt.h"
Stefan Reinauerb7b865c2012-08-23 15:06:25 -07008#include "cgptlib_internal.h"
Bill Richardson0c3ba242013-03-29 11:09:30 -07009#include "vboot_host.h"
Stefan Reinauerb7b865c2012-08-23 15:06:25 -070010
Bill Richardson3f806a22013-03-20 15:02:34 -070011int CgptLegacy(CgptLegacyParams *params) {
Stefan Reinauerb7b865c2012-08-23 15:06:25 -070012 struct drive drive;
13 GptHeader *h1, *h2;
14
15 if (params == NULL)
16 return CGPT_FAILED;
17
Nam T. Nguyenab899592014-11-13 19:30:46 -080018 if (CGPT_OK != DriveOpen(params->drive_name, &drive, O_RDWR,
19 params->drive_size))
Stefan Reinauerb7b865c2012-08-23 15:06:25 -070020 return CGPT_FAILED;
21
Stefan Reinauerb7b865c2012-08-23 15:06:25 -070022 h1 = (GptHeader *)drive.gpt.primary_header;
23 h2 = (GptHeader *)drive.gpt.secondary_header;
24 if (params->efipart) {
25 memcpy(h1->signature, GPT_HEADER_SIGNATURE, GPT_HEADER_SIGNATURE_SIZE);
26 memcpy(h2->signature, GPT_HEADER_SIGNATURE, GPT_HEADER_SIGNATURE_SIZE);
27 RepairEntries(&drive.gpt, MASK_SECONDARY);
28 drive.gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 |
29 GPT_MODIFIED_HEADER2);
30 } else {
31 memcpy(h1->signature, GPT_HEADER_SIGNATURE2, GPT_HEADER_SIGNATURE_SIZE);
32 memcpy(h2->signature, GPT_HEADER_SIGNATURE2, GPT_HEADER_SIGNATURE_SIZE);
33 memset(drive.gpt.primary_entries, 0, drive.gpt.sector_bytes);
34 drive.gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 |
35 GPT_MODIFIED_HEADER2);
36 }
37
38 UpdateCrc(&drive.gpt);
39
40 // Write it all out
41 return DriveClose(&drive, 1);
42}