cmd_show.c 2.8 KB

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