blob: 509085ee4aef56261ce763aa6c316c806844a4b9 [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
5#include "cgpt.h"
6
7#define __STDC_FORMAT_MACROS
8#include <getopt.h>
Bill Richardsonc4e92af2010-10-12 07:33:15 -07009#include <inttypes.h>
Bill Richardsonf1372d92010-06-11 09:15:55 -070010#include <string.h>
Jay Srinivasana0581432012-01-26 21:50:05 -080011#include "cgpt_params.h"
Bill Richardsonf1372d92010-06-11 09:15:55 -070012
13static void Usage(void)
14{
15 printf("\nUsage: %s show [OPTIONS] DRIVE\n\n"
16 "Display the GPT table\n\n"
17 "Options:\n"
18 " -n Numeric output only\n"
19 " -v Verbose output\n"
20 " -q Quick output\n"
21 " -i NUM Show specified partition only - pick one of:\n"
22 " -b beginning sector\n"
23 " -s partition size\n"
24 " -t type guid\n"
25 " -u unique guid\n"
26 " -l label\n"
27 " -S Successful flag\n"
28 " -T Tries flag\n"
29 " -P Priority flag\n"
30 " -A raw 64-bit attribute value\n"
31 "\n", progname);
32}
33
Bill Richardsonf1372d92010-06-11 09:15:55 -070034int cmd_show(int argc, char *argv[]) {
35 struct drive drive;
Jay Srinivasana0581432012-01-26 21:50:05 -080036
37 CgptShowParams params;
38 memset(&params, 0, sizeof(params));
Bill Richardsonf1372d92010-06-11 09:15:55 -070039
40 int c;
41 int errorcnt = 0;
42 char *e = 0;
43
44 opterr = 0; // quiet, you
45 while ((c=getopt(argc, argv, ":hnvqi:bstulSTPA")) != -1)
46 {
47 switch (c)
48 {
49 case 'n':
Jay Srinivasana0581432012-01-26 21:50:05 -080050 params.numeric = 1;
Bill Richardsonf1372d92010-06-11 09:15:55 -070051 break;
52 case 'v':
Jay Srinivasana0581432012-01-26 21:50:05 -080053 params.verbose = 1;
Bill Richardsonf1372d92010-06-11 09:15:55 -070054 break;
55 case 'q':
Jay Srinivasana0581432012-01-26 21:50:05 -080056 params.quick = 1;
Bill Richardsonf1372d92010-06-11 09:15:55 -070057 break;
58 case 'i':
Jay Srinivasana0581432012-01-26 21:50:05 -080059 params.partition = (uint32_t)strtoul(optarg, &e, 0);
Bill Richardsonf1372d92010-06-11 09:15:55 -070060 if (!*optarg || (e && *e))
61 {
62 Error("invalid argument to -%c: \"%s\"\n", c, optarg);
63 errorcnt++;
64 }
65 break;
66 case 'b':
67 case 's':
68 case 't':
69 case 'u':
70 case 'l':
71 case 'S':
72 case 'T':
73 case 'P':
74 case 'A':
Jay Srinivasana0581432012-01-26 21:50:05 -080075 params.single_item = c;
Bill Richardsonf1372d92010-06-11 09:15:55 -070076 break;
77
78 case 'h':
79 Usage();
80 return CGPT_OK;
81 case '?':
82 Error("unrecognized option: -%c\n", optopt);
83 errorcnt++;
84 break;
85 case ':':
86 Error("missing argument to -%c\n", optopt);
87 errorcnt++;
88 break;
89 default:
90 errorcnt++;
91 break;
92 }
93 }
94 if (errorcnt)
95 {
96 Usage();
97 return CGPT_FAILED;
98 }
99
100 if (optind >= argc) {
101 Error("missing drive argument\n");
102 Usage();
103 return CGPT_FAILED;
104 }
105
Jay Srinivasana0581432012-01-26 21:50:05 -0800106 params.driveName = argv[optind];
Bill Richardsonf1372d92010-06-11 09:15:55 -0700107
Jay Srinivasana0581432012-01-26 21:50:05 -0800108 return cgpt_show(&params);
Bill Richardsonf1372d92010-06-11 09:15:55 -0700109}