OLD | NEW |
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 * | 4 * |
5 * Update GPT attribute bits. | 5 * Update GPT attribute bits. |
6 */ | 6 */ |
7 #include <getopt.h> | 7 #include <getopt.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include "cgpt.h" | 10 #include "cgpt.h" |
11 #include "cgptlib_internal.h" | 11 #include "cgptlib_internal.h" |
12 #include "utility.h" | 12 #include "utility.h" |
13 | 13 |
14 static struct number_range | 14 static struct number_range |
15 range_1_0 = {1, 0}, | 15 range_1_0 = {1, 0}, |
16 range_15_0 = {15, 0}; | 16 range_15_0 = {15, 0}; |
17 | 17 |
18 /* Integers to store parsed argument. */ | 18 /* Integers to store parsed argument. */ |
19 static int help, partition, bad, successful, tries, priority; | 19 static int help, partition, bad, successful, tries, priority; |
20 | 20 |
21 /* The structure for getopt_long(). When you add/delete any line, please refine | 21 /* The structure for getopt_long(). When you add/delete any line, please refine |
22 * attribute_comments[] and third parameter of getopt_long() too. */ | 22 * attribute_comments[] and third parameter of getopt_long() too. */ |
23 static struct option attribute_options[] = { | 23 static struct option attribute_options[] = { |
24 {.name = "help", .has_arg = no_argument, .flag = 0, .val = 'h'}, | 24 {.name = "help", .has_arg = no_argument, .flag = 0, .val = 'h'}, |
25 {.name = "partition", .has_arg = required_argument, .flag = 0, .val = 'i'}, | 25 {.name = "partition", .has_arg = required_argument, .flag = 0, .val = 'i'}, |
26 {.name = "bad", .has_arg = required_argument, .flag = 0, .val = 'b'}, | 26 {.name = "bad", .has_arg = required_argument, .flag = 0, .val = 'b'}, |
27 {.name = "successful", .has_arg = required_argument, .flag = 0, .val = 's'}, | 27 {.name = "successful", .has_arg = required_argument, .flag = 0, .val = 's'}, |
28 {.name = "tries", .has_arg = required_argument, .flag = 0, .val = 't'}, | 28 {.name = "tries", .has_arg = required_argument, .flag = 0, .val = 't'}, |
29 {.name = "priority", .has_arg = required_argument, .flag = 0, .val = 'p'}, | 29 {.name = "priority", .has_arg = required_argument, .flag = 0, .val = 'p'}, |
| 30 { /* last element, which should be zero. */ } |
30 }; | 31 }; |
31 | 32 |
32 /* Extra information than struct option, please update this structure if you | 33 /* Extra information than struct option, please update this structure if you |
33 * add/remove any line in attribute_options[]. */ | 34 * add/remove any line in attribute_options[]. */ |
34 static struct option_details attribute_options_details[] = { | 35 static struct option_details attribute_options_details[] = { |
35 /* help */ | 36 /* help */ |
36 { .comment = "print this help", | 37 { .comment = "print this help", |
37 .validator = AssignTrue, | 38 .validator = AssignTrue, |
38 .valid_range = 0, | 39 .valid_range = 0, |
39 .parsed = &help}, | 40 .parsed = &help}, |
(...skipping 16 matching lines...) Expand all Loading... |
56 /* tries */ | 57 /* tries */ |
57 { .comment = "tries", | 58 { .comment = "tries", |
58 .validator = InNumberRange, | 59 .validator = InNumberRange, |
59 .valid_range = &range_15_0, | 60 .valid_range = &range_15_0, |
60 .parsed = &tries}, | 61 .parsed = &tries}, |
61 /* priority */ | 62 /* priority */ |
62 { .comment = "priority to boot", | 63 { .comment = "priority to boot", |
63 .validator = InNumberRange, | 64 .validator = InNumberRange, |
64 .valid_range = &range_15_0, | 65 .valid_range = &range_15_0, |
65 .parsed = &priority}, | 66 .parsed = &priority}, |
| 67 { /* last element, which should be zero. */ } |
66 }; | 68 }; |
67 | 69 |
68 void AttributeHelp() { | 70 void AttributeHelp() { |
69 printf("\nUsage: %s attribute [OPTIONS] device_name\n\n", progname); | 71 printf("\nUsage: %s attribute [OPTIONS] device_name\n\n", progname); |
70 ShowOptions(attribute_options, attribute_options_details, | 72 ShowOptions(attribute_options, attribute_options_details, |
71 ARRAY_COUNT(attribute_options)); | 73 ARRAY_COUNT(attribute_options)); |
72 printf("\n* Attribute command only applies on ChromeOS kernel entry.\n\n"); | 74 printf("\n* Attribute command only applies on ChromeOS kernel entry.\n\n"); |
73 } | 75 } |
74 | 76 |
75 /* Parses all options (and validates them), then opens the drive and sets | 77 /* Parses all options (and validates them), then opens the drive and sets |
(...skipping 18 matching lines...) Expand all Loading... |
94 if (help != NOT_INITED) { | 96 if (help != NOT_INITED) { |
95 AttributeHelp(); | 97 AttributeHelp(); |
96 return CGPT_FAILED; | 98 return CGPT_FAILED; |
97 } | 99 } |
98 | 100 |
99 if (CGPT_OK != OpenDriveInLastArgument(argc, argv, &drive)) | 101 if (CGPT_OK != OpenDriveInLastArgument(argc, argv, &drive)) |
100 return CGPT_FAILED; | 102 return CGPT_FAILED; |
101 | 103 |
102 if (CheckValid(&drive) != CGPT_OK) return CGPT_FAILED; | 104 if (CheckValid(&drive) != CGPT_OK) return CGPT_FAILED; |
103 | 105 |
104 debug("[OPTION] i:%d b:%d s:%d t:%d p:%d\n", partition, bad, successful, tries
, priority); /* FIXME */ | |
105 | |
106 /* partition is not specified, search for the first Chromeos kernel. */ | 106 /* partition is not specified, search for the first Chromeos kernel. */ |
107 if (partition == NOT_INITED) { | 107 if (partition == NOT_INITED) { |
108 int i; | 108 int i; |
109 for (i = 0; i < GetNumberOfEntries(&drive.gpt); ++i) { | 109 for (i = 0; i < GetNumberOfEntries(&drive.gpt); ++i) { |
110 static Guid chromeos_kernel = GPT_ENT_TYPE_CHROMEOS_KERNEL; | 110 static Guid chromeos_kernel = GPT_ENT_TYPE_CHROMEOS_KERNEL; |
111 GptEntry *entry; | 111 GptEntry *entry; |
112 entry = GetEntry(&drive.gpt, PRIMARY, i); | 112 entry = GetEntry(&drive.gpt, PRIMARY, i); |
113 if (!Memcmp(&chromeos_kernel, &entry->type, sizeof(Guid))) { | 113 if (!Memcmp(&chromeos_kernel, &entry->type, sizeof(Guid))) { |
114 partition = i; | 114 partition = i; |
115 break; | 115 break; |
(...skipping 24 matching lines...) Expand all Loading... |
140 RepairHeader(&drive.gpt, MASK_PRIMARY); | 140 RepairHeader(&drive.gpt, MASK_PRIMARY); |
141 /* Forces headers and entries are modified so that CRC32 will be re-calculated | 141 /* Forces headers and entries are modified so that CRC32 will be re-calculated |
142 * and headers and entries will be updated to drive. */ | 142 * and headers and entries will be updated to drive. */ |
143 drive.gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 | | 143 drive.gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 | |
144 GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES2); | 144 GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES2); |
145 UpdateCrc(&drive.gpt); | 145 UpdateCrc(&drive.gpt); |
146 DriveClose(&drive); | 146 DriveClose(&drive); |
147 | 147 |
148 return CGPT_OK; | 148 return CGPT_OK; |
149 } | 149 } |
OLD | NEW |