| 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 { /* last element, which should be zero. */ } | |
| 24 }; | |
| 25 | |
| 26 /* Extra information than struct option, please update this structure if you | |
| 27 * add/remove any line in attribute_options[]. */ | |
| 28 static struct option_details repair_options_details[] = { | |
| 29 /* help */ | |
| 30 { .comment = "print this help", | |
| 31 .validator = AssignTrue, | |
| 32 .valid_range = 0, | |
| 33 .parsed = &help}, | |
| 34 { /* last element, which should be zero. */ } | |
| 35 }; | |
| 36 | |
| 37 void RepairHelp() { | |
| 38 printf("\nUsage: %s repair [OPTIONS] device_name\n\n", progname); | |
| 39 ShowOptions(repair_options, repair_options_details, | |
| 40 ARRAY_COUNT(repair_options)); | |
| 41 printf("\n"); | |
| 42 } | |
| 43 | |
| 44 /* Parses all options (and validates them), then opens the drive and sets | |
| 45 * corresponding bits in GPT entry. */ | |
| 46 int CgptRepair(int argc, char *argv[]) { | |
| 47 struct drive drive; | |
| 48 | |
| 49 /* I know this is NOT the perfect place to put code to make options[] and | |
| 50 * details[] are synced. But this is the best place we have right now since C | |
| 51 * preprocessor doesn't know sizeof() for #if directive. */ | |
| 52 assert(ARRAY_COUNT(repair_options) == | |
| 53 ARRAY_COUNT(repair_options_details)); | |
| 54 | |
| 55 help = NOT_INITED; | |
| 56 | |
| 57 if (CGPT_OK != HandleOptions(argc, argv, | |
| 58 "hr", | |
| 59 ARRAY_COUNT(repair_options), | |
| 60 repair_options, | |
| 61 repair_options_details)) | |
| 62 return CGPT_FAILED; | |
| 63 if (help != NOT_INITED) { | |
| 64 RepairHelp(); | |
| 65 return CGPT_FAILED; | |
| 66 } | |
| 67 | |
| 68 if (CGPT_OK != OpenDriveInLastArgument(argc, argv, &drive)) | |
| 69 return CGPT_FAILED; | |
| 70 | |
| 71 GptRepair(&drive.gpt); | |
| 72 if (drive.gpt.modified & GPT_MODIFIED_HEADER1) | |
| 73 printf("* Pri Header is updated.\n"); | |
| 74 if (drive.gpt.modified & GPT_MODIFIED_ENTRIES1) | |
| 75 printf("* Pri Table Entries is updated.\n"); | |
| 76 if (drive.gpt.modified & GPT_MODIFIED_ENTRIES2) | |
| 77 printf("* Sec Table Entries is updated.\n"); | |
| 78 if (drive.gpt.modified & GPT_MODIFIED_HEADER2) | |
| 79 printf("* Sec Header is updated.\n"); | |
| 80 | |
| 81 DriveClose(&drive); | |
| 82 | |
| 83 return CGPT_OK; | |
| 84 } | |
| OLD | NEW |