diff options
author | Bill Richardson <wfrichar@chromium.org> | 2012-08-24 17:52:01 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-08-24 20:43:28 -0700 |
commit | da77e6953c96f9bb52a04dc32b337066144879aa (patch) | |
tree | 4cf0e87afa0909a70ba901a737c07d2acca3f631 | |
parent | 263ffdfdd710a33a2a12ee33179f088292b2864f (diff) | |
download | vboot-da77e6953c96f9bb52a04dc32b337066144879aa.tar.gz |
cgpt: Fix error in modifying size of an existing partition
Modifying the size of an existing partition without modifying the start as
well assumed the start was at block 0. Sometimes it was caught, often it
wasn't.
Fix the error, add a test to catch the problem.
BUG=chrome-os-partner:13090
BRANCH=all
TEST=manual
make && make runtests
Change-Id: I4f5a5031a90a3e78d886ed3573f61305316a3f1f
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/31418
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | cgpt/cgpt_add.c | 4 | ||||
-rwxr-xr-x | tests/run_cgpt_tests.sh | 25 |
2 files changed, 27 insertions, 2 deletions
diff --git a/cgpt/cgpt_add.c b/cgpt/cgpt_add.c index f72b4de5..319754ac 100644 --- a/cgpt/cgpt_add.c +++ b/cgpt/cgpt_add.c @@ -297,7 +297,7 @@ int cgpt_add(CgptAddParams *params) { if (params->set_begin) entry->starting_lba = params->begin; if (params->set_size) - entry->ending_lba = params->begin + params->size - 1; + entry->ending_lba = entry->starting_lba + params->size - 1; if (params->set_type) memcpy(&entry->type, ¶ms->type_guid, sizeof(Guid)); if (params->set_unique) @@ -323,7 +323,7 @@ int cgpt_add(CgptAddParams *params) { if (0 != CheckEntries((GptEntry*)drive.gpt.primary_entries, (GptHeader*)drive.gpt.primary_header)) { memcpy(entry, &backup, sizeof(*entry)); - Error("At least a parameter is not allowed:\n"); + Error("At least one parameter is not allowed:\n"); Error(DumpCgptAddParams(params)); goto bad; } diff --git a/tests/run_cgpt_tests.sh b/tests/run_cgpt_tests.sh index 97f540ce..445070a4 100755 --- a/tests/run_cgpt_tests.sh +++ b/tests/run_cgpt_tests.sh @@ -105,6 +105,31 @@ Y=$($CGPT show -s -i $RANDOM_NUM ${DEV}) [ "$X $Y" = "$RANDOM_START $RANDOM_SIZE" ] || error +echo "Change the beginning..." +DATA_START=$((DATA_START + 10)) +$CGPT add -i 1 -b ${DATA_START} ${DEV} || error +X=$($CGPT show -b -i 1 ${DEV}) +[ "$X" = "$DATA_START" ] || error + +echo "Change the size..." +DATA_SIZE=$((DATA_SIZE + 10)) +$CGPT add -i 1 -s ${DATA_SIZE} ${DEV} || error +X=$($CGPT show -s -i 1 ${DEV}) +[ "$X" = "$DATA_SIZE" ] || error + +echo "Change the type..." +$CGPT add -i 1 -t reserved ${DEV} || error +X=$($CGPT show -t -i 1 ${DEV} | tr 'A-Z' 'a-z') +[ "$X" = "$FUTURE_GUID" ] || error +# arbitrary value +$CGPT add -i 1 -t 610a563a-a55c-4ae0-ab07-86e5bb9db67f ${DEV} || error +X=$($CGPT show -t -i 1 ${DEV}) +[ "$X" = "610A563A-A55C-4AE0-AB07-86E5BB9DB67F" ] || error +$CGPT add -i 1 -t data ${DEV} || error +X=$($CGPT show -t -i 1 ${DEV} | tr 'A-Z' 'a-z') +[ "$X" = "$DATA_GUID" ] || error + + echo "Set the boot partition.." $CGPT boot -i ${KERN_NUM} ${DEV} >/dev/null |