summaryrefslogtreecommitdiff
path: root/cgpt/cgpt.c
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2010-11-29 14:24:51 -0800
committerBill Richardson <wfrichar@chromium.org>2010-11-29 14:24:51 -0800
commit3430b32667937a75c7a3afc83f8f7a601a8187f7 (patch)
treeaf0492bff6b8493080d0ae959baa015434c3e3a7 /cgpt/cgpt.c
parent5f500b19ba0cdc174a47a68e40f939a4ed69861c (diff)
downloadvboot-3430b32667937a75c7a3afc83f8f7a601a8187f7.tar.gz
Add 'prioritize' command to cgpt tool.
This lets us reorder the priority of all the kernel partitions with a single command, instead of a bunch of complicated and error-prone shell script logic. Change-Id: I21d39763ec5a748488d5319a987bcfe7c34ce4d0 BUG=chromium-os:9167 TEST=manual In the chroot, do this: cd ~/trunk/src/platform/vboot_reference make make runtests make clean Everything should pass. Review URL: http://codereview.chromium.org/5352005
Diffstat (limited to 'cgpt/cgpt.c')
-rw-r--r--cgpt/cgpt.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/cgpt/cgpt.c b/cgpt/cgpt.c
index d8604b1f..4c9fc328 100644
--- a/cgpt/cgpt.c
+++ b/cgpt/cgpt.c
@@ -27,18 +27,19 @@ struct {
{"repair", cmd_repair, "Repair damaged GPT headers and tables"},
{"boot", cmd_boot, "Edit the PMBR sector for legacy BIOSes"},
{"find", cmd_find, "Locate a partition by its GUID"},
+ {"prioritize", cmd_prioritize,
+ "Reorder the priority of all kernel partitions"},
};
-
void Usage(void) {
int i;
- printf("Usage: %s COMMAND [OPTIONS] DRIVE\n\n"
+ printf("\nUsage: %s COMMAND [OPTIONS] DRIVE\n\n"
"Supported COMMANDs:\n\n",
progname);
for (i = 0; i < sizeof(cmds)/sizeof(cmds[0]); ++i) {
- printf(" %-10s %s\n", cmds[i].name, cmds[i].comment);
+ printf(" %-15s %s\n", cmds[i].name, cmds[i].comment);
}
printf("\nFor more detailed usage, use %s COMMAND -h\n\n", progname);
}
@@ -47,6 +48,8 @@ void Usage(void) {
int main(int argc, char *argv[]) {
int i;
+ int match_count = 0;
+ int match_index = 0;
progname = strrchr(argv[0], '/');
if (progname)
@@ -64,12 +67,23 @@ int main(int argc, char *argv[]) {
// Find the command to invoke.
for (i = 0; command && i < sizeof(cmds)/sizeof(cmds[0]); ++i) {
+ // exact match?
if (0 == strcmp(cmds[i].name, command)) {
- return cmds[i].fp(argc, argv);
+ match_index = i;
+ match_count = 1;
+ break;
+ }
+ // unique match?
+ else if (0 == strncmp(cmds[i].name, command, strlen(command))) {
+ match_index = i;
+ match_count++;
}
}
- // Couldn't find the command.
+ if (match_count == 1)
+ return cmds[match_index].fp(argc, argv);
+
+ // Couldn't find a single matching command.
Usage();
return CGPT_FAILED;