Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 5 | #define __STDC_FORMAT_MACROS |
| 6 | #include <getopt.h> |
Bill Richardson | c4e92af | 2010-10-12 07:33:15 -0700 | [diff] [blame] | 7 | #include <inttypes.h> |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 8 | #include <string.h> |
Bill Richardson | 0c3ba24 | 2013-03-29 11:09:30 -0700 | [diff] [blame] | 9 | |
| 10 | #include "cgpt.h" |
| 11 | #include "vboot_host.h" |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 12 | |
Bill Richardson | 4cb5497 | 2014-06-20 14:33:00 -0700 | [diff] [blame] | 13 | extern const char* progname; |
| 14 | |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 15 | static void Usage(void) |
| 16 | { |
| 17 | printf("\nUsage: %s show [OPTIONS] DRIVE\n\n" |
| 18 | "Display the GPT table\n\n" |
| 19 | "Options:\n" |
Nam T. Nguyen | ab89959 | 2014-11-13 19:30:46 -0800 | [diff] [blame] | 20 | " -D NUM Size (in bytes) of the disk where partitions reside\n" |
| 21 | " default 0, meaning partitions and GPT structs are\n" |
| 22 | " both on DRIVE\n" |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 23 | " -n Numeric output only\n" |
| 24 | " -v Verbose output\n" |
| 25 | " -q Quick output\n" |
| 26 | " -i NUM Show specified partition only - pick one of:\n" |
| 27 | " -b beginning sector\n" |
| 28 | " -s partition size\n" |
| 29 | " -t type guid\n" |
| 30 | " -u unique guid\n" |
| 31 | " -l label\n" |
| 32 | " -S Successful flag\n" |
| 33 | " -T Tries flag\n" |
| 34 | " -P Priority flag\n" |
| 35 | " -A raw 64-bit attribute value\n" |
Louis Yung-Chieh Lo | 455b119 | 2012-06-26 14:48:39 +0800 | [diff] [blame] | 36 | " -d Debug output (including invalid headers)\n" |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 37 | "\n", progname); |
| 38 | } |
| 39 | |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 40 | int cmd_show(int argc, char *argv[]) { |
Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 41 | CgptShowParams params; |
| 42 | memset(¶ms, 0, sizeof(params)); |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 43 | |
| 44 | int c; |
| 45 | int errorcnt = 0; |
| 46 | char *e = 0; |
| 47 | |
| 48 | opterr = 0; // quiet, you |
Nam T. Nguyen | ab89959 | 2014-11-13 19:30:46 -0800 | [diff] [blame] | 49 | while ((c=getopt(argc, argv, ":hnvqi:bstulSTPAdD:")) != -1) |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 50 | { |
| 51 | switch (c) |
| 52 | { |
Nam T. Nguyen | ab89959 | 2014-11-13 19:30:46 -0800 | [diff] [blame] | 53 | case 'D': |
| 54 | params.drive_size = strtoull(optarg, &e, 0); |
| 55 | if (!*optarg || (e && *e)) |
| 56 | { |
| 57 | Error("invalid argument to -%c: \"%s\"\n", c, optarg); |
| 58 | errorcnt++; |
| 59 | } |
| 60 | break; |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 61 | case 'n': |
Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 62 | params.numeric = 1; |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 63 | break; |
| 64 | case 'v': |
Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 65 | params.verbose = 1; |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 66 | break; |
| 67 | case 'q': |
Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 68 | params.quick = 1; |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 69 | break; |
| 70 | case 'i': |
Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 71 | params.partition = (uint32_t)strtoul(optarg, &e, 0); |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 72 | if (!*optarg || (e && *e)) |
| 73 | { |
| 74 | Error("invalid argument to -%c: \"%s\"\n", c, optarg); |
| 75 | errorcnt++; |
| 76 | } |
| 77 | break; |
| 78 | case 'b': |
| 79 | case 's': |
| 80 | case 't': |
| 81 | case 'u': |
| 82 | case 'l': |
| 83 | case 'S': |
| 84 | case 'T': |
| 85 | case 'P': |
| 86 | case 'A': |
Jay Srinivasan | a058143 | 2012-01-26 21:50:05 -0800 | [diff] [blame] | 87 | params.single_item = c; |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 88 | break; |
| 89 | |
Louis Yung-Chieh Lo | 455b119 | 2012-06-26 14:48:39 +0800 | [diff] [blame] | 90 | case 'd': |
| 91 | params.debug = 1; |
| 92 | break; |
| 93 | |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 94 | case 'h': |
| 95 | Usage(); |
| 96 | return CGPT_OK; |
| 97 | case '?': |
| 98 | Error("unrecognized option: -%c\n", optopt); |
| 99 | errorcnt++; |
| 100 | break; |
| 101 | case ':': |
| 102 | Error("missing argument to -%c\n", optopt); |
| 103 | errorcnt++; |
| 104 | break; |
| 105 | default: |
| 106 | errorcnt++; |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | if (errorcnt) |
| 111 | { |
| 112 | Usage(); |
| 113 | return CGPT_FAILED; |
| 114 | } |
| 115 | |
| 116 | if (optind >= argc) { |
| 117 | Error("missing drive argument\n"); |
| 118 | Usage(); |
| 119 | return CGPT_FAILED; |
| 120 | } |
| 121 | |
Jay Srinivasan | 250549d | 2012-02-16 17:40:45 -0800 | [diff] [blame] | 122 | params.drive_name = argv[optind]; |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 123 | |
Bill Richardson | 3f806a2 | 2013-03-20 15:02:34 -0700 | [diff] [blame] | 124 | return CgptShow(¶ms); |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 125 | } |