blob: 1880ea5b2598b77b8bee8356af1a0e088b340c49 [file] [log] [blame]
Jay Srinivasana0581432012-01-26 21:50:05 -08001// 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 Srinivasana0581432012-01-26 21:50:05 -08005
6#include <string.h>
7
Bill Richardson0c3ba242013-03-29 11:09:30 -07008#include "cgpt.h"
Jay Srinivasana0581432012-01-26 21:50:05 -08009#include "cgptlib_internal.h"
Bill Richardson0c3ba242013-03-29 11:09:30 -070010#include "vboot_host.h"
Jay Srinivasana0581432012-01-26 21:50:05 -080011
Bill Richardson3f806a22013-03-20 15:02:34 -070012int CgptRepair(CgptRepairParams *params) {
Jay Srinivasana0581432012-01-26 21:50:05 -080013 struct drive drive;
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))
Jay Srinivasana0581432012-01-26 21:50:05 -080020 return CGPT_FAILED;
21
Jay Srinivasana0581432012-01-26 21:50:05 -080022 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}