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 * Repair headers and tables. |
| 6 * |
| 7 * If primary header or table is invalid, it copies from secondary (vice versa). |
| 8 */ |
| 9 #include <getopt.h> |
| 10 #include <stdio.h> |
| 11 #include <stdlib.h> |
| 12 #include "cgpt.h" |
| 13 #include "cgptlib_internal.h" |
| 14 #include "utility.h" |
| 15 |
| 16 /* Integers to store parsed argument. */ |
| 17 static int help; |
| 18 |
| 19 /* The structure for getopt_long(). When you add/delete any line, please refine |
| 20 * attribute_comments[] and third parameter of getopt_long() too. */ |
| 21 static struct option repair_options[] = { |
| 22 {.name = "help", .has_arg = no_argument, .flag = 0, .val = 'h'}, |
| 23 }; |
| 24 |
| 25 /* Extra information than struct option, please update this structure if you |
| 26 * add/remove any line in attribute_options[]. */ |
| 27 static struct option_details repair_options_details[] = { |
| 28 /* help */ |
| 29 { .comment = "print this help", |
| 30 .validator = AssignTrue, |
| 31 .valid_range = 0, |
| 32 .parsed = &help}, |
| 33 }; |
| 34 |
| 35 void RepairHelp() { |
| 36 printf("\nUsage: %s repair [OPTIONS] device_name\n\n", progname); |
| 37 ShowOptions(repair_options, repair_options_details, |
| 38 ARRAY_COUNT(repair_options)); |
| 39 printf("\n"); |
| 40 } |
| 41 |
| 42 /* Parses all options (and validates them), then opens the drive and sets |
| 43 * corresponding bits in GPT entry. */ |
| 44 int CgptRepair(int argc, char *argv[]) { |
| 45 struct drive drive; |
| 46 |
| 47 /* I know this is NOT the perfect place to put code to make options[] and |
| 48 * details[] are synced. But this is the best place we have right now since C |
| 49 * preprocessor doesn't know sizeof() for #if directive. */ |
| 50 assert(ARRAY_COUNT(repair_options) == |
| 51 ARRAY_COUNT(repair_options_details)); |
| 52 |
| 53 help = NOT_INITED; |
| 54 |
| 55 if (CGPT_OK != HandleOptions(argc, argv, |
| 56 "hr", |
| 57 ARRAY_COUNT(repair_options), |
| 58 repair_options, |
| 59 repair_options_details)) |
| 60 return CGPT_FAILED; |
| 61 if (help != NOT_INITED) { |
| 62 RepairHelp(); |
| 63 return CGPT_FAILED; |
| 64 } |
| 65 |
| 66 if (CGPT_OK != OpenDriveInLastArgument(argc, argv, &drive)) |
| 67 return CGPT_FAILED; |
| 68 |
| 69 DriveClose(&drive); |
| 70 |
| 71 return CGPT_OK; |
| 72 } |
OLD | NEW |