mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-08 16:41:55 +00:00
The debug mode is used to dump GPT headers and entries no matter the
they are valid or not.
BUG=chromium-os:32142
TEST=tested in chroot with the bad secondary entries.
% cgpt show /dev/sda -d
...
976773135 32 INVALID Sec GPT table
282624 968101888 1 Label: "STATE"
Type: Linux data
...
1 1 INVALID Sec GPT header
Sig: [EFI PART]
Rev: 0x00010000
...
Change-Id: Ie54068353b87c9f15915ffb51b8de688e0367975
Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26091
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Tested-by: Yung-Chieh Lo <yjlou%chromium.org@gtempaccount.com>
Commit-Ready: Yung-Chieh Lo <yjlou%chromium.org@gtempaccount.com>
113 lines
2.5 KiB
C
113 lines
2.5 KiB
C
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "cgpt.h"
|
|
|
|
#define __STDC_FORMAT_MACROS
|
|
#include <getopt.h>
|
|
#include <inttypes.h>
|
|
#include <string.h>
|
|
#include "cgpt_params.h"
|
|
|
|
static void Usage(void)
|
|
{
|
|
printf("\nUsage: %s show [OPTIONS] DRIVE\n\n"
|
|
"Display the GPT table\n\n"
|
|
"Options:\n"
|
|
" -n Numeric output only\n"
|
|
" -v Verbose output\n"
|
|
" -q Quick output\n"
|
|
" -i NUM Show specified partition only - pick one of:\n"
|
|
" -b beginning sector\n"
|
|
" -s partition size\n"
|
|
" -t type guid\n"
|
|
" -u unique guid\n"
|
|
" -l label\n"
|
|
" -S Successful flag\n"
|
|
" -T Tries flag\n"
|
|
" -P Priority flag\n"
|
|
" -A raw 64-bit attribute value\n"
|
|
" -d Debug output (including invalid headers)\n"
|
|
"\n", progname);
|
|
}
|
|
|
|
int cmd_show(int argc, char *argv[]) {
|
|
CgptShowParams params;
|
|
memset(¶ms, 0, sizeof(params));
|
|
|
|
int c;
|
|
int errorcnt = 0;
|
|
char *e = 0;
|
|
|
|
opterr = 0; // quiet, you
|
|
while ((c=getopt(argc, argv, ":hnvqi:bstulSTPAd")) != -1)
|
|
{
|
|
switch (c)
|
|
{
|
|
case 'n':
|
|
params.numeric = 1;
|
|
break;
|
|
case 'v':
|
|
params.verbose = 1;
|
|
break;
|
|
case 'q':
|
|
params.quick = 1;
|
|
break;
|
|
case 'i':
|
|
params.partition = (uint32_t)strtoul(optarg, &e, 0);
|
|
if (!*optarg || (e && *e))
|
|
{
|
|
Error("invalid argument to -%c: \"%s\"\n", c, optarg);
|
|
errorcnt++;
|
|
}
|
|
break;
|
|
case 'b':
|
|
case 's':
|
|
case 't':
|
|
case 'u':
|
|
case 'l':
|
|
case 'S':
|
|
case 'T':
|
|
case 'P':
|
|
case 'A':
|
|
params.single_item = c;
|
|
break;
|
|
|
|
case 'd':
|
|
params.debug = 1;
|
|
break;
|
|
|
|
case 'h':
|
|
Usage();
|
|
return CGPT_OK;
|
|
case '?':
|
|
Error("unrecognized option: -%c\n", optopt);
|
|
errorcnt++;
|
|
break;
|
|
case ':':
|
|
Error("missing argument to -%c\n", optopt);
|
|
errorcnt++;
|
|
break;
|
|
default:
|
|
errorcnt++;
|
|
break;
|
|
}
|
|
}
|
|
if (errorcnt)
|
|
{
|
|
Usage();
|
|
return CGPT_FAILED;
|
|
}
|
|
|
|
if (optind >= argc) {
|
|
Error("missing drive argument\n");
|
|
Usage();
|
|
return CGPT_FAILED;
|
|
}
|
|
|
|
params.drive_name = argv[optind];
|
|
|
|
return cgpt_show(¶ms);
|
|
}
|