| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <getopt.h> |
| 7 |
#include <string.h> |
| 8 |
|
| 9 |
#include "cgpt.h" |
| 10 |
#include "vboot_host.h" |
| 11 |
|
| 12 |
extern const char* progname; |
| 13 |
|
| 14 |
static void Usage(void) |
| 15 |
{ |
| 16 |
printf("\nUsage: %s legacy [OPTIONS] DRIVE\n\n" |
| 17 |
"Switch GPT header signature to \"CHROMEOS\".\n\n" |
| 18 |
"Options:\n" |
| 19 |
" -D NUM Size (in bytes) of the disk where partitions reside;\n" |
| 20 |
" default 0, meaning partitions and GPT structs are\n" |
| 21 |
" both on DRIVE\n" |
| 22 |
" -e Switch GPT header signature back to \"EFI PART\"\n" |
| 23 |
" -p Switch primary GPT header signature to \"IGNOREME\"\n" |
| 24 |
"\n", progname); |
| 25 |
} |
| 26 |
|
| 27 |
int cmd_legacy(int argc, char *argv[]) { |
| 28 |
CgptLegacyParams params; |
| 29 |
memset(¶ms, 0, sizeof(params)); |
| 30 |
|
| 31 |
int c; |
| 32 |
char* e = 0; |
| 33 |
int errorcnt = 0; |
| 34 |
|
| 35 |
opterr = 0; |
| 36 |
while ((c=getopt(argc, argv, ":hepD:")) != -1) |
| 37 |
{ |
| 38 |
switch (c) |
| 39 |
{ |
| 40 |
case 'D': |
| 41 |
params.drive_size = strtoull(optarg, &e, 0); |
| 42 |
errorcnt += check_int_parse(c, e); |
| 43 |
break; |
| 44 |
case 'e': |
| 45 |
if (params.mode) { |
| 46 |
Error("Incompatible flags, pick either -e or -p\n"); |
| 47 |
errorcnt++; |
| 48 |
} |
| 49 |
params.mode = CGPT_LEGACY_MODE_EFIPART; |
| 50 |
break; |
| 51 |
case 'p': |
| 52 |
if (params.mode) { |
| 53 |
Error("Incompatible flags, pick either -e or -p\n"); |
| 54 |
errorcnt++; |
| 55 |
} |
| 56 |
params.mode = CGPT_LEGACY_MODE_IGNORE_PRIMARY; |
| 57 |
break; |
| 58 |
case 'h': |
| 59 |
Usage(); |
| 60 |
return CGPT_OK; |
| 61 |
case '?': |
| 62 |
Error("unrecognized option: -%c\n", optopt); |
| 63 |
errorcnt++; |
| 64 |
break; |
| 65 |
case ':': |
| 66 |
Error("missing argument to -%c\n", optopt); |
| 67 |
errorcnt++; |
| 68 |
break; |
| 69 |
default: |
| 70 |
errorcnt++; |
| 71 |
break; |
| 72 |
} |
| 73 |
} |
| 74 |
if (errorcnt) |
| 75 |
{ |
| 76 |
Usage(); |
| 77 |
return CGPT_FAILED; |
| 78 |
} |
| 79 |
|
| 80 |
if (optind >= argc) { |
| 81 |
Usage(); |
| 82 |
return CGPT_FAILED; |
| 83 |
} |
| 84 |
|
| 85 |
params.drive_name = argv[optind]; |
| 86 |
|
| 87 |
return CgptLegacy(¶ms); |
| 88 |
} |