blob: d8604b1f0cd5dd34bcc30ce8104e9cbfefc54ed8 [file] [log] [blame]
Bill Richardsonf1372d92010-06-11 09:15:55 -07001/* 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
16const char* progname;
17const char* command;
18
19struct {
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"},
Bill Richardson4a209312010-07-02 11:34:38 -070029 {"find", cmd_find, "Locate a partition by its GUID"},
Bill Richardsonf1372d92010-06-11 09:15:55 -070030};
31
32
33void Usage(void) {
34 int i;
35
36 printf("Usage: %s COMMAND [OPTIONS] DRIVE\n\n"
37 "Supported COMMANDs:\n\n",
38 progname);
39
40 for (i = 0; i < sizeof(cmds)/sizeof(cmds[0]); ++i) {
41 printf(" %-10s %s\n", cmds[i].name, cmds[i].comment);
42 }
43 printf("\nFor more detailed usage, use %s COMMAND -h\n\n", progname);
44}
45
46
47
48int main(int argc, char *argv[]) {
49 int i;
50
51 progname = strrchr(argv[0], '/');
52 if (progname)
53 progname++;
54 else
55 progname = argv[0];
56
57 if (argc < 2) {
58 Usage();
59 return CGPT_FAILED;
60 }
61
62 // increment optind now, so that getopt skips argv[0] in command function
63 command = argv[optind++];
64
65 // Find the command to invoke.
66 for (i = 0; command && i < sizeof(cmds)/sizeof(cmds[0]); ++i) {
67 if (0 == strcmp(cmds[i].name, command)) {
68 return cmds[i].fp(argc, argv);
69 }
70 }
71
72 // Couldn't find the command.
73 Usage();
74
75 return CGPT_FAILED;
76}