OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 |
| 5 #include "cgpt.h" |
| 6 |
| 7 #include <getopt.h> |
| 8 #include <stdio.h> |
| 9 #include <stdlib.h> |
| 10 #include <string.h> |
| 11 |
| 12 #include "cgptlib_internal.h" |
| 13 |
| 14 static void Usage(void) |
| 15 { |
| 16 printf("\nUsage: %s repair [OPTIONS] DRIVE\n\n" |
| 17 "Repair damaged GPT headers and tables.\n\n" |
| 18 "Options:\n" |
| 19 " -v Verbose\n" |
| 20 "\n", progname); |
| 21 } |
| 22 |
| 23 int cmd_repair(int argc, char *argv[]) { |
| 24 struct drive drive; |
| 25 int verbose = 0; |
| 26 |
| 27 int c; |
| 28 int errorcnt = 0; |
| 29 |
| 30 opterr = 0; // quiet, you |
| 31 while ((c=getopt(argc, argv, ":hv")) != -1) |
| 32 { |
| 33 switch (c) |
| 34 { |
| 35 case 'v': |
| 36 verbose++; |
| 37 break; |
| 38 |
| 39 case 'h': |
| 40 Usage(); |
| 41 return CGPT_OK; |
| 42 case '?': |
| 43 Error("unrecognized option: -%c\n", optopt); |
| 44 errorcnt++; |
| 45 break; |
| 46 case ':': |
| 47 Error("missing argument to -%c\n", optopt); |
| 48 errorcnt++; |
| 49 break; |
| 50 default: |
| 51 errorcnt++; |
| 52 break; |
| 53 } |
| 54 } |
| 55 if (errorcnt) |
| 56 { |
| 57 Usage(); |
| 58 return CGPT_FAILED; |
| 59 } |
| 60 |
| 61 if (optind >= argc) { |
| 62 Error("missing drive argument\n"); |
| 63 return CGPT_FAILED; |
| 64 } |
| 65 |
| 66 if (CGPT_OK != DriveOpen(argv[optind], &drive)) |
| 67 return CGPT_FAILED; |
| 68 |
| 69 int gpt_retval = GptSanityCheck(&drive.gpt); |
| 70 if (verbose) |
| 71 printf("GptSanityCheck() returned %d: %s\n", |
| 72 gpt_retval, GptError(gpt_retval)); |
| 73 |
| 74 GptRepair(&drive.gpt); |
| 75 if (drive.gpt.modified & GPT_MODIFIED_HEADER1) |
| 76 printf("Primary Header is updated.\n"); |
| 77 if (drive.gpt.modified & GPT_MODIFIED_ENTRIES1) |
| 78 printf("Primary Entries is updated.\n"); |
| 79 if (drive.gpt.modified & GPT_MODIFIED_ENTRIES2) |
| 80 printf("Secondary Entries is updated.\n"); |
| 81 if (drive.gpt.modified & GPT_MODIFIED_HEADER2) |
| 82 printf("Secondary Header is updated.\n"); |
| 83 |
| 84 return DriveClose(&drive, 1); |
| 85 } |
OLD | NEW |