blob: b5f7d31e9efc6ead74e9d47194310567c32e273e [file] [log] [blame]
Jay Srinivasana0581432012-01-26 21:50:05 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Bill Richardsonf1372d92010-06-11 09:15:55 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Bill Richardsonf1372d92010-06-11 09:15:55 -07005#include <getopt.h>
Bill Richardsonf1372d92010-06-11 09:15:55 -07006#include <string.h>
7
Bill Richardson0c3ba242013-03-29 11:09:30 -07008#include "cgpt.h"
9#include "vboot_host.h"
Bill Richardsonf1372d92010-06-11 09:15:55 -070010
Bill Richardson4cb54972014-06-20 14:33:00 -070011extern const char* progname;
12
Bill Richardsonf1372d92010-06-11 09:15:55 -070013static void Usage(void)
14{
15 printf("\nUsage: %s repair [OPTIONS] DRIVE\n\n"
16 "Repair damaged GPT headers and tables.\n\n"
17 "Options:\n"
18 " -v Verbose\n"
19 "\n", progname);
20}
21
22int cmd_repair(int argc, char *argv[]) {
Jay Srinivasana0581432012-01-26 21:50:05 -080023 CgptRepairParams params;
24 memset(&params, 0, sizeof(params));
25
Bill Richardsonf1372d92010-06-11 09:15:55 -070026 int c;
27 int errorcnt = 0;
28
29 opterr = 0; // quiet, you
30 while ((c=getopt(argc, argv, ":hv")) != -1)
31 {
32 switch (c)
33 {
34 case 'v':
Jay Srinivasana0581432012-01-26 21:50:05 -080035 params.verbose++;
Bill Richardsonf1372d92010-06-11 09:15:55 -070036 break;
37
38 case 'h':
39 Usage();
40 return CGPT_OK;
41 case '?':
42 Error("unrecognized option: -%c\n", optopt);
43 errorcnt++;
44 break;
45 case ':':
46 Error("missing argument to -%c\n", optopt);
47 errorcnt++;
48 break;
49 default:
50 errorcnt++;
51 break;
52 }
53 }
54 if (errorcnt)
55 {
56 Usage();
57 return CGPT_FAILED;
58 }
59
Jay Srinivasan250549d2012-02-16 17:40:45 -080060 params.drive_name = argv[optind];
Bill Richardsonf1372d92010-06-11 09:15:55 -070061
Bill Richardson3f806a22013-03-20 15:02:34 -070062 return CgptRepair(&params);
Bill Richardsonf1372d92010-06-11 09:15:55 -070063}