cgpt: prioritize: Make sure all headers/entries are valid

The prioritize cmd expected primary gpt header and entries are valid.

Add a validity check to guarantee that.

BUG=b:35585016
TEST=Check on bob, the secondary gpt still valid after these commands:
dd if=/dev/zero of=/dev/mmcblk0 bs=512 count=64
cgpt prioritize /dev/mmcblk0

Change-Id: I853e25211a46fa3ce93cef1e5169b93b0a6430a9
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
Reviewed-on: https://chromium-review.googlesource.com/604814
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Jeffy Chen
2017-02-20 21:26:58 +08:00
committed by chrome-bot
parent ca97b25a33
commit a9dca5c04d
2 changed files with 7 additions and 4 deletions

View File

@@ -138,10 +138,8 @@ static int CgptCheckAddValidity(struct drive *drive) {
return -1;
}
if (((drive->gpt.valid_headers & MASK_BOTH) != MASK_BOTH) ||
((drive->gpt.valid_entries & MASK_BOTH) != MASK_BOTH)) {
Error("one of the GPT header/entries is invalid.\n"
"please run 'cgpt repair' before adding anything.\n");
if (CGPT_OK != CheckValid(drive)) {
Error("please run 'cgpt repair' before adding anything.\n");
return -1;
}

View File

@@ -116,6 +116,11 @@ int CgptPrioritize(CgptPrioritizeParams *params) {
return CGPT_FAILED;
}
if (CGPT_OK != CheckValid(&drive)) {
Error("please run 'cgpt repair' before reordering the priority.\n");
return CGPT_OK;
}
max_part = GetNumberOfEntries(&drive);
if (params->set_partition) {