blob: 5fd742cc9f60dfd2aa7451886e5fce2acf363723 [file] [log] [blame]
Stefan Reinauerb7b865c2012-08-23 15:06:25 -07001// 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 Reinauerb7b865c2012-08-23 15:06:25 -07005#include <getopt.h>
6#include <string.h>
7
Bill Richardson0c3ba242013-03-29 11:09:30 -07008#include "cgpt.h"
9#include "vboot_host.h"
Stefan Reinauerb7b865c2012-08-23 15:06:25 -070010
Bill Richardson4cb54972014-06-20 14:33:00 -070011extern const char* progname;
12
Stefan Reinauerb7b865c2012-08-23 15:06:25 -070013static 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. Nguyenab899592014-11-13 19:30:46 -080018 " -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 Reinauerb7b865c2012-08-23 15:06:25 -070021 " -e Switch GPT header signature back to \"EFI PART\"\n"
22 "\n", progname);
23}
24
25int cmd_legacy(int argc, char *argv[]) {
26 CgptLegacyParams params;
27 memset(&params, 0, sizeof(params));
28
29 int c;
Nam T. Nguyenab899592014-11-13 19:30:46 -080030 char* e = 0;
Stefan Reinauerb7b865c2012-08-23 15:06:25 -070031 int errorcnt = 0;
32
33 opterr = 0; // quiet, you
Nam T. Nguyenab899592014-11-13 19:30:46 -080034 while ((c=getopt(argc, argv, ":heD:")) != -1)
Stefan Reinauerb7b865c2012-08-23 15:06:25 -070035 {
36 switch (c)
37 {
Nam T. Nguyenab899592014-11-13 19:30:46 -080038 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 Reinauerb7b865c2012-08-23 15:06:25 -070046 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 Richardson3f806a22013-03-20 15:02:34 -070079 return CgptLegacy(&params);
Stefan Reinauerb7b865c2012-08-23 15:06:25 -070080}