diff options
Diffstat (limited to 'cgpt/cmd_edit.c')
-rw-r--r-- | cgpt/cmd_edit.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/cgpt/cmd_edit.c b/cgpt/cmd_edit.c new file mode 100644 index 00000000..4f4290b9 --- /dev/null +++ b/cgpt/cmd_edit.c @@ -0,0 +1,78 @@ +// Copyright 2018 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <getopt.h> + +#include "cgpt.h" +#include "vboot_host.h" + +extern const char* progname; + +static void Usage(void) +{ + printf("\nUsage: %s edit [OPTIONS] DRIVE\n\n" + "Edit a drive's parameters.\n\n" + "Options:\n" + " -u GUID Drive Unique ID\n" + "\n", progname); +} + +int cmd_edit(int argc, char *argv[]) { + + CgptEditParams params; + memset(¶ms, 0, sizeof(params)); + + int c; + int errorcnt = 0; + + opterr = 0; // quiet, you + while ((c=getopt(argc, argv, ":hu:")) != -1) + { + switch (c) + { + case 'u': + params.set_unique = 1; + if (CGPT_OK != StrToGuid(optarg, ¶ms.unique_guid)) { + Error("invalid argument to -%c: %s\n", c, optarg); + errorcnt++; + } + break; + case 'h': + Usage(); + return CGPT_OK; + case '?': + Error("unrecognized option: -%c\n", optopt); + errorcnt++; + break; + case ':': + Error("missing argument to -%c\n", optopt); + errorcnt++; + break; + default: + errorcnt++; + break; + } + } + if (errorcnt) + { + Usage(); + return CGPT_FAILED; + } + + if (optind >= argc) + { + Error("missing drive argument\n"); + return CGPT_FAILED; + } + + params.drive_name = argv[optind]; + + if (!params.set_unique) + { + Error("no parameters were edited\n"); + return CGPT_FAILED; + } + + return CgptEdit(¶ms); +} |