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

Side by Side Diff: utility/cgpt/cgpt_dev.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_attribute.c ('k') | utility/cgpt/cgpt_options.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 * Developper mode.
6 */
7 #include <getopt.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "cgpt.h"
11 #include "cgptlib_internal.h"
12 #include "utility.h"
13
14 /* Integers to store parsed argument. */
15 static int help, primary_header, primary_entries,
16 secondary_header, secondary_entries;
17
18 /* The structure for getopt_long(). When you add/delete any line, please refine
19 * attribute_comments[] and third parameter of getopt_long() too. */
20 static struct option dev_options[] = {
21 {.name = "help", .has_arg = no_argument, .flag = 0, .val = 'h'},
22 {.name = "primary-header", .has_arg = no_argument, .flag = 0, .val = 'a'},
23 {.name = "primary-entries", .has_arg = no_argument, .flag = 0, .val = 'b'},
24 {.name = "secondary-entries", .has_arg = no_argument, .flag = 0, .val = 'c'},
25 {.name = "secondary-header", .has_arg = no_argument, .flag = 0, .val = 'd'},
26 { /* last element, which should be zero. */ }
27 };
28
29 /* Extra information than struct option, please update this structure if you
30 * add/remove any line in attribute_options[]. */
31 static struct option_details dev_options_details[] = {
32 /* help */
33 { .comment = "print this help",
34 .validator = AssignTrue,
35 .valid_range = 0,
36 .parsed = &help},
37 /* primary-header */
38 { .comment = "damage primary header",
39 .validator = AssignTrue,
40 .valid_range = 0,
41 .parsed = &primary_header},
42 /* primary-entries */
43 { .comment = "damage primary entries",
44 .validator = AssignTrue,
45 .valid_range = 0,
46 .parsed = &primary_entries},
47 /* secondary-entries */
48 { .comment = "damage secondary entries",
49 .validator = AssignTrue,
50 .valid_range = 0,
51 .parsed = &secondary_entries},
52 /* secondary-header */
53 { .comment = "damage secondary header",
54 .validator = AssignTrue,
55 .valid_range = 0,
56 .parsed = &secondary_header},
57 { /* last element, which should be zero. */ }
58 };
59
60 void DevHelp() {
61 printf("\nDeveloper mode.\n\n");
62 printf("\nUsage: %s dev [OPTIONS] device_name\n\n", progname);
63 ShowOptions(dev_options, dev_options_details, ARRAY_COUNT(dev_options));
64 printf("\n");
65 }
66
67 /* Very simple function, you may choose damage one or more of the following
68 * sections:
69 *
70 * Primary GPT header
71 * Primary GPT table entries
72 * Secondary GPT table entries
73 * Secondary GPT header
74 */
75 int CgptDev(int argc, char *argv[]) {
76 struct drive drive;
77
78 /* I know this is NOT the perfect place to put code to make options[] and
79 * details[] are synced. But this is the best place we have right now since C
80 * preprocessor doesn't know sizeof() for #if directive. */
81 assert(ARRAY_COUNT(dev_options) ==
82 ARRAY_COUNT(dev_options_details));
83
84 help = primary_header = primary_entries =
85 secondary_header = secondary_entries = NOT_INITED;
86
87 if (CGPT_OK != HandleOptions(argc, argv,
88 "h",
89 ARRAY_COUNT(dev_options),
90 dev_options,
91 dev_options_details))
92 return CGPT_FAILED;
93 if (help != NOT_INITED) {
94 DevHelp();
95 return CGPT_FAILED;
96 }
97
98 if (CGPT_OK != OpenDriveInLastArgument(argc, argv, &drive))
99 return CGPT_FAILED;
100
101 #define ANY_PRIME 7
102 if (primary_header != NOT_INITED) {
103 printf("* damage Pri Header\n");
104 drive.gpt.primary_header[0] += ANY_PRIME;
105 drive.gpt.modified |= GPT_MODIFIED_HEADER1;
106 }
107 if (primary_entries != NOT_INITED) {
108 printf("* damage Pri Table\n");
109 drive.gpt.primary_entries[0] += ANY_PRIME;
110 drive.gpt.modified |= GPT_MODIFIED_ENTRIES1;
111 }
112 if (secondary_entries != NOT_INITED) {
113 printf("* damage Sec Table\n");
114 drive.gpt.secondary_entries[0] += ANY_PRIME;
115 drive.gpt.modified |= GPT_MODIFIED_ENTRIES2;
116 }
117 if (secondary_header != NOT_INITED) {
118 printf("* damage Sec Header\n");
119 drive.gpt.secondary_header[0] += ANY_PRIME;
120 drive.gpt.modified |= GPT_MODIFIED_HEADER2;
121 }
122
123 DriveClose(&drive);
124
125 return CGPT_OK;
126 }
OLDNEW
« no previous file with comments | « utility/cgpt/cgpt_attribute.c ('k') | utility/cgpt/cgpt_options.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698