| 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 * Show GPT details. |
| 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 /* Integers to store parsed argument. */ | 14 /* Integers to store parsed argument. */ |
| 15 static int help, number, verbose; | 15 static int help, number, verbose; |
| 16 | 16 |
| 17 /* The structure for getopt_long(). When you add/delete any line, please refine | 17 /* The structure for getopt_long(). When you add/delete any line, please refine |
| 18 * attribute_comments[] and third parameter of getopt_long() too. */ | 18 * attribute_comments[] and third parameter of getopt_long() too. */ |
| 19 static struct option show_options[] = { | 19 static struct option show_options[] = { |
| 20 {.name = "help", .has_arg = no_argument, .flag = 0, .val = 'h'}, | 20 {.name = "help", .has_arg = no_argument, .flag = 0, .val = 'h'}, |
| 21 {.name = "number", .has_arg = no_argument, .flag = 0, .val = 'n'}, | 21 {.name = "number", .has_arg = no_argument, .flag = 0, .val = 'n'}, |
| 22 {.name = "verbose", .has_arg = no_argument, .flag = 0, .val = 'v'}, | 22 {.name = "verbose", .has_arg = no_argument, .flag = 0, .val = 'v'}, |
| 23 { /* last element, which should be zero. */ } |
| 23 }; | 24 }; |
| 24 | 25 |
| 25 /* Extra information than struct option, please update this structure if you | 26 /* Extra information than struct option, please update this structure if you |
| 26 * add/remove any line in attribute_options[]. */ | 27 * add/remove any line in attribute_options[]. */ |
| 27 static struct option_details show_options_details[] = { | 28 static struct option_details show_options_details[] = { |
| 28 /* help */ | 29 /* help */ |
| 29 { .comment = "print this help", | 30 { .comment = "print this help", |
| 30 .validator = AssignTrue, | 31 .validator = AssignTrue, |
| 31 .valid_range = 0, | 32 .valid_range = 0, |
| 32 .parsed = &help}, | 33 .parsed = &help}, |
| 33 /* number */ | 34 /* number */ |
| 34 { .comment = "print raw numbers (don't interpret)", | 35 { .comment = "print raw numbers (don't interpret)", |
| 35 .validator = AssignTrue, | 36 .validator = AssignTrue, |
| 36 .valid_range = 0, | 37 .valid_range = 0, |
| 37 .parsed = &number}, | 38 .parsed = &number}, |
| 38 /* verbose */ | 39 /* verbose */ |
| 39 { .comment = "verbose print", | 40 { .comment = "verbose print", |
| 40 .validator = AssignTrue, | 41 .validator = AssignTrue, |
| 41 .valid_range = 0, | 42 .valid_range = 0, |
| 42 .parsed = &verbose}, | 43 .parsed = &verbose}, |
| 44 { /* last element, which should be zero. */ } |
| 43 }; | 45 }; |
| 44 | 46 |
| 45 void ShowHelp() { | 47 void ShowHelp() { |
| 46 printf("\nUsage: %s show [OPTIONS] device_name\n\n", progname); | 48 printf("\nUsage: %s show [OPTIONS] device_name\n\n", progname); |
| 47 ShowOptions(show_options, show_options_details, ARRAY_COUNT(show_options)); | 49 ShowOptions(show_options, show_options_details, ARRAY_COUNT(show_options)); |
| 48 printf("\n"); | 50 printf("\n"); |
| 49 } | 51 } |
| 50 | 52 |
| 51 /* Generate output like: | 53 /* Generate output like: |
| 52 * | 54 * |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 GuidToStr(&header->disk_uuid, buf); | 116 GuidToStr(&header->disk_uuid, buf); |
| 115 printf("%sDisk UUID: %s\n", indent, buf); | 117 printf("%sDisk UUID: %s\n", indent, buf); |
| 116 } | 118 } |
| 117 | 119 |
| 118 printf("%sEntries LBA: %lld\n", indent, (long long)header->entries_lba); | 120 printf("%sEntries LBA: %lld\n", indent, (long long)header->entries_lba); |
| 119 printf("%sNumber of entries: %d\n", indent, header->number_of_entries); | 121 printf("%sNumber of entries: %d\n", indent, header->number_of_entries); |
| 120 printf("%sSize of entry: %d\n", indent, header->size_of_entry); | 122 printf("%sSize of entry: %d\n", indent, header->size_of_entry); |
| 121 printf("%sEntries CRC: 0x%08x\n", indent, header->entries_crc32); | 123 printf("%sEntries CRC: 0x%08x\n", indent, header->entries_crc32); |
| 122 } | 124 } |
| 123 | 125 |
| 124 /* Resolves human-readable GPT type. | |
| 125 * Returns CGPT_OK if found. | |
| 126 * Returns CGPT_FAILED if no known type found. */ | |
| 127 int ResolveType(const Guid *type, char *buf) { | |
| 128 struct { | |
| 129 Guid type; | |
| 130 char *description; | |
| 131 } known[] = { | |
| 132 {GPT_ENT_TYPE_UNUSED, "Unused partition"}, | |
| 133 {GPT_ENT_TYPE_EFI, "EFI partition"}, | |
| 134 {GPT_ENT_TYPE_CHROMEOS_KERNEL, "ChromeOS kernel"}, | |
| 135 {GPT_ENT_TYPE_CHROMEOS_ROOTFS, "ChromeOS rootfs"}, | |
| 136 {GPT_ENT_TYPE_CHROMEOS_RESERVED, "ChromeOS reserved"}, | |
| 137 }; | |
| 138 int i; | |
| 139 | |
| 140 for (i = 0; i < ARRAY_COUNT(known); ++i) { | |
| 141 if (!Memcmp(type, &known[i].type, sizeof(Guid))) { | |
| 142 strcpy(buf, known[i].description); | |
| 143 return CGPT_OK; | |
| 144 } | |
| 145 } | |
| 146 return CGPT_FAILED; | |
| 147 } | |
| 148 | |
| 149 void EntriesDetails(GptData *gpt, const int secondary) { | 126 void EntriesDetails(GptData *gpt, const int secondary) { |
| 150 int i; | 127 int i; |
| 151 | 128 |
| 152 for (i = 0; i < GetNumberOfEntries(gpt); ++i) { | 129 for (i = 0; i < GetNumberOfEntries(gpt); ++i) { |
| 153 static Guid unused = GPT_ENT_TYPE_UNUSED; | 130 static Guid unused = GPT_ENT_TYPE_UNUSED; |
| 154 char contents[256]; | 131 char contents[256]; |
| 155 | 132 |
| 156 GptEntry *entry; | 133 GptEntry *entry; |
| 157 entry = GetEntry(gpt, secondary, i); | 134 entry = GetEntry(gpt, secondary, i); |
| 158 | 135 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 "hnv", | 206 "hnv", |
| 230 ARRAY_COUNT(show_options), | 207 ARRAY_COUNT(show_options), |
| 231 show_options, | 208 show_options, |
| 232 show_options_details)) | 209 show_options_details)) |
| 233 return CGPT_FAILED; | 210 return CGPT_FAILED; |
| 234 if (help != NOT_INITED) { | 211 if (help != NOT_INITED) { |
| 235 ShowHelp(); | 212 ShowHelp(); |
| 236 return CGPT_FAILED; | 213 return CGPT_FAILED; |
| 237 } | 214 } |
| 238 | 215 |
| 216 OpenDriveInLastArgument(argc, argv, &drive); |
| 239 if (CGPT_OK != OpenDriveInLastArgument(argc, argv, &drive)) | 217 if (CGPT_OK != OpenDriveInLastArgument(argc, argv, &drive)) |
| 240 return CGPT_FAILED; | 218 return CGPT_FAILED; |
| 241 | 219 |
| 242 printf(TITLE_FMT, "start", "size", "index", "contents"); | 220 printf(TITLE_FMT, "start", "size", "index", "contents"); |
| 243 printf(GPT_FMT, 0, GPT_PMBR_SECTOR, "", "PMBR"); | 221 printf(GPT_FMT, 0, GPT_PMBR_SECTOR, "", "PMBR"); |
| 244 | 222 |
| 245 if (drive.gpt.valid_headers & MASK_PRIMARY) { | 223 if (drive.gpt.valid_headers & MASK_PRIMARY) { |
| 246 printf(GPT_FMT, (int)GPT_PMBR_SECTOR, | 224 printf(GPT_FMT, (int)GPT_PMBR_SECTOR, |
| 247 (int)GPT_HEADER_SECTOR, "", "Pri GPT header"); | 225 (int)GPT_HEADER_SECTOR, "", "Pri GPT header"); |
| 248 if (verbose) { | 226 if (verbose) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 header = (GptHeader*)drive.gpt.secondary_header; | 282 header = (GptHeader*)drive.gpt.secondary_header; |
| 305 HeaderDetails(header, indent); | 283 HeaderDetails(header, indent); |
| 306 } | 284 } |
| 307 } | 285 } |
| 308 | 286 |
| 309 CheckValid(&drive); | 287 CheckValid(&drive); |
| 310 DriveClose(&drive); | 288 DriveClose(&drive); |
| 311 | 289 |
| 312 return CGPT_OK; | 290 return CGPT_OK; |
| 313 } | 291 } |
| OLD | NEW |