From a22ce61eda75ec3a394e32f5c1eff27f1b2ff224 Mon Sep 17 00:00:00 2001 From: Matt Delco Date: Fri, 25 Jan 2019 11:34:25 -0800 Subject: cgpt: add -D support to CgptEdit The lack of -D support in CgptEdit introduced a test failure. This change adds support for -D. BRANCH=none BUG=chromium:605348 TEST=Verified that prior to this change the tests failed: cros_workon --host start vboot_reference sudo FEATURES=test emerge vboot_reference The tests fail in a different area prior to CgptEdit, so I applied the following temporary change to Makefile to see the relevant failure: ifeq (${MINIMAL},) # Bitmap utility isn't compiled for minimal variant - test_targets:: runbmptests runfutiltests + test_targets:: runbmptests # runfutiltests # Scripts don't work under qemu testing With this change the tests pass. Change-Id: Ia2127a3537c72e4ea6daf59c5c33b8701a89b0f6 Signed-off-by: Matt Delco Reviewed-on: https://chromium-review.googlesource.com/1436496 Tested-by: Matt Delco Reviewed-by: Julius Werner --- cgpt/cgpt_edit.c | 3 ++- cgpt/cmd_edit.c | 10 +++++++++- host/include/cgpt_params.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cgpt/cgpt_edit.c b/cgpt/cgpt_edit.c index 622819b7..c7781ffc 100644 --- a/cgpt/cgpt_edit.c +++ b/cgpt/cgpt_edit.c @@ -15,7 +15,8 @@ int CgptEdit(CgptEditParams *params) { if (params == NULL) return CGPT_FAILED; - if (CGPT_OK != DriveOpen(params->drive_name, &drive, O_RDWR, 0)) + if (CGPT_OK != DriveOpen(params->drive_name, &drive, O_RDWR, + params->drive_size)) return CGPT_FAILED; if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) { diff --git a/cgpt/cmd_edit.c b/cgpt/cmd_edit.c index 4f4290b9..fb4d9192 100644 --- a/cgpt/cmd_edit.c +++ b/cgpt/cmd_edit.c @@ -14,6 +14,9 @@ static void Usage(void) printf("\nUsage: %s edit [OPTIONS] DRIVE\n\n" "Edit a drive's parameters.\n\n" "Options:\n" + " -D NUM Size (in bytes) of the disk where partitions reside\n" + " default 0, meaning partitions and GPT structs are\n" + " both on DRIVE\n" " -u GUID Drive Unique ID\n" "\n", progname); } @@ -25,12 +28,17 @@ int cmd_edit(int argc, char *argv[]) { int c; int errorcnt = 0; + char *e = 0; opterr = 0; // quiet, you - while ((c=getopt(argc, argv, ":hu:")) != -1) + while ((c=getopt(argc, argv, ":hu:D:")) != -1) { switch (c) { + case 'D': + params.drive_size = strtoull(optarg, &e, 0); + errorcnt += check_int_parse(c, e); + break; case 'u': params.set_unique = 1; if (CGPT_OK != StrToGuid(optarg, ¶ms.unique_guid)) { diff --git a/host/include/cgpt_params.h b/host/include/cgpt_params.h index ffd071a2..8e8bfa6c 100644 --- a/host/include/cgpt_params.h +++ b/host/include/cgpt_params.h @@ -55,6 +55,7 @@ typedef struct CgptAddParams { typedef struct CgptEditParams { char *drive_name; + uint64_t drive_size; Guid unique_guid; int set_unique; } CgptEditParams; -- cgit v1.2.1