Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [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 | |
Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 5 | |
| 6 | #include <string.h> |
| 7 | |
Bill Richardson | 0c3ba24 | 2013-03-29 11:09:30 -0700 | [diff] [blame] | 8 | #include "cgpt.h" |
Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 9 | #include "cgptlib_internal.h" |
Bill Richardson | 0c3ba24 | 2013-03-29 11:09:30 -0700 | [diff] [blame] | 10 | #include "vboot_host.h" |
Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 11 | |
Bill Richardson | 3f806a2 | 2013-03-20 15:02:34 -0700 | [diff] [blame] | 12 | int CgptRepair(CgptRepairParams *params) { |
Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 13 | struct drive drive; |
| 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)) |
Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 20 | return CGPT_FAILED; |
| 21 | |
Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 22 | int gpt_retval = GptSanityCheck(&drive.gpt); |
| 23 | if (params->verbose) |
| 24 | printf("GptSanityCheck() returned %d: %s\n", |
| 25 | gpt_retval, GptError(gpt_retval)); |
| 26 | |
| 27 | GptRepair(&drive.gpt); |
| 28 | if (drive.gpt.modified & GPT_MODIFIED_HEADER1) |
| 29 | printf("Primary Header is updated.\n"); |
| 30 | if (drive.gpt.modified & GPT_MODIFIED_ENTRIES1) |
| 31 | printf("Primary Entries is updated.\n"); |
| 32 | if (drive.gpt.modified & GPT_MODIFIED_ENTRIES2) |
| 33 | printf("Secondary Entries is updated.\n"); |
| 34 | if (drive.gpt.modified & GPT_MODIFIED_HEADER2) |
| 35 | printf("Secondary Header is updated.\n"); |
| 36 | |
| 37 | return DriveClose(&drive, 1); |
| 38 | } |