| 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 #include "cgpt.h" | 5 #include "cgpt.h" |
| 6 | 6 |
| 7 #define __STDC_FORMAT_MACROS | 7 #define __STDC_FORMAT_MACROS |
| 8 #include <getopt.h> | 8 #include <getopt.h> |
| 9 #include <inttypes.h> | 9 #include <inttypes.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 } | 267 } |
| 268 | 268 |
| 269 if (partition) { // show single partition | 269 if (partition) { // show single partition |
| 270 | 270 |
| 271 if (partition > GetNumberOfEntries(&drive.gpt)) { | 271 if (partition > GetNumberOfEntries(&drive.gpt)) { |
| 272 Error("invalid partition number: %d\n", partition); | 272 Error("invalid partition number: %d\n", partition); |
| 273 return CGPT_FAILED; | 273 return CGPT_FAILED; |
| 274 } | 274 } |
| 275 | 275 |
| 276 uint32_t index = partition - 1; | 276 uint32_t index = partition - 1; |
| 277 GptEntry *entry = GetEntry(&drive.gpt, PRIMARY, index); | 277 GptEntry *entry = GetEntry(&drive.gpt, ANY_VALID, index); |
| 278 char buf[256]; // scratch buffer for string conversion | 278 char buf[256]; // scratch buffer for string conversion |
| 279 | 279 |
| 280 if (single_item) { | 280 if (single_item) { |
| 281 switch(single_item) { | 281 switch(single_item) { |
| 282 case 'b': | 282 case 'b': |
| 283 printf("%" PRId64 "\n", entry->starting_lba); | 283 printf("%" PRId64 "\n", entry->starting_lba); |
| 284 break; | 284 break; |
| 285 case 's': | 285 case 's': |
| 286 printf("%" PRId64 "\n", entry->ending_lba - entry->starting_lba + 1); | 286 printf("%" PRId64 "\n", entry->ending_lba - entry->starting_lba + 1); |
| 287 break; | 287 break; |
| 288 case 't': | 288 case 't': |
| 289 GuidToStr(&entry->type, buf, sizeof(buf)); | 289 GuidToStr(&entry->type, buf, sizeof(buf)); |
| 290 printf("%s\n", buf); | 290 printf("%s\n", buf); |
| 291 break; | 291 break; |
| 292 case 'u': | 292 case 'u': |
| 293 GuidToStr(&entry->unique, buf, sizeof(buf)); | 293 GuidToStr(&entry->unique, buf, sizeof(buf)); |
| 294 printf("%s\n", buf); | 294 printf("%s\n", buf); |
| 295 break; | 295 break; |
| 296 case 'l': | 296 case 'l': |
| 297 UTF16ToUTF8(entry->name, sizeof(entry->name) / sizeof(entry->name[0]), | 297 UTF16ToUTF8(entry->name, sizeof(entry->name) / sizeof(entry->name[0]), |
| 298 (uint8_t *)buf, sizeof(buf)); | 298 (uint8_t *)buf, sizeof(buf)); |
| 299 printf("%s\n", buf); | 299 printf("%s\n", buf); |
| 300 break; | 300 break; |
| 301 case 'S': | 301 case 'S': |
| 302 printf("%d\n", GetSuccessful(&drive.gpt, PRIMARY, index)); | 302 printf("%d\n", GetSuccessful(&drive.gpt, ANY_VALID, index)); |
| 303 break; | 303 break; |
| 304 case 'T': | 304 case 'T': |
| 305 printf("%d\n", GetTries(&drive.gpt, PRIMARY, index)); | 305 printf("%d\n", GetTries(&drive.gpt, ANY_VALID, index)); |
| 306 break; | 306 break; |
| 307 case 'P': | 307 case 'P': |
| 308 printf("%d\n", GetPriority(&drive.gpt, PRIMARY, index)); | 308 printf("%d\n", GetPriority(&drive.gpt, ANY_VALID, index)); |
| 309 break; | 309 break; |
| 310 case 'A': | 310 case 'A': |
| 311 printf("0x%x\n", entry->attrs.fields.gpt_att); | 311 printf("0x%x\n", entry->attrs.fields.gpt_att); |
| 312 break; | 312 break; |
| 313 } | 313 } |
| 314 } else { | 314 } else { |
| 315 printf(TITLE_FMT, "start", "size", "part", "contents"); | 315 printf(TITLE_FMT, "start", "size", "part", "contents"); |
| 316 EntryDetails(entry, index, numeric); | 316 EntryDetails(entry, index, numeric); |
| 317 } | 317 } |
| 318 | 318 |
| 319 } else if (quick) { // show all partitions, quickly | 319 } else if (quick) { // show all partitions, quickly |
| 320 uint32_t i; | 320 uint32_t i; |
| 321 GptEntry *entry; | 321 GptEntry *entry; |
| 322 char type[GUID_STRLEN]; | 322 char type[GUID_STRLEN]; |
| 323 | 323 |
| 324 for (i = 0; i < GetNumberOfEntries(&drive.gpt); ++i) { | 324 for (i = 0; i < GetNumberOfEntries(&drive.gpt); ++i) { |
| 325 entry = GetEntry(&drive.gpt, PRIMARY, i); | 325 entry = GetEntry(&drive.gpt, ANY_VALID, i); |
| 326 | 326 |
| 327 if (IsZero(&entry->type)) | 327 if (IsZero(&entry->type)) |
| 328 continue; | 328 continue; |
| 329 | 329 |
| 330 if (!numeric && CGPT_OK == ResolveType(&entry->type, type)) { | 330 if (!numeric && CGPT_OK == ResolveType(&entry->type, type)) { |
| 331 } else { | 331 } else { |
| 332 GuidToStr(&entry->type, type, GUID_STRLEN); | 332 GuidToStr(&entry->type, type, GUID_STRLEN); |
| 333 } | 333 } |
| 334 printf(PARTITION_FMT, (int)entry->starting_lba, | 334 printf(PARTITION_FMT, (int)entry->starting_lba, |
| 335 (int)(entry->ending_lba - entry->starting_lba + 1), | 335 (int)(entry->ending_lba - entry->starting_lba + 1), |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 HeaderDetails(header, indent, numeric); | 411 HeaderDetails(header, indent, numeric); |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 } | 414 } |
| 415 | 415 |
| 416 (void) CheckValid(&drive); | 416 (void) CheckValid(&drive); |
| 417 (void) DriveClose(&drive, 0); | 417 (void) DriveClose(&drive, 0); |
| 418 | 418 |
| 419 return CGPT_OK; | 419 return CGPT_OK; |
| 420 } | 420 } |
| OLD | NEW |