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>
This commit is contained in:
Bill Richardson
2012-08-24 17:52:01 -07:00
committed by Gerrit
parent 263ffdfdd7
commit da77e6953c
2 changed files with 27 additions and 2 deletions

View File

@@ -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, &params->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;
}

View File

@@ -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