OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2010 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 * Utility for ChromeOS-specific GPT partitions, Please see corresponding .c |
| 6 * files for more details. |
| 7 */ |
| 8 |
| 9 #include "cgpt.h" |
| 10 |
| 11 #include <stdio.h> |
| 12 #include <string.h> |
| 13 #include <unistd.h> |
| 14 |
| 15 |
| 16 const char* progname; |
| 17 const char* command; |
| 18 |
| 19 struct { |
| 20 const char *name; |
| 21 int (*fp)(int argc, char *argv[]); |
| 22 const char *comment; |
| 23 } cmds[] = { |
| 24 {"create", cmd_create, "Create or reset GPT headers and tables"}, |
| 25 {"add", cmd_add, "Add, edit or remove a partition entry"}, |
| 26 {"show", cmd_show, "Show partition table and entries"}, |
| 27 {"repair", cmd_repair, "Repair damaged GPT headers and tables"}, |
| 28 {"boot", cmd_boot, "Edit the PMBR sector for legacy BIOSes"}, |
| 29 }; |
| 30 |
| 31 |
| 32 void Usage(void) { |
| 33 int i; |
| 34 |
| 35 printf("Usage: %s COMMAND [OPTIONS] DRIVE\n\n" |
| 36 "Supported COMMANDs:\n\n", |
| 37 progname); |
| 38 |
| 39 for (i = 0; i < sizeof(cmds)/sizeof(cmds[0]); ++i) { |
| 40 printf(" %-10s %s\n", cmds[i].name, cmds[i].comment); |
| 41 } |
| 42 printf("\nFor more detailed usage, use %s COMMAND -h\n\n", progname); |
| 43 } |
| 44 |
| 45 |
| 46 |
| 47 int main(int argc, char *argv[]) { |
| 48 int i; |
| 49 |
| 50 progname = strrchr(argv[0], '/'); |
| 51 if (progname) |
| 52 progname++; |
| 53 else |
| 54 progname = argv[0]; |
| 55 |
| 56 if (argc < 2) { |
| 57 Usage(); |
| 58 return CGPT_FAILED; |
| 59 } |
| 60 |
| 61 // increment optind now, so that getopt skips argv[0] in command function |
| 62 command = argv[optind++]; |
| 63 |
| 64 // Find the command to invoke. |
| 65 for (i = 0; command && i < sizeof(cmds)/sizeof(cmds[0]); ++i) { |
| 66 if (0 == strcmp(cmds[i].name, command)) { |
| 67 return cmds[i].fp(argc, argv); |
| 68 } |
| 69 } |
| 70 |
| 71 // Couldn't find the command. |
| 72 Usage(); |
| 73 |
| 74 return CGPT_FAILED; |
| 75 } |
OLD | NEW |