blob: dcfefdd3925ffd531e4ce6017a40409e3d752b12 [file] [log] [blame]
Jay Srinivasana0581432012-01-26 21:50:05 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Bill Richardsonf1372d92010-06-11 09:15:55 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Bill Richardsonf1372d92010-06-11 09:15:55 -07005#define __STDC_FORMAT_MACROS
6#include <getopt.h>
Bill Richardsonc4e92af2010-10-12 07:33:15 -07007#include <inttypes.h>
Bill Richardsonf1372d92010-06-11 09:15:55 -07008#include <string.h>
Bill Richardson0c3ba242013-03-29 11:09:30 -07009
10#include "cgpt.h"
11#include "vboot_host.h"
Bill Richardsonf1372d92010-06-11 09:15:55 -070012
Bill Richardson4cb54972014-06-20 14:33:00 -070013extern const char* progname;
14
Bill Richardsonf1372d92010-06-11 09:15:55 -070015static 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. Nguyenab899592014-11-13 19:30:46 -080020 " -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 Richardsonf1372d92010-06-11 09:15:55 -070023 " -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 Lo455b1192012-06-26 14:48:39 +080036 " -d Debug output (including invalid headers)\n"
Bill Richardsonf1372d92010-06-11 09:15:55 -070037 "\n", progname);
38}
39
Bill Richardsonf1372d92010-06-11 09:15:55 -070040int cmd_show(int argc, char *argv[]) {
Jay Srinivasana0581432012-01-26 21:50:05 -080041 CgptShowParams params;
42 memset(&params, 0, sizeof(params));
Bill Richardsonf1372d92010-06-11 09:15:55 -070043
44 int c;
45 int errorcnt = 0;
46 char *e = 0;
47
48 opterr = 0; // quiet, you
Nam T. Nguyenab899592014-11-13 19:30:46 -080049 while ((c=getopt(argc, argv, ":hnvqi:bstulSTPAdD:")) != -1)
Bill Richardsonf1372d92010-06-11 09:15:55 -070050 {
51 switch (c)
52 {
Nam T. Nguyenab899592014-11-13 19:30:46 -080053 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 Richardsonf1372d92010-06-11 09:15:55 -070061 case 'n':
Jay Srinivasana0581432012-01-26 21:50:05 -080062 params.numeric = 1;
Bill Richardsonf1372d92010-06-11 09:15:55 -070063 break;
64 case 'v':
Jay Srinivasana0581432012-01-26 21:50:05 -080065 params.verbose = 1;
Bill Richardsonf1372d92010-06-11 09:15:55 -070066 break;
67 case 'q':
Jay Srinivasana0581432012-01-26 21:50:05 -080068 params.quick = 1;
Bill Richardsonf1372d92010-06-11 09:15:55 -070069 break;
70 case 'i':
Jay Srinivasana0581432012-01-26 21:50:05 -080071 params.partition = (uint32_t)strtoul(optarg, &e, 0);
Bill Richardsonf1372d92010-06-11 09:15:55 -070072 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 Srinivasana0581432012-01-26 21:50:05 -080087 params.single_item = c;
Bill Richardsonf1372d92010-06-11 09:15:55 -070088 break;
89
Louis Yung-Chieh Lo455b1192012-06-26 14:48:39 +080090 case 'd':
91 params.debug = 1;
92 break;
93
Bill Richardsonf1372d92010-06-11 09:15:55 -070094 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 Srinivasan250549d2012-02-16 17:40:45 -0800122 params.drive_name = argv[optind];
Bill Richardsonf1372d92010-06-11 09:15:55 -0700123
Bill Richardson3f806a22013-03-20 15:02:34 -0700124 return CgptShow(&params);
Bill Richardsonf1372d92010-06-11 09:15:55 -0700125}