Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 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 | |
Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 5 | #include <getopt.h> |
| 6 | #include <string.h> |
| 7 | |
Bill Richardson | 0c3ba24 | 2013-03-29 11:09:30 -0700 | [diff] [blame] | 8 | #include "cgpt.h" |
| 9 | #include "vboot_host.h" |
Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 10 | |
Bill Richardson | 4cb5497 | 2014-06-20 14:33:00 -0700 | [diff] [blame] | 11 | extern const char* progname; |
| 12 | |
Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 13 | static void Usage(void) |
| 14 | { |
| 15 | printf("\nUsage: %s legacy [OPTIONS] DRIVE\n\n" |
| 16 | "Switch GPT header signature to \"CHROMEOS\".\n\n" |
| 17 | "Options:\n" |
Nam T. Nguyen | ab89959 | 2014-11-13 19:30:46 -0800 | [diff] [blame] | 18 | " -D NUM Size (in bytes) of the disk where partitions reside\n" |
| 19 | " default 0, meaning partitions and GPT structs are\n" |
| 20 | " both on DRIVE\n" |
Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 21 | " -e Switch GPT header signature back to \"EFI PART\"\n" |
| 22 | "\n", progname); |
| 23 | } |
| 24 | |
| 25 | int cmd_legacy(int argc, char *argv[]) { |
| 26 | CgptLegacyParams params; |
| 27 | memset(¶ms, 0, sizeof(params)); |
| 28 | |
| 29 | int c; |
Nam T. Nguyen | ab89959 | 2014-11-13 19:30:46 -0800 | [diff] [blame] | 30 | char* e = 0; |
Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 31 | int errorcnt = 0; |
| 32 | |
| 33 | opterr = 0; // quiet, you |
Nam T. Nguyen | ab89959 | 2014-11-13 19:30:46 -0800 | [diff] [blame] | 34 | while ((c=getopt(argc, argv, ":heD:")) != -1) |
Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 35 | { |
| 36 | switch (c) |
| 37 | { |
Nam T. Nguyen | ab89959 | 2014-11-13 19:30:46 -0800 | [diff] [blame] | 38 | case 'D': |
| 39 | params.drive_size = strtoull(optarg, &e, 0); |
| 40 | if (!*optarg || (e && *e)) |
| 41 | { |
| 42 | Error("invalid argument to -%c: \"%s\"\n", c, optarg); |
| 43 | errorcnt++; |
| 44 | } |
| 45 | break; |
Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 46 | case 'e': |
| 47 | params.efipart = 1; |
| 48 | break; |
| 49 | |
| 50 | case 'h': |
| 51 | Usage(); |
| 52 | return CGPT_OK; |
| 53 | case '?': |
| 54 | Error("unrecognized option: -%c\n", optopt); |
| 55 | errorcnt++; |
| 56 | break; |
| 57 | case ':': |
| 58 | Error("missing argument to -%c\n", optopt); |
| 59 | errorcnt++; |
| 60 | break; |
| 61 | default: |
| 62 | errorcnt++; |
| 63 | break; |
| 64 | } |
| 65 | } |
| 66 | if (errorcnt) |
| 67 | { |
| 68 | Usage(); |
| 69 | return CGPT_FAILED; |
| 70 | } |
| 71 | |
| 72 | if (optind >= argc) { |
| 73 | Usage(); |
| 74 | return CGPT_FAILED; |
| 75 | } |
| 76 | |
| 77 | params.drive_name = argv[optind]; |
| 78 | |
Bill Richardson | 3f806a2 | 2013-03-20 15:02:34 -0700 | [diff] [blame] | 79 | return CgptLegacy(¶ms); |
Stefan Reinauer | b7b865c | 2012-08-23 15:06:25 -0700 | [diff] [blame] | 80 | } |