cmd_repair.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include <getopt.h>
  5. #include <string.h>
  6. #include "cgpt.h"
  7. #include "vboot_host.h"
  8. extern const char* progname;
  9. static void Usage(void)
  10. {
  11. printf("\nUsage: %s repair [OPTIONS] DRIVE\n\n"
  12. "Repair damaged GPT headers and tables.\n\n"
  13. "Options:\n"
  14. " -D NUM Size (in bytes) of the disk where partitions reside\n"
  15. " default 0, meaning partitions and GPT structs are\n"
  16. " both on DRIVE\n"
  17. " -v Verbose\n"
  18. "\n", progname);
  19. }
  20. int cmd_repair(int argc, char *argv[]) {
  21. CgptRepairParams params;
  22. memset(&params, 0, sizeof(params));
  23. int c;
  24. char* e = 0;
  25. int errorcnt = 0;
  26. opterr = 0; // quiet, you
  27. while ((c=getopt(argc, argv, ":hvD:")) != -1)
  28. {
  29. switch (c)
  30. {
  31. case 'D':
  32. params.drive_size = strtoull(optarg, &e, 0);
  33. errorcnt += check_int_parse(c, e);
  34. break;
  35. case 'v':
  36. params.verbose++;
  37. break;
  38. case 'h':
  39. Usage();
  40. return CGPT_OK;
  41. case '?':
  42. Error("unrecognized option: -%c\n", optopt);
  43. errorcnt++;
  44. break;
  45. case ':':
  46. Error("missing argument to -%c\n", optopt);
  47. errorcnt++;
  48. break;
  49. default:
  50. errorcnt++;
  51. break;
  52. }
  53. }
  54. if (errorcnt)
  55. {
  56. Usage();
  57. return CGPT_FAILED;
  58. }
  59. params.drive_name = argv[optind];
  60. return CgptRepair(&params);
  61. }