Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: utility/cgpt/cgpt_repair.c

Issue 2719008: Nearly complete rewrite of cgpt tool. (Closed) Base URL: ssh://git@chromiumos-git//vboot_reference.git
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « utility/cgpt/cgpt_options.c ('k') | utility/cgpt/cgpt_show.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « utility/cgpt/cgpt_options.c ('k') | utility/cgpt/cgpt_show.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698