Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 1 | // 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 Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 5 | #include <string.h> |
| 6 | |
Bill Richardson | 0c3ba24 | 2013-03-29 11:09:30 -0700 | [diff] [blame] | 7 | #include "cgpt.h" |
Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 8 | #include "cgptlib_internal.h" |
Bill Richardson | 0c3ba24 | 2013-03-29 11:09:30 -0700 | [diff] [blame] | 9 | #include "vboot_host.h" |
Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 10 | |
Bill Richardson | 3f806a2 | 2013-03-20 15:02:34 -0700 | [diff] [blame] | 11 | int CgptLegacy(CgptLegacyParams *params) { |
Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 12 | struct drive drive; |
| 13 | GptHeader *h1, *h2; |
| 14 | |
| 15 | if (params == NULL) |
| 16 | return CGPT_FAILED; |
| 17 | |
Nam T. Nguyen | ab89959 | 2014-11-13 19:30:46 -0800 | [diff] [blame] | 18 | if (CGPT_OK != DriveOpen(params->drive_name, &drive, O_RDWR, |
| 19 | params->drive_size)) |
Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 20 | return CGPT_FAILED; |
| 21 | |
Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 22 | 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 | } |