Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 5 | #include <getopt.h> |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 6 | #include <string.h> |
| 7 | |
Bill Richardson | 0c3ba24 | 2013-03-29 11:09:30 -0700 | [diff] [blame] | 8 | #include "cgpt.h" |
| 9 | #include "vboot_host.h" |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 10 | |
Bill Richardson | 4cb5497 | 2014-06-20 14:33:00 -0700 | [diff] [blame] | 11 | extern const char* progname; |
| 12 | |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 13 | static 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 | |
| 22 | int cmd_repair(int argc, char *argv[]) { |
Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 23 | CgptRepairParams params; |
| 24 | memset(¶ms, 0, sizeof(params)); |
| 25 | |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 26 | 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 Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 35 | params.verbose++; |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 36 | 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 Srinivasan | 250549d | 2012-02-16 17:40:45 -0800 | [diff] [blame] | 60 | params.drive_name = argv[optind]; |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 61 | |
Bill Richardson | 3f806a2 | 2013-03-20 15:02:34 -0700 | [diff] [blame] | 62 | return CgptRepair(¶ms); |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 63 | } |