summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2016-04-20 13:05:53 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2016-11-16 23:43:05 +0000
commitd52de47751659d3b632bd11fe9f09033cd5de8b9 (patch)
tree8a844632972b7b52e4201bcf67b31812de7c5265
parent4f99a7d7231ad8a94b94ff0df9fa9ce73441b2bf (diff)
downloadvboot-factory-veyron-6591.B.tar.gz
cgpt: Add cgpt legacy parameter to set primary GPT signature to IGNOREMEfactory-veyron-6591.B
Now that we have support for the IGNOREME signature in cgpt, we need a way to set it on an existing disk. The easiest option is to shoehorn this into the cgpt legacy command, because that's already made to modify GPT header signatures (really, it would be nice to rename it to cgpt signature or something, but let's not break existing uses for now). BRANCH=None BUG=chrome-os-partner:52595 TEST=unit tests Change-Id: If2835fec28a9c39373abd050e2e057f73e5ec700 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/340073 Reviewed-by: Nam Nguyen <namnguyen@google.com> Reviewed-on: https://chromium-review.googlesource.com/411933 Commit-Queue: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org>
-rw-r--r--cgpt/cgpt_legacy.c21
-rw-r--r--cgpt/cmd_legacy.c17
-rw-r--r--host/include/cgpt_params.h8
-rwxr-xr-xtests/run_cgpt_tests.sh344
4 files changed, 234 insertions, 156 deletions
diff --git a/cgpt/cgpt_legacy.c b/cgpt/cgpt_legacy.c
index b7582123..d5df34d5 100644
--- a/cgpt/cgpt_legacy.c
+++ b/cgpt/cgpt_legacy.c
@@ -10,6 +10,7 @@
int CgptLegacy(CgptLegacyParams *params) {
struct drive drive;
+ int gpt_retval;
GptHeader *h1, *h2;
if (params == NULL)
@@ -19,14 +20,32 @@ int CgptLegacy(CgptLegacyParams *params) {
params->drive_size))
return CGPT_FAILED;
+ if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) {
+ Error("GptSanityCheck() returned %d: %s\n",
+ gpt_retval, GptError(gpt_retval));
+ return CGPT_FAILED;
+ }
+
h1 = (GptHeader *)drive.gpt.primary_header;
h2 = (GptHeader *)drive.gpt.secondary_header;
- if (params->efipart) {
+ if (params->mode == CGPT_LEGACY_MODE_EFIPART) {
+ drive.gpt.ignored = MASK_NONE;
memcpy(h1->signature, GPT_HEADER_SIGNATURE, GPT_HEADER_SIGNATURE_SIZE);
memcpy(h2->signature, GPT_HEADER_SIGNATURE, GPT_HEADER_SIGNATURE_SIZE);
RepairEntries(&drive.gpt, MASK_SECONDARY);
drive.gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 |
GPT_MODIFIED_HEADER2);
+ } else if (params->mode == CGPT_LEGACY_MODE_IGNORE_PRIMARY) {
+ if (!(drive.gpt.valid_headers & MASK_SECONDARY) ||
+ !(drive.gpt.valid_entries & MASK_SECONDARY) ||
+ drive.gpt.ignored & MASK_SECONDARY) {
+ Error("Refusing to mark primary GPT ignored unless secondary is valid.");
+ return CGPT_FAILED;
+ }
+ memset(h1, 0, sizeof(*h1));
+ memcpy(h1->signature, GPT_HEADER_SIGNATURE_IGNORED,
+ GPT_HEADER_SIGNATURE_SIZE);
+ drive.gpt.modified |= GPT_MODIFIED_HEADER1;
} else {
memcpy(h1->signature, GPT_HEADER_SIGNATURE2, GPT_HEADER_SIGNATURE_SIZE);
memcpy(h2->signature, GPT_HEADER_SIGNATURE2, GPT_HEADER_SIGNATURE_SIZE);
diff --git a/cgpt/cmd_legacy.c b/cgpt/cmd_legacy.c
index 5fd742cc..e45b305c 100644
--- a/cgpt/cmd_legacy.c
+++ b/cgpt/cmd_legacy.c
@@ -19,6 +19,7 @@ static void Usage(void)
" default 0, meaning partitions and GPT structs are\n"
" both on DRIVE\n"
" -e Switch GPT header signature back to \"EFI PART\"\n"
+ " -p Switch primary GPT header signature to \"IGNOREME\"\n"
"\n", progname);
}
@@ -31,7 +32,7 @@ int cmd_legacy(int argc, char *argv[]) {
int errorcnt = 0;
opterr = 0; // quiet, you
- while ((c=getopt(argc, argv, ":heD:")) != -1)
+ while ((c=getopt(argc, argv, ":hepD:")) != -1)
{
switch (c)
{
@@ -44,9 +45,19 @@ int cmd_legacy(int argc, char *argv[]) {
}
break;
case 'e':
- params.efipart = 1;
+ if (params.mode) {
+ Error("Incompatible flags, pick either -e or -p\n");
+ errorcnt++;
+ }
+ params.mode = CGPT_LEGACY_MODE_EFIPART;
+ break;
+ case 'p':
+ if (params.mode) {
+ Error("Incompatible flags, pick either -e or -p\n");
+ errorcnt++;
+ }
+ params.mode = CGPT_LEGACY_MODE_IGNORE_PRIMARY;
break;
-
case 'h':
Usage();
return CGPT_OK;
diff --git a/host/include/cgpt_params.h b/host/include/cgpt_params.h
index e7ac7327..abbfa142 100644
--- a/host/include/cgpt_params.h
+++ b/host/include/cgpt_params.h
@@ -98,10 +98,16 @@ typedef struct CgptFindParams {
int match_partnum; /* 1-based; 0 means no match */
} CgptFindParams;
+enum {
+ CGPT_LEGACY_MODE_LEGACY = 0,
+ CGPT_LEGACY_MODE_EFIPART,
+ CGPT_LEGACY_MODE_IGNORE_PRIMARY,
+};
+
typedef struct CgptLegacyParams {
char *drive_name;
uint64_t drive_size;
- int efipart;
+ int mode;
} CgptLegacyParams;
#endif // VBOOT_REFERENCE_CGPT_CGPT_PARAMS_H_
diff --git a/tests/run_cgpt_tests.sh b/tests/run_cgpt_tests.sh
index 5176017a..88799ea5 100755
--- a/tests/run_cgpt_tests.sh
+++ b/tests/run_cgpt_tests.sh
@@ -38,8 +38,6 @@ DEV=fake_dev.bin
rm -f ${DEV}
dd if=/dev/zero of=${DEV} conv=notrunc bs=512 count=${NUM_SECTORS} 2>/dev/null
-
-echo "Create a bunch of partitions, using the real GUID types..."
DATA_START=100
DATA_SIZE=20
DATA_LABEL="data stuff"
@@ -78,71 +76,76 @@ RANDOM_NUM=6
$CGPT create $MTD ${DEV}
-$CGPT add $MTD -b ${DATA_START} -s ${DATA_SIZE} -t ${DATA_GUID} \
- -l "${DATA_LABEL}" ${DEV}
-$CGPT add $MTD -b ${KERN_START} -s ${KERN_SIZE} -t ${KERN_GUID} \
- -l "${KERN_LABEL}" ${DEV}
-$CGPT add $MTD -b ${ROOTFS_START} -s ${ROOTFS_SIZE} -t ${ROOTFS_GUID} \
- -l "${ROOTFS_LABEL}" ${DEV}
-$CGPT add $MTD -b ${ESP_START} -s ${ESP_SIZE} -t ${ESP_GUID} \
- -l "${ESP_LABEL}" ${DEV}
-$CGPT add $MTD -b ${FUTURE_START} -s ${FUTURE_SIZE} -t ${FUTURE_GUID} \
- -l "${FUTURE_LABEL}" ${DEV}
-$CGPT add $MTD -b ${RANDOM_START} -s ${RANDOM_SIZE} -t ${RANDOM_GUID} \
- -l "${RANDOM_LABEL}" ${DEV}
-
-
-echo "Extract the start and size of given partitions..."
-
-X=$($CGPT show $MTD -b -i $DATA_NUM ${DEV})
-Y=$($CGPT show $MTD -s -i $DATA_NUM ${DEV})
-[ "$X $Y" = "$DATA_START $DATA_SIZE" ] || error
-
-X=$($CGPT show $MTD -b -i $KERN_NUM ${DEV})
-Y=$($CGPT show $MTD -s -i $KERN_NUM ${DEV})
-[ "$X $Y" = "$KERN_START $KERN_SIZE" ] || error
-
-X=$($CGPT show $MTD -b -i $ROOTFS_NUM ${DEV})
-Y=$($CGPT show $MTD -s -i $ROOTFS_NUM ${DEV})
-[ "$X $Y" = "$ROOTFS_START $ROOTFS_SIZE" ] || error
-
-X=$($CGPT show $MTD -b -i $ESP_NUM ${DEV})
-Y=$($CGPT show $MTD -s -i $ESP_NUM ${DEV})
-[ "$X $Y" = "$ESP_START $ESP_SIZE" ] || error
-
-X=$($CGPT show $MTD -b -i $FUTURE_NUM ${DEV})
-Y=$($CGPT show $MTD -s -i $FUTURE_NUM ${DEV})
-[ "$X $Y" = "$FUTURE_START $FUTURE_SIZE" ] || error
-
-X=$($CGPT show $MTD -b -i $RANDOM_NUM ${DEV})
-Y=$($CGPT show $MTD -s -i $RANDOM_NUM ${DEV})
-[ "$X $Y" = "$RANDOM_START $RANDOM_SIZE" ] || error
-
-
-echo "Change the beginning..."
-DATA_START=$((DATA_START + 10))
-$CGPT add $MTD -i 1 -b ${DATA_START} ${DEV} || error
-X=$($CGPT show $MTD -b -i 1 ${DEV})
-[ "$X" = "$DATA_START" ] || error
-
-echo "Change the size..."
-DATA_SIZE=$((DATA_SIZE + 10))
-$CGPT add $MTD -i 1 -s ${DATA_SIZE} ${DEV} || error
-X=$($CGPT show $MTD -s -i 1 ${DEV})
-[ "$X" = "$DATA_SIZE" ] || error
-
-echo "Change the type..."
-$CGPT add $MTD -i 1 -t reserved ${DEV} || error
-X=$($CGPT show $MTD -t -i 1 ${DEV} | tr 'A-Z' 'a-z')
-[ "$X" = "$FUTURE_GUID" ] || error
-# arbitrary value
-$CGPT add $MTD -i 1 -t 610a563a-a55c-4ae0-ab07-86e5bb9db67f ${DEV} || error
-X=$($CGPT show $MTD -t -i 1 ${DEV})
-[ "$X" = "610A563A-A55C-4AE0-AB07-86E5BB9DB67F" ] || error
-
-$CGPT add $MTD -i 1 -t data ${DEV} || error
-X=$($CGPT show $MTD -t -i 1 ${DEV} | tr 'A-Z' 'a-z')
-[ "$X" = "$DATA_GUID" ] || error
+run_basic_tests() {
+ echo "Create a bunch of partitions, using the real GUID types..."
+
+ $CGPT add $MTD -b ${DATA_START} -s ${DATA_SIZE} -t ${DATA_GUID} \
+ -l "${DATA_LABEL}" ${DEV}
+ $CGPT add $MTD -b ${KERN_START} -s ${KERN_SIZE} -t ${KERN_GUID} \
+ -l "${KERN_LABEL}" ${DEV}
+ $CGPT add $MTD -b ${ROOTFS_START} -s ${ROOTFS_SIZE} -t ${ROOTFS_GUID} \
+ -l "${ROOTFS_LABEL}" ${DEV}
+ $CGPT add $MTD -b ${ESP_START} -s ${ESP_SIZE} -t ${ESP_GUID} \
+ -l "${ESP_LABEL}" ${DEV}
+ $CGPT add $MTD -b ${FUTURE_START} -s ${FUTURE_SIZE} -t ${FUTURE_GUID} \
+ -l "${FUTURE_LABEL}" ${DEV}
+ $CGPT add $MTD -b ${RANDOM_START} -s ${RANDOM_SIZE} -t ${RANDOM_GUID} \
+ -l "${RANDOM_LABEL}" ${DEV}
+
+
+ echo "Extract the start and size of given partitions..."
+
+ X=$($CGPT show $MTD -b -i $DATA_NUM ${DEV})
+ Y=$($CGPT show $MTD -s -i $DATA_NUM ${DEV})
+ [ "$X $Y" = "$DATA_START $DATA_SIZE" ] || error
+
+ X=$($CGPT show $MTD -b -i $KERN_NUM ${DEV})
+ Y=$($CGPT show $MTD -s -i $KERN_NUM ${DEV})
+ [ "$X $Y" = "$KERN_START $KERN_SIZE" ] || error
+
+ X=$($CGPT show $MTD -b -i $ROOTFS_NUM ${DEV})
+ Y=$($CGPT show $MTD -s -i $ROOTFS_NUM ${DEV})
+ [ "$X $Y" = "$ROOTFS_START $ROOTFS_SIZE" ] || error
+
+ X=$($CGPT show $MTD -b -i $ESP_NUM ${DEV})
+ Y=$($CGPT show $MTD -s -i $ESP_NUM ${DEV})
+ [ "$X $Y" = "$ESP_START $ESP_SIZE" ] || error
+
+ X=$($CGPT show $MTD -b -i $FUTURE_NUM ${DEV})
+ Y=$($CGPT show $MTD -s -i $FUTURE_NUM ${DEV})
+ [ "$X $Y" = "$FUTURE_START $FUTURE_SIZE" ] || error
+
+ X=$($CGPT show $MTD -b -i $RANDOM_NUM ${DEV})
+ Y=$($CGPT show $MTD -s -i $RANDOM_NUM ${DEV})
+ [ "$X $Y" = "$RANDOM_START $RANDOM_SIZE" ] || error
+
+
+ echo "Change the beginning..."
+ DATA_START=$((DATA_START + 10))
+ $CGPT add $MTD -i 1 -b ${DATA_START} ${DEV} || error
+ X=$($CGPT show $MTD -b -i 1 ${DEV})
+ [ "$X" = "$DATA_START" ] || error
+
+ echo "Change the size..."
+ DATA_SIZE=$((DATA_SIZE + 10))
+ $CGPT add $MTD -i 1 -s ${DATA_SIZE} ${DEV} || error
+ X=$($CGPT show $MTD -s -i 1 ${DEV})
+ [ "$X" = "$DATA_SIZE" ] || error
+
+ echo "Change the type..."
+ $CGPT add $MTD -i 1 -t reserved ${DEV} || error
+ X=$($CGPT show $MTD -t -i 1 ${DEV} | tr 'A-Z' 'a-z')
+ [ "$X" = "$FUTURE_GUID" ] || error
+ # arbitrary value
+ $CGPT add $MTD -i 1 -t 610a563a-a55c-4ae0-ab07-86e5bb9db67f ${DEV} || error
+ X=$($CGPT show $MTD -t -i 1 ${DEV})
+ [ "$X" = "610A563A-A55C-4AE0-AB07-86E5BB9DB67F" ] || error
+
+ $CGPT add $MTD -i 1 -t data ${DEV} || error
+ X=$($CGPT show $MTD -t -i 1 ${DEV} | tr 'A-Z' 'a-z')
+ [ "$X" = "$DATA_GUID" ] || error
+}
+run_basic_tests
echo "Set the boot partition.."
@@ -153,8 +156,6 @@ X=$($CGPT boot $MTD ${DEV})
Y=$($CGPT show $MTD -u -i $KERN_NUM $DEV)
[ "$X" = "$Y" ] || error
-echo "Test the cgpt prioritize command..."
-
# Input: sequence of priorities
# Output: ${DEV} has kernel partitions with the given priorities
make_pri() {
@@ -186,88 +187,129 @@ assert_pri() {
# no kernels at all. This should do nothing.
$CGPT create $MTD ${DEV}
-$CGPT add $MTD -t rootfs -b 100 -s 1 ${DEV}
-$CGPT prioritize $MTD ${DEV}
-assert_pri ""
-
-# common install/upgrade sequence
-make_pri 2 0 0
-$CGPT prioritize $MTD -i 1 ${DEV}
-assert_pri 1 0 0
-$CGPT prioritize $MTD -i 2 ${DEV}
-assert_pri 1 2 0
-$CGPT prioritize $MTD -i 1 ${DEV}
-assert_pri 2 1 0
-$CGPT prioritize $MTD -i 2 ${DEV}
-assert_pri 1 2 0
-# lots of kernels, all same starting priority, should go to priority 1
-make_pri 8 8 8 8 8 8 8 8 8 8 8 0 0 8
-$CGPT prioritize $MTD ${DEV}
-assert_pri 1 1 1 1 1 1 1 1 1 1 1 0 0 1
-
-# now raise them all up again
-$CGPT prioritize $MTD -P 4 ${DEV}
-assert_pri 4 4 4 4 4 4 4 4 4 4 4 0 0 4
-
-# set one of them higher, should leave the rest alone
-$CGPT prioritize $MTD -P 5 -i 3 ${DEV}
-assert_pri 4 4 5 4 4 4 4 4 4 4 4 0 0 4
-
-# set one of them lower, should bring the rest down
-$CGPT prioritize $MTD -P 3 -i 4 ${DEV}
-assert_pri 1 1 2 3 1 1 1 1 1 1 1 0 0 1
-
-# raise a group by including the friends of one partition
-$CGPT prioritize $MTD -P 6 -i 1 -f ${DEV}
-assert_pri 6 6 4 5 6 6 6 6 6 6 6 0 0 6
-
-# resurrect one, should not affect the others
-make_pri 0 0 0 0 0 0 0 0 0 0 0 0 0 0
-$CGPT prioritize $MTD -i 2 ${DEV}
-assert_pri 0 1 0 0 0 0 0 0 0 0 0 0 0 0
-
-# resurrect one and all its friends
-make_pri 0 0 0 0 0 0 0 0 1 2 0 0 0 0
-$CGPT prioritize $MTD -P 5 -i 2 -f ${DEV}
-assert_pri 5 5 5 5 5 5 5 5 3 4 5 5 5 5
-
-# no options should maintain the same order
-$CGPT prioritize $MTD ${DEV}
-assert_pri 3 3 3 3 3 3 3 3 1 2 3 3 3 3
-
-# squish all the ranks
-make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
-$CGPT prioritize $MTD -P 6 ${DEV}
-assert_pri 1 1 1 1 2 2 3 3 4 4 0 5 6 6
-
-# squish the ranks by not leaving room
-make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
-$CGPT prioritize $MTD -P 7 -i 3 ${DEV}
-assert_pri 1 1 7 1 2 2 3 3 4 4 0 5 6 6
-
-# squish the ranks while bringing the friends along
-make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
-$CGPT prioritize $MTD -P 6 -i 3 -f ${DEV}
-assert_pri 1 1 6 6 1 1 2 2 3 3 0 4 5 5
-
-# squish them pretty hard
-make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
-$CGPT prioritize $MTD -P 2 ${DEV}
-assert_pri 1 1 1 1 1 1 1 1 1 1 0 1 2 2
-
-# squish them really really hard (nobody gets reduced to zero, though)
-make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
-$CGPT prioritize $MTD -P 1 -i 3 ${DEV}
-assert_pri 1 1 1 1 1 1 1 1 1 1 0 1 1 1
-
-make_pri 15 15 14 14 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0
-$CGPT prioritize $MTD -i 3 ${DEV}
-assert_pri 14 14 15 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 1 1 0
-$CGPT prioritize $MTD -i 5 ${DEV}
-assert_pri 13 13 14 12 15 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 1 1 1 1 0
-# but if I bring friends I don't have to squish
-$CGPT prioritize $MTD -i 1 -f ${DEV}
-assert_pri 15 15 13 12 14 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 1 1 1 1 0
+
+run_prioritize_tests() {
+ echo "Test the cgpt prioritize command..."
+ $CGPT add $MTD -t rootfs -b 100 -s 1 ${DEV}
+ $CGPT prioritize $MTD ${DEV}
+ assert_pri ""
+
+ # common install/upgrade sequence
+ make_pri 2 0 0
+ $CGPT prioritize $MTD -i 1 ${DEV}
+ assert_pri 1 0 0
+ $CGPT prioritize $MTD -i 2 ${DEV}
+ assert_pri 1 2 0
+ $CGPT prioritize $MTD -i 1 ${DEV}
+ assert_pri 2 1 0
+ $CGPT prioritize $MTD -i 2 ${DEV}
+ assert_pri 1 2 0
+ # lots of kernels, all same starting priority, should go to priority 1
+ make_pri 8 8 8 8 8 8 8 8 8 8 8 0 0 8
+ $CGPT prioritize $MTD ${DEV}
+ assert_pri 1 1 1 1 1 1 1 1 1 1 1 0 0 1
+
+ # now raise them all up again
+ $CGPT prioritize $MTD -P 4 ${DEV}
+ assert_pri 4 4 4 4 4 4 4 4 4 4 4 0 0 4
+
+ # set one of them higher, should leave the rest alone
+ $CGPT prioritize $MTD -P 5 -i 3 ${DEV}
+ assert_pri 4 4 5 4 4 4 4 4 4 4 4 0 0 4
+
+ # set one of them lower, should bring the rest down
+ $CGPT prioritize $MTD -P 3 -i 4 ${DEV}
+ assert_pri 1 1 2 3 1 1 1 1 1 1 1 0 0 1
+
+ # raise a group by including the friends of one partition
+ $CGPT prioritize $MTD -P 6 -i 1 -f ${DEV}
+ assert_pri 6 6 4 5 6 6 6 6 6 6 6 0 0 6
+
+ # resurrect one, should not affect the others
+ make_pri 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ $CGPT prioritize $MTD -i 2 ${DEV}
+ assert_pri 0 1 0 0 0 0 0 0 0 0 0 0 0 0
+
+ # resurrect one and all its friends
+ make_pri 0 0 0 0 0 0 0 0 1 2 0 0 0 0
+ $CGPT prioritize $MTD -P 5 -i 2 -f ${DEV}
+ assert_pri 5 5 5 5 5 5 5 5 3 4 5 5 5 5
+
+ # no options should maintain the same order
+ $CGPT prioritize $MTD ${DEV}
+ assert_pri 3 3 3 3 3 3 3 3 1 2 3 3 3 3
+
+ # squish all the ranks
+ make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
+ $CGPT prioritize $MTD -P 6 ${DEV}
+ assert_pri 1 1 1 1 2 2 3 3 4 4 0 5 6 6
+
+ # squish the ranks by not leaving room
+ make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
+ $CGPT prioritize $MTD -P 7 -i 3 ${DEV}
+ assert_pri 1 1 7 1 2 2 3 3 4 4 0 5 6 6
+
+ # squish the ranks while bringing the friends along
+ make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
+ $CGPT prioritize $MTD -P 6 -i 3 -f ${DEV}
+ assert_pri 1 1 6 6 1 1 2 2 3 3 0 4 5 5
+
+ # squish them pretty hard
+ make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
+ $CGPT prioritize $MTD -P 2 ${DEV}
+ assert_pri 1 1 1 1 1 1 1 1 1 1 0 1 2 2
+
+ # squish them really really hard (nobody gets reduced to zero, though)
+ make_pri 1 1 2 2 3 3 4 4 5 5 0 6 7 7
+ $CGPT prioritize $MTD -P 1 -i 3 ${DEV}
+ assert_pri 1 1 1 1 1 1 1 1 1 1 0 1 1 1
+
+ make_pri 15 15 14 14 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0
+ $CGPT prioritize $MTD -i 3 ${DEV}
+ assert_pri 14 14 15 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 1 1 0
+ $CGPT prioritize $MTD -i 5 ${DEV}
+ assert_pri 13 13 14 12 15 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 1 1 1 1 0
+ # but if I bring friends I don't have to squish
+ $CGPT prioritize $MTD -i 1 -f ${DEV}
+ assert_pri 15 15 13 12 14 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 1 1 1 1 0
+}
+run_prioritize_tests
+
+echo "Test cgpt repair command"
+$CGPT repair $MTD ${DEV}
+($CGPT show $MTD ${DEV} | grep -q INVALID) && error
+
+# Zero primary header and partition table and try to repair it.
+dd if=/dev/zero of=${DEV} conv=notrunc bs=512 count=33 2>/dev/null
+$CGPT show $MTD ${DEV} | grep -q INVALID
+$CGPT repair $MTD ${DEV}
+($CGPT show $MTD ${DEV} | grep -q INVALID) && error
+
+# Zero secondary header and partition table and try to repair it.
+dd if=/dev/zero of=${DEV} seek=$(($NUM_SECTORS - 33)) conv=notrunc bs=512 count=33 2>/dev/null
+$CGPT show $MTD ${DEV} | grep -q INVALID
+$CGPT repair $MTD ${DEV}
+($CGPT show $MTD ${DEV} | grep -q INVALID) && error
+
+echo "Test with IGNOREME primary GPT..."
+$CGPT create $MTD ${DEV}
+$CGPT legacy $MTD -p ${DEV}
+$CGPT show $MTD ${DEV} | egrep -q "IGNORED.*Pri GPT" 2>/dev/null
+($CGPT show $MTD ${DEV} | grep -q "Pri GPT table" 2>/dev/null) && error
+$CGPT repair $MTD ${DEV} 2>/dev/null
+$CGPT show $MTD ${DEV} | egrep -q "IGNORED.*Pri GPT" 2>/dev/null
+($CGPT show $MTD ${DEV} | grep -q "Pri GPT table" 2>/dev/null) && error
+$CGPT legacy $MTD -e ${DEV} 2>/dev/null
+($CGPT show $MTD ${DEV} | egrep -q "IGNORED.*Pri GPT") && error
+$CGPT show $MTD ${DEV} | grep -q "Pri GPT table"
+
+$CGPT create $MTD ${DEV}
+$CGPT legacy $MTD -p ${DEV}
+run_basic_tests 2>/dev/null
+
+$CGPT create $MTD ${DEV}
+$CGPT legacy $MTD -p ${DEV}
+run_prioritize_tests 2>/dev/null
# Now make sure that we don't need write access if we're just looking.
echo "Test read vs read-write access..."