• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #include <getopt.h>
6 #include <string.h>
7 
8 #include "cgpt.h"
9 #include "vboot_host.h"
10 
11 extern const char* progname;
12 
Usage(void)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"
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"
21          "  -e           Switch GPT header signature back to \"EFI PART\"\n"
22          "\n", progname);
23 }
24 
cmd_legacy(int argc,char * argv[])25 int cmd_legacy(int argc, char *argv[]) {
26   CgptLegacyParams params;
27   memset(&params, 0, sizeof(params));
28 
29   int c;
30   char* e = 0;
31   int errorcnt = 0;
32 
33   opterr = 0;                     // quiet, you
34   while ((c=getopt(argc, argv, ":heD:")) != -1)
35   {
36     switch (c)
37     {
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;
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 
79   return CgptLegacy(&params);
80 }
81