mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-24 10:14:55 +00:00
vboot: GPT interface cleanup
- Rename drive_sectors to streaming_drive_sectors, to contrast with gpt_drive_sectors - Replace stored_on_device field with flags field for future extensibility BUG=chromium:433433 TEST=make runtests BRANCH=none Change-Id: I785a3b735b8eb96f647a334659329db3ee43eb80 Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/234283 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
This commit is contained in:
committed by
chrome-internal-fetch
parent
cfe83a827d
commit
b3d38f5c62
@@ -99,8 +99,8 @@ int CgptBoot(CgptBootParams *params) {
|
|||||||
drive.pmbr.part[0].l_cyl = 0xff;
|
drive.pmbr.part[0].l_cyl = 0xff;
|
||||||
drive.pmbr.part[0].f_lba = htole32(1);
|
drive.pmbr.part[0].f_lba = htole32(1);
|
||||||
uint32_t max = 0xffffffff;
|
uint32_t max = 0xffffffff;
|
||||||
if (drive.gpt.drive_sectors < 0xffffffff)
|
if (drive.gpt.streaming_drive_sectors < 0xffffffff)
|
||||||
max = drive.gpt.drive_sectors - 1;
|
max = drive.gpt.streaming_drive_sectors - 1;
|
||||||
drive.pmbr.part[0].num_sect = htole32(max);
|
drive.pmbr.part[0].num_sect = htole32(max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -150,11 +150,11 @@ static int GptLoad(struct drive *drive, uint32_t sector_bytes) {
|
|||||||
(long long unsigned int)drive->size, drive->gpt.sector_bytes);
|
(long long unsigned int)drive->size, drive->gpt.sector_bytes);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
drive->gpt.drive_sectors = drive->size / drive->gpt.sector_bytes;
|
drive->gpt.streaming_drive_sectors = drive->size / drive->gpt.sector_bytes;
|
||||||
|
|
||||||
/* TODO(namnguyen): Remove this and totally trust gpt_drive_sectors. */
|
/* TODO(namnguyen): Remove this and totally trust gpt_drive_sectors. */
|
||||||
if (drive->gpt.stored_on_device == GPT_STORED_ON_DEVICE) {
|
if (!(drive->gpt.flags & GPT_FLAG_EXTERNAL)) {
|
||||||
drive->gpt.gpt_drive_sectors = drive->gpt.drive_sectors;
|
drive->gpt.gpt_drive_sectors = drive->gpt.streaming_drive_sectors;
|
||||||
} /* Else, we trust gpt.gpt_drive_sectors. */
|
} /* Else, we trust gpt.gpt_drive_sectors. */
|
||||||
|
|
||||||
// Read the data.
|
// Read the data.
|
||||||
@@ -171,9 +171,9 @@ static int GptLoad(struct drive *drive, uint32_t sector_bytes) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
GptHeader* primary_header = (GptHeader*)drive->gpt.primary_header;
|
GptHeader* primary_header = (GptHeader*)drive->gpt.primary_header;
|
||||||
if (CheckHeader(primary_header, 0, drive->gpt.drive_sectors,
|
if (CheckHeader(primary_header, 0, drive->gpt.streaming_drive_sectors,
|
||||||
drive->gpt.gpt_drive_sectors,
|
drive->gpt.gpt_drive_sectors,
|
||||||
drive->gpt.stored_on_device) == 0) {
|
drive->gpt.flags) == 0) {
|
||||||
if (CGPT_OK != Load(drive, &drive->gpt.primary_entries,
|
if (CGPT_OK != Load(drive, &drive->gpt.primary_entries,
|
||||||
primary_header->entries_lba,
|
primary_header->entries_lba,
|
||||||
drive->gpt.sector_bytes, GPT_ENTRIES_SECTORS)) {
|
drive->gpt.sector_bytes, GPT_ENTRIES_SECTORS)) {
|
||||||
@@ -184,9 +184,9 @@ static int GptLoad(struct drive *drive, uint32_t sector_bytes) {
|
|||||||
Warning("Primary GPT header is invalid\n");
|
Warning("Primary GPT header is invalid\n");
|
||||||
}
|
}
|
||||||
GptHeader* secondary_header = (GptHeader*)drive->gpt.secondary_header;
|
GptHeader* secondary_header = (GptHeader*)drive->gpt.secondary_header;
|
||||||
if (CheckHeader(secondary_header, 1, drive->gpt.drive_sectors,
|
if (CheckHeader(secondary_header, 1, drive->gpt.streaming_drive_sectors,
|
||||||
drive->gpt.gpt_drive_sectors,
|
drive->gpt.gpt_drive_sectors,
|
||||||
drive->gpt.stored_on_device) == 0) {
|
drive->gpt.flags) == 0) {
|
||||||
if (CGPT_OK != Load(drive, &drive->gpt.secondary_entries,
|
if (CGPT_OK != Load(drive, &drive->gpt.secondary_entries,
|
||||||
secondary_header->entries_lba,
|
secondary_header->entries_lba,
|
||||||
drive->gpt.sector_bytes, GPT_ENTRIES_SECTORS)) {
|
drive->gpt.sector_bytes, GPT_ENTRIES_SECTORS)) {
|
||||||
@@ -284,7 +284,6 @@ int DriveOpen(const char *drive_path, struct drive *drive, int mode,
|
|||||||
|
|
||||||
// Clear struct for proper error handling.
|
// Clear struct for proper error handling.
|
||||||
memset(drive, 0, sizeof(struct drive));
|
memset(drive, 0, sizeof(struct drive));
|
||||||
drive->gpt.stored_on_device = GPT_STORED_ON_DEVICE;
|
|
||||||
|
|
||||||
drive->fd = open(drive_path, mode | O_LARGEFILE | O_NOFOLLOW);
|
drive->fd = open(drive_path, mode | O_LARGEFILE | O_NOFOLLOW);
|
||||||
if (drive->fd == -1) {
|
if (drive->fd == -1) {
|
||||||
@@ -303,10 +302,10 @@ int DriveOpen(const char *drive_path, struct drive *drive, int mode,
|
|||||||
drive->gpt.gpt_drive_sectors = gpt_drive_size / sector_bytes;
|
drive->gpt.gpt_drive_sectors = gpt_drive_size / sector_bytes;
|
||||||
if (drive_size == 0) {
|
if (drive_size == 0) {
|
||||||
drive->size = gpt_drive_size;
|
drive->size = gpt_drive_size;
|
||||||
drive->gpt.stored_on_device = GPT_STORED_ON_DEVICE;
|
drive->gpt.flags = 0;
|
||||||
} else {
|
} else {
|
||||||
drive->size = drive_size;
|
drive->size = drive_size;
|
||||||
drive->gpt.stored_on_device = GPT_STORED_OFF_DEVICE;
|
drive->gpt.flags = GPT_FLAG_EXTERNAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -46,14 +46,15 @@ static int GptCreate(struct drive *drive, CgptCreateParams *params) {
|
|||||||
h->my_lba = GPT_PMBR_SECTORS; /* The second sector on drive. */
|
h->my_lba = GPT_PMBR_SECTORS; /* The second sector on drive. */
|
||||||
h->alternate_lba = drive->gpt.gpt_drive_sectors - GPT_HEADER_SECTORS;
|
h->alternate_lba = drive->gpt.gpt_drive_sectors - GPT_HEADER_SECTORS;
|
||||||
h->entries_lba = h->my_lba + GPT_HEADER_SECTORS;
|
h->entries_lba = h->my_lba + GPT_HEADER_SECTORS;
|
||||||
if (drive->gpt.stored_on_device == GPT_STORED_ON_DEVICE) {
|
if (!(drive->gpt.flags & GPT_FLAG_EXTERNAL)) {
|
||||||
h->entries_lba += params->padding;
|
h->entries_lba += params->padding;
|
||||||
h->first_usable_lba = h->entries_lba + GPT_ENTRIES_SECTORS;
|
h->first_usable_lba = h->entries_lba + GPT_ENTRIES_SECTORS;
|
||||||
h->last_usable_lba = (drive->gpt.drive_sectors - GPT_HEADER_SECTORS -
|
h->last_usable_lba = (drive->gpt.streaming_drive_sectors -
|
||||||
|
GPT_HEADER_SECTORS -
|
||||||
GPT_ENTRIES_SECTORS - 1);
|
GPT_ENTRIES_SECTORS - 1);
|
||||||
} else {
|
} else {
|
||||||
h->first_usable_lba = params->padding;
|
h->first_usable_lba = params->padding;
|
||||||
h->last_usable_lba = (drive->gpt.drive_sectors - 1);
|
h->last_usable_lba = (drive->gpt.streaming_drive_sectors - 1);
|
||||||
}
|
}
|
||||||
if (CGPT_OK != GenerateGuid(&h->disk_uuid)) {
|
if (CGPT_OK != GenerateGuid(&h->disk_uuid)) {
|
||||||
Error("Unable to generate new GUID.\n");
|
Error("Unable to generate new GUID.\n");
|
||||||
@@ -61,7 +62,7 @@ static int GptCreate(struct drive *drive, CgptCreateParams *params) {
|
|||||||
}
|
}
|
||||||
h->size_of_entry = sizeof(GptEntry);
|
h->size_of_entry = sizeof(GptEntry);
|
||||||
h->number_of_entries = TOTAL_ENTRIES_SIZE / h->size_of_entry;
|
h->number_of_entries = TOTAL_ENTRIES_SIZE / h->size_of_entry;
|
||||||
if (drive->gpt.stored_on_device != GPT_STORED_ON_DEVICE) {
|
if (drive->gpt.flags & GPT_FLAG_EXTERNAL) {
|
||||||
// We might have smaller space for the GPT table. Scale accordingly.
|
// We might have smaller space for the GPT table. Scale accordingly.
|
||||||
size_t half_size_sectors = drive->gpt.gpt_drive_sectors / 2;
|
size_t half_size_sectors = drive->gpt.gpt_drive_sectors / 2;
|
||||||
if (half_size_sectors < GPT_HEADER_SECTORS) {
|
if (half_size_sectors < GPT_HEADER_SECTORS) {
|
||||||
|
|||||||
@@ -57,10 +57,8 @@ enum {
|
|||||||
GPT_UPDATE_ENTRY_BAD = 2,
|
GPT_UPDATE_ENTRY_BAD = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
/* If this bit is 1, the GPT is stored in another from the streaming data */
|
||||||
GPT_STORED_ON_DEVICE = 0, /* The GPT is stored on the same device. */
|
#define GPT_FLAG_EXTERNAL 0x1
|
||||||
GPT_STORED_OFF_DEVICE = 1, /* The GPT is stored on another place. */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A note about stored_on_device and gpt_drive_sectors:
|
* A note about stored_on_device and gpt_drive_sectors:
|
||||||
@@ -88,11 +86,11 @@ typedef struct {
|
|||||||
/* Size of a LBA sector, in bytes */
|
/* Size of a LBA sector, in bytes */
|
||||||
uint32_t sector_bytes;
|
uint32_t sector_bytes;
|
||||||
/* Size of drive (that the partitions are on) in LBA sectors */
|
/* Size of drive (that the partitions are on) in LBA sectors */
|
||||||
uint64_t drive_sectors;
|
uint64_t streaming_drive_sectors;
|
||||||
/* Are the GPT structures stored on the same device */
|
|
||||||
uint8_t stored_on_device;
|
|
||||||
/* Size of the device that holds the GPT structures, 512-byte sectors */
|
/* Size of the device that holds the GPT structures, 512-byte sectors */
|
||||||
uint64_t gpt_drive_sectors;
|
uint64_t gpt_drive_sectors;
|
||||||
|
/* Flags */
|
||||||
|
uint32_t flags;
|
||||||
|
|
||||||
/* Outputs */
|
/* Outputs */
|
||||||
/* Which inputs have been modified? GPT_MODIFIED_* */
|
/* Which inputs have been modified? GPT_MODIFIED_* */
|
||||||
|
|||||||
@@ -20,12 +20,13 @@ int CheckParameters(GptData *gpt)
|
|||||||
return GPT_ERROR_INVALID_SECTOR_SIZE;
|
return GPT_ERROR_INVALID_SECTOR_SIZE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* gpt_drive_sectors should be reasonable. It cannot be unset, and it cannot
|
* gpt_drive_sectors should be reasonable. It cannot be unset, and it
|
||||||
* differ from drive_sectors if the GPT structs are stored on same device.
|
* cannot differ from streaming_drive_sectors if the GPT structs are
|
||||||
|
* stored on same device.
|
||||||
*/
|
*/
|
||||||
if (gpt->gpt_drive_sectors == 0 ||
|
if (gpt->gpt_drive_sectors == 0 ||
|
||||||
(gpt->stored_on_device == GPT_STORED_ON_DEVICE &&
|
(!(gpt->flags & GPT_FLAG_EXTERNAL) &&
|
||||||
gpt->gpt_drive_sectors != gpt->drive_sectors)) {
|
gpt->gpt_drive_sectors != gpt->streaming_drive_sectors)) {
|
||||||
return GPT_ERROR_INVALID_SECTOR_NUMBER;
|
return GPT_ERROR_INVALID_SECTOR_NUMBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,8 +54,9 @@ uint32_t HeaderCrc(GptHeader *h)
|
|||||||
return crc32;
|
return crc32;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
|
int CheckHeader(GptHeader *h, int is_secondary,
|
||||||
uint64_t gpt_drive_sectors, uint8_t stored_on_device)
|
uint64_t streaming_drive_sectors,
|
||||||
|
uint64_t gpt_drive_sectors, uint32_t flags)
|
||||||
{
|
{
|
||||||
if (!h)
|
if (!h)
|
||||||
return 1;
|
return 1;
|
||||||
@@ -91,7 +93,7 @@ int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
|
|||||||
return 1;
|
return 1;
|
||||||
if ((h->number_of_entries < MIN_NUMBER_OF_ENTRIES) ||
|
if ((h->number_of_entries < MIN_NUMBER_OF_ENTRIES) ||
|
||||||
(h->number_of_entries > MAX_NUMBER_OF_ENTRIES) ||
|
(h->number_of_entries > MAX_NUMBER_OF_ENTRIES) ||
|
||||||
(stored_on_device == GPT_STORED_ON_DEVICE &&
|
(!(flags & GPT_FLAG_EXTERNAL) &&
|
||||||
h->number_of_entries * h->size_of_entry != TOTAL_ENTRIES_SIZE))
|
h->number_of_entries * h->size_of_entry != TOTAL_ENTRIES_SIZE))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@@ -116,8 +118,8 @@ int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
|
|||||||
if (h->first_usable_lba > h->last_usable_lba)
|
if (h->first_usable_lba > h->last_usable_lba)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (stored_on_device != GPT_STORED_ON_DEVICE) {
|
if (flags & GPT_FLAG_EXTERNAL) {
|
||||||
if (h->last_usable_lba >= drive_sectors) {
|
if (h->last_usable_lba >= streaming_drive_sectors) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -131,7 +133,8 @@ int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
|
|||||||
/* TODO(namnguyen): Also check for padding between header & entries. */
|
/* TODO(namnguyen): Also check for padding between header & entries. */
|
||||||
if (h->first_usable_lba < 2 + GPT_ENTRIES_SECTORS)
|
if (h->first_usable_lba < 2 + GPT_ENTRIES_SECTORS)
|
||||||
return 1;
|
return 1;
|
||||||
if (h->last_usable_lba >= drive_sectors - 1 - GPT_ENTRIES_SECTORS)
|
if (h->last_usable_lba >=
|
||||||
|
streaming_drive_sectors - 1 - GPT_ENTRIES_SECTORS)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Success */
|
/* Success */
|
||||||
@@ -245,13 +248,13 @@ int GptSanityCheck(GptData *gpt)
|
|||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
/* Check both headers; we need at least one valid header. */
|
/* Check both headers; we need at least one valid header. */
|
||||||
if (0 == CheckHeader(header1, 0, gpt->drive_sectors,
|
if (0 == CheckHeader(header1, 0, gpt->streaming_drive_sectors,
|
||||||
gpt->gpt_drive_sectors, gpt->stored_on_device)) {
|
gpt->gpt_drive_sectors, gpt->flags)) {
|
||||||
gpt->valid_headers |= MASK_PRIMARY;
|
gpt->valid_headers |= MASK_PRIMARY;
|
||||||
goodhdr = header1;
|
goodhdr = header1;
|
||||||
}
|
}
|
||||||
if (0 == CheckHeader(header2, 1, gpt->drive_sectors,
|
if (0 == CheckHeader(header2, 1, gpt->streaming_drive_sectors,
|
||||||
gpt->gpt_drive_sectors, gpt->stored_on_device)) {
|
gpt->gpt_drive_sectors, gpt->flags)) {
|
||||||
gpt->valid_headers |= MASK_SECONDARY;
|
gpt->valid_headers |= MASK_SECONDARY;
|
||||||
if (!goodhdr)
|
if (!goodhdr)
|
||||||
goodhdr = header2;
|
goodhdr = header2;
|
||||||
@@ -332,7 +335,8 @@ void GptRepair(GptData *gpt)
|
|||||||
/* Secondary is good, primary is bad */
|
/* Secondary is good, primary is bad */
|
||||||
Memcpy(header1, header2, sizeof(GptHeader));
|
Memcpy(header1, header2, sizeof(GptHeader));
|
||||||
header1->my_lba = GPT_PMBR_SECTORS; /* Second sector. */
|
header1->my_lba = GPT_PMBR_SECTORS; /* Second sector. */
|
||||||
header1->alternate_lba = gpt->drive_sectors - GPT_HEADER_SECTORS;
|
header1->alternate_lba =
|
||||||
|
gpt->streaming_drive_sectors - GPT_HEADER_SECTORS;
|
||||||
/* TODO (namnguyen): Preserve (header, entries) padding. */
|
/* TODO (namnguyen): Preserve (header, entries) padding. */
|
||||||
header1->entries_lba = header1->my_lba + 1;
|
header1->entries_lba = header1->my_lba + 1;
|
||||||
header1->header_crc32 = HeaderCrc(header1);
|
header1->header_crc32 = HeaderCrc(header1);
|
||||||
|
|||||||
@@ -90,8 +90,9 @@ int CheckParameters(GptData* gpt);
|
|||||||
*
|
*
|
||||||
* Returns 0 if header is valid, 1 if invalid.
|
* Returns 0 if header is valid, 1 if invalid.
|
||||||
*/
|
*/
|
||||||
int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors,
|
int CheckHeader(GptHeader *h, int is_secondary,
|
||||||
uint64_t gpt_drive_sectors, uint8_t stored_on_device);
|
uint64_t streaming_drive_sectors,
|
||||||
|
uint64_t gpt_drive_sectors, uint32_t flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate and return the header CRC.
|
* Calculate and return the header CRC.
|
||||||
|
|||||||
@@ -48,9 +48,10 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
|
|||||||
|
|
||||||
/* Only read primary GPT if the primary header is valid */
|
/* Only read primary GPT if the primary header is valid */
|
||||||
GptHeader* primary_header = (GptHeader*)gptdata->primary_header;
|
GptHeader* primary_header = (GptHeader*)gptdata->primary_header;
|
||||||
if (0 == CheckHeader(primary_header, 0, gptdata->drive_sectors,
|
if (0 == CheckHeader(primary_header, 0,
|
||||||
|
gptdata->streaming_drive_sectors,
|
||||||
gptdata->gpt_drive_sectors,
|
gptdata->gpt_drive_sectors,
|
||||||
gptdata->stored_on_device)) {
|
gptdata->flags)) {
|
||||||
primary_valid = 1;
|
primary_valid = 1;
|
||||||
if (0 != VbExDiskRead(disk_handle,
|
if (0 != VbExDiskRead(disk_handle,
|
||||||
primary_header->entries_lba,
|
primary_header->entries_lba,
|
||||||
@@ -68,9 +69,10 @@ int AllocAndReadGptData(VbExDiskHandle_t disk_handle, GptData *gptdata)
|
|||||||
|
|
||||||
/* Only read secondary GPT if the secondary header is valid */
|
/* Only read secondary GPT if the secondary header is valid */
|
||||||
GptHeader* secondary_header = (GptHeader*)gptdata->secondary_header;
|
GptHeader* secondary_header = (GptHeader*)gptdata->secondary_header;
|
||||||
if (0 == CheckHeader(secondary_header, 1, gptdata->drive_sectors,
|
if (0 == CheckHeader(secondary_header, 1,
|
||||||
|
gptdata->streaming_drive_sectors,
|
||||||
gptdata->gpt_drive_sectors,
|
gptdata->gpt_drive_sectors,
|
||||||
gptdata->stored_on_device)) {
|
gptdata->flags)) {
|
||||||
secondary_valid = 1;
|
secondary_valid = 1;
|
||||||
if (0 != VbExDiskRead(disk_handle,
|
if (0 != VbExDiskRead(disk_handle,
|
||||||
secondary_header->entries_lba,
|
secondary_header->entries_lba,
|
||||||
|
|||||||
@@ -115,10 +115,10 @@ VbError_t LoadKernel(LoadKernelParams *params, VbCommonParams *cparams)
|
|||||||
|
|
||||||
/* Read GPT data */
|
/* Read GPT data */
|
||||||
gpt.sector_bytes = (uint32_t)blba;
|
gpt.sector_bytes = (uint32_t)blba;
|
||||||
gpt.drive_sectors = params->ending_lba + 1;
|
gpt.streaming_drive_sectors = params->ending_lba + 1;
|
||||||
/* TODO: Set stored_on_device and gpt_drive_sectors appropriately */
|
/* TODO: Set stored_on_device and gpt_drive_sectors appropriately */
|
||||||
gpt.stored_on_device = GPT_STORED_ON_DEVICE;
|
gpt.gpt_drive_sectors = gpt.streaming_drive_sectors;
|
||||||
gpt.gpt_drive_sectors = gpt.drive_sectors;
|
gpt.flags = 0;
|
||||||
if (0 != AllocAndReadGptData(params->disk_handle, &gpt)) {
|
if (0 != AllocAndReadGptData(params->disk_handle, &gpt)) {
|
||||||
VBDEBUG(("Unable to read GPT data\n"));
|
VBDEBUG(("Unable to read GPT data\n"));
|
||||||
shcall->check_result = VBSD_LKC_CHECK_GPT_READ_ERROR;
|
shcall->check_result = VBSD_LKC_CHECK_GPT_READ_ERROR;
|
||||||
|
|||||||
@@ -149,7 +149,8 @@ static void BuildTestGptData(GptData *gpt)
|
|||||||
Guid chromeos_rootfs = GPT_ENT_TYPE_CHROMEOS_ROOTFS;
|
Guid chromeos_rootfs = GPT_ENT_TYPE_CHROMEOS_ROOTFS;
|
||||||
|
|
||||||
gpt->sector_bytes = DEFAULT_SECTOR_SIZE;
|
gpt->sector_bytes = DEFAULT_SECTOR_SIZE;
|
||||||
gpt->drive_sectors = gpt->gpt_drive_sectors = DEFAULT_DRIVE_SECTORS;
|
gpt->streaming_drive_sectors =
|
||||||
|
gpt->gpt_drive_sectors = DEFAULT_DRIVE_SECTORS;
|
||||||
gpt->current_kernel = CGPT_KERNEL_ENTRY_NOT_FOUND;
|
gpt->current_kernel = CGPT_KERNEL_ENTRY_NOT_FOUND;
|
||||||
gpt->valid_headers = MASK_BOTH;
|
gpt->valid_headers = MASK_BOTH;
|
||||||
gpt->valid_entries = MASK_BOTH;
|
gpt->valid_entries = MASK_BOTH;
|
||||||
@@ -255,7 +256,8 @@ static int ParameterTests(void)
|
|||||||
for (i = 0; i < ARRAY_SIZE(cases); ++i) {
|
for (i = 0; i < ARRAY_SIZE(cases); ++i) {
|
||||||
BuildTestGptData(gpt);
|
BuildTestGptData(gpt);
|
||||||
gpt->sector_bytes = cases[i].sector_bytes;
|
gpt->sector_bytes = cases[i].sector_bytes;
|
||||||
gpt->drive_sectors = gpt->gpt_drive_sectors = cases[i].drive_sectors;
|
gpt->streaming_drive_sectors =
|
||||||
|
gpt->gpt_drive_sectors = cases[i].drive_sectors;
|
||||||
EXPECT(cases[i].expected_retval == CheckParameters(gpt));
|
EXPECT(cases[i].expected_retval == CheckParameters(gpt));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,15 +352,15 @@ static int SignatureTest(void)
|
|||||||
GptHeader *h2 = (GptHeader *)gpt->secondary_header;
|
GptHeader *h2 = (GptHeader *)gpt->secondary_header;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
EXPECT(1 == CheckHeader(NULL, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(NULL, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
|
|
||||||
for (i = 0; i < 8; ++i) {
|
for (i = 0; i < 8; ++i) {
|
||||||
BuildTestGptData(gpt);
|
BuildTestGptData(gpt);
|
||||||
h1->signature[i] ^= 0xff;
|
h1->signature[i] ^= 0xff;
|
||||||
h2->signature[i] ^= 0xff;
|
h2->signature[i] ^= 0xff;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return TEST_OK;
|
return TEST_OK;
|
||||||
@@ -392,9 +394,9 @@ static int RevisionTest(void)
|
|||||||
h2->revision = cases[i].value_to_test;
|
h2->revision = cases[i].value_to_test;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
|
|
||||||
EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
|
EXPECT(CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
|
||||||
cases[i].expect_rv);
|
cases[i].expect_rv);
|
||||||
EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
|
EXPECT(CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
|
||||||
cases[i].expect_rv);
|
cases[i].expect_rv);
|
||||||
}
|
}
|
||||||
return TEST_OK;
|
return TEST_OK;
|
||||||
@@ -425,9 +427,9 @@ static int SizeTest(void)
|
|||||||
h2->size = cases[i].value_to_test;
|
h2->size = cases[i].value_to_test;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
|
|
||||||
EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
|
EXPECT(CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
|
||||||
cases[i].expect_rv);
|
cases[i].expect_rv);
|
||||||
EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
|
EXPECT(CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
|
||||||
cases[i].expect_rv);
|
cases[i].expect_rv);
|
||||||
}
|
}
|
||||||
return TEST_OK;
|
return TEST_OK;
|
||||||
@@ -444,12 +446,12 @@ static int CrcFieldTest(void)
|
|||||||
/* Modify a field that the header verification doesn't care about */
|
/* Modify a field that the header verification doesn't care about */
|
||||||
h1->entries_crc32++;
|
h1->entries_crc32++;
|
||||||
h2->entries_crc32++;
|
h2->entries_crc32++;
|
||||||
EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
/* Refresh the CRC; should pass now */
|
/* Refresh the CRC; should pass now */
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(0 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(0 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(0 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
|
|
||||||
return TEST_OK;
|
return TEST_OK;
|
||||||
}
|
}
|
||||||
@@ -465,8 +467,8 @@ static int ReservedFieldsTest(void)
|
|||||||
h1->reserved_zero ^= 0x12345678; /* whatever random */
|
h1->reserved_zero ^= 0x12345678; /* whatever random */
|
||||||
h2->reserved_zero ^= 0x12345678; /* whatever random */
|
h2->reserved_zero ^= 0x12345678; /* whatever random */
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
|
|
||||||
#ifdef PADDING_CHECKED
|
#ifdef PADDING_CHECKED
|
||||||
/* TODO: padding check is currently disabled */
|
/* TODO: padding check is currently disabled */
|
||||||
@@ -474,8 +476,8 @@ static int ReservedFieldsTest(void)
|
|||||||
h1->padding[12] ^= 0x34; /* whatever random */
|
h1->padding[12] ^= 0x34; /* whatever random */
|
||||||
h2->padding[56] ^= 0x78; /* whatever random */
|
h2->padding[56] ^= 0x78; /* whatever random */
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return TEST_OK;
|
return TEST_OK;
|
||||||
@@ -513,9 +515,9 @@ static int SizeOfPartitionEntryTest(void) {
|
|||||||
cases[i].value_to_test;
|
cases[i].value_to_test;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
|
|
||||||
EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
|
EXPECT(CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
|
||||||
cases[i].expect_rv);
|
cases[i].expect_rv);
|
||||||
EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
|
EXPECT(CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
|
||||||
cases[i].expect_rv);
|
cases[i].expect_rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,11 +538,11 @@ static int NumberOfPartitionEntriesTest(void)
|
|||||||
h1->number_of_entries--;
|
h1->number_of_entries--;
|
||||||
h2->number_of_entries /= 2;
|
h2->number_of_entries /= 2;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
/* But it's okay to have less if the GPT structs are stored elsewhere. */
|
/* But it's okay to have less if the GPT structs are stored elsewhere. */
|
||||||
EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
|
EXPECT(0 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
|
||||||
EXPECT(0 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
|
EXPECT(0 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
|
||||||
|
|
||||||
return TEST_OK;
|
return TEST_OK;
|
||||||
}
|
}
|
||||||
@@ -555,37 +557,37 @@ static int MyLbaTest(void)
|
|||||||
|
|
||||||
/* myLBA depends on primary vs secondary flag */
|
/* myLBA depends on primary vs secondary flag */
|
||||||
BuildTestGptData(gpt);
|
BuildTestGptData(gpt);
|
||||||
EXPECT(1 == CheckHeader(h1, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h1, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(1 == CheckHeader(h2, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h2, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
|
|
||||||
BuildTestGptData(gpt);
|
BuildTestGptData(gpt);
|
||||||
h1->my_lba--;
|
h1->my_lba--;
|
||||||
h2->my_lba--;
|
h2->my_lba--;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
|
|
||||||
BuildTestGptData(gpt);
|
BuildTestGptData(gpt);
|
||||||
h1->my_lba = 2;
|
h1->my_lba = 2;
|
||||||
h2->my_lba--;
|
h2->my_lba--;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
|
|
||||||
/* We should ignore the alternate_lba field entirely */
|
/* We should ignore the alternate_lba field entirely */
|
||||||
BuildTestGptData(gpt);
|
BuildTestGptData(gpt);
|
||||||
h1->alternate_lba++;
|
h1->alternate_lba++;
|
||||||
h2->alternate_lba++;
|
h2->alternate_lba++;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(0 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(0 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(0 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
|
|
||||||
BuildTestGptData(gpt);
|
BuildTestGptData(gpt);
|
||||||
h1->alternate_lba--;
|
h1->alternate_lba--;
|
||||||
h2->alternate_lba--;
|
h2->alternate_lba--;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(0 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(0 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(0 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
|
|
||||||
BuildTestGptData(gpt);
|
BuildTestGptData(gpt);
|
||||||
h1->entries_lba++;
|
h1->entries_lba++;
|
||||||
@@ -595,19 +597,19 @@ static int MyLbaTest(void)
|
|||||||
* We support a padding between primary GPT header and its entries. So
|
* We support a padding between primary GPT header and its entries. So
|
||||||
* this still passes.
|
* this still passes.
|
||||||
*/
|
*/
|
||||||
EXPECT(0 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(0 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
/*
|
/*
|
||||||
* But the secondary table should fail because it would overlap the
|
* But the secondary table should fail because it would overlap the
|
||||||
* header, which is now lying after its entry array.
|
* header, which is now lying after its entry array.
|
||||||
*/
|
*/
|
||||||
EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
|
|
||||||
BuildTestGptData(gpt);
|
BuildTestGptData(gpt);
|
||||||
h1->entries_lba--;
|
h1->entries_lba--;
|
||||||
h2->entries_lba--;
|
h2->entries_lba--;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
EXPECT(1 == CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0));
|
||||||
|
|
||||||
return TEST_OK;
|
return TEST_OK;
|
||||||
}
|
}
|
||||||
@@ -656,9 +658,9 @@ static int FirstUsableLbaAndLastUsableLbaTest(void)
|
|||||||
h2->last_usable_lba = cases[i].secondary_last_usable_lba;
|
h2->last_usable_lba = cases[i].secondary_last_usable_lba;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
|
|
||||||
EXPECT(CheckHeader(h1, 0, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
|
EXPECT(CheckHeader(h1, 0, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
|
||||||
cases[i].primary_rv);
|
cases[i].primary_rv);
|
||||||
EXPECT(CheckHeader(h2, 1, gpt->drive_sectors, gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE) ==
|
EXPECT(CheckHeader(h2, 1, gpt->streaming_drive_sectors, gpt->gpt_drive_sectors, 0) ==
|
||||||
cases[i].secondary_rv);
|
cases[i].secondary_rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1424,50 +1426,50 @@ static int CheckHeaderOffDevice()
|
|||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
// GPT is stored on the same device so first usable lba should not
|
// GPT is stored on the same device so first usable lba should not
|
||||||
// start at 0.
|
// start at 0.
|
||||||
EXPECT(1 == CheckHeader(primary_header, 0, gpt->drive_sectors,
|
EXPECT(1 == CheckHeader(primary_header, 0, gpt->streaming_drive_sectors,
|
||||||
gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
gpt->gpt_drive_sectors, 0));
|
||||||
// But off device, it is okay to accept this GPT header.
|
// But off device, it is okay to accept this GPT header.
|
||||||
EXPECT(0 == CheckHeader(primary_header, 0, gpt->drive_sectors,
|
EXPECT(0 == CheckHeader(primary_header, 0, gpt->streaming_drive_sectors,
|
||||||
gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
|
gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
|
||||||
|
|
||||||
BuildTestGptData(gpt);
|
BuildTestGptData(gpt);
|
||||||
primary_header->number_of_entries = 100;
|
primary_header->number_of_entries = 100;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
// Normally, number of entries is 128. So this should fail.
|
// Normally, number of entries is 128. So this should fail.
|
||||||
EXPECT(1 == CheckHeader(primary_header, 0, gpt->drive_sectors,
|
EXPECT(1 == CheckHeader(primary_header, 0, gpt->streaming_drive_sectors,
|
||||||
gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
gpt->gpt_drive_sectors, 0));
|
||||||
// But off device, it is okay.
|
// But off device, it is okay.
|
||||||
EXPECT(0 == CheckHeader(primary_header, 0, gpt->drive_sectors,
|
EXPECT(0 == CheckHeader(primary_header, 0, gpt->streaming_drive_sectors,
|
||||||
gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
|
gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
|
||||||
|
|
||||||
primary_header->number_of_entries = MIN_NUMBER_OF_ENTRIES - 1;
|
primary_header->number_of_entries = MIN_NUMBER_OF_ENTRIES - 1;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
// However, too few entries is not good.
|
// However, too few entries is not good.
|
||||||
EXPECT(1 == CheckHeader(primary_header, 0, gpt->drive_sectors,
|
EXPECT(1 == CheckHeader(primary_header, 0, gpt->streaming_drive_sectors,
|
||||||
gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
|
gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
|
||||||
|
|
||||||
// Repeat for secondary header.
|
// Repeat for secondary header.
|
||||||
BuildTestGptData(gpt);
|
BuildTestGptData(gpt);
|
||||||
GptHeader* secondary_header = (GptHeader*)gpt->secondary_header;
|
GptHeader* secondary_header = (GptHeader*)gpt->secondary_header;
|
||||||
secondary_header->first_usable_lba = 0;
|
secondary_header->first_usable_lba = 0;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
EXPECT(1 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
|
EXPECT(1 == CheckHeader(secondary_header, 1, gpt->streaming_drive_sectors,
|
||||||
gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(0 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
|
EXPECT(0 == CheckHeader(secondary_header, 1, gpt->streaming_drive_sectors,
|
||||||
gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
|
gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
|
||||||
|
|
||||||
BuildTestGptData(gpt);
|
BuildTestGptData(gpt);
|
||||||
secondary_header->number_of_entries = 100;
|
secondary_header->number_of_entries = 100;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
EXPECT(1 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
|
EXPECT(1 == CheckHeader(secondary_header, 1, gpt->streaming_drive_sectors,
|
||||||
gpt->gpt_drive_sectors, GPT_STORED_ON_DEVICE));
|
gpt->gpt_drive_sectors, 0));
|
||||||
EXPECT(0 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
|
EXPECT(0 == CheckHeader(secondary_header, 1, gpt->streaming_drive_sectors,
|
||||||
gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
|
gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
|
||||||
|
|
||||||
secondary_header->number_of_entries = MIN_NUMBER_OF_ENTRIES - 1;
|
secondary_header->number_of_entries = MIN_NUMBER_OF_ENTRIES - 1;
|
||||||
RefreshCrc32(gpt);
|
RefreshCrc32(gpt);
|
||||||
EXPECT(1 == CheckHeader(secondary_header, 1, gpt->drive_sectors,
|
EXPECT(1 == CheckHeader(secondary_header, 1, gpt->streaming_drive_sectors,
|
||||||
gpt->gpt_drive_sectors, GPT_STORED_OFF_DEVICE));
|
gpt->gpt_drive_sectors, GPT_FLAG_EXTERNAL));
|
||||||
|
|
||||||
return TEST_OK;
|
return TEST_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ static void ReadWriteGptTest(void)
|
|||||||
GptHeader *h;
|
GptHeader *h;
|
||||||
|
|
||||||
g.sector_bytes = MOCK_SECTOR_SIZE;
|
g.sector_bytes = MOCK_SECTOR_SIZE;
|
||||||
g.drive_sectors = g.gpt_drive_sectors = MOCK_SECTOR_COUNT;
|
g.streaming_drive_sectors = g.gpt_drive_sectors = MOCK_SECTOR_COUNT;
|
||||||
g.valid_headers = g.valid_entries = MASK_BOTH;
|
g.valid_headers = g.valid_entries = MASK_BOTH;
|
||||||
|
|
||||||
ResetMocks();
|
ResetMocks();
|
||||||
@@ -315,11 +315,11 @@ static void ReadWriteGptTest(void)
|
|||||||
Memset(mock_gpt_primary, '\0', sizeof(*mock_gpt_primary));
|
Memset(mock_gpt_primary, '\0', sizeof(*mock_gpt_primary));
|
||||||
TEST_EQ(AllocAndReadGptData(handle, &g), 0,
|
TEST_EQ(AllocAndReadGptData(handle, &g), 0,
|
||||||
"AllocAndRead primary invalid");
|
"AllocAndRead primary invalid");
|
||||||
TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.drive_sectors,
|
TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.streaming_drive_sectors,
|
||||||
g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
|
g.gpt_drive_sectors, 0),
|
||||||
1, "Primary header is invalid");
|
1, "Primary header is invalid");
|
||||||
TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.drive_sectors,
|
TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.streaming_drive_sectors,
|
||||||
g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
|
g.gpt_drive_sectors, 0),
|
||||||
0, "Secondary header is valid");
|
0, "Secondary header is valid");
|
||||||
TEST_CALLS("VbExDiskRead(h, 1, 1)\n"
|
TEST_CALLS("VbExDiskRead(h, 1, 1)\n"
|
||||||
"VbExDiskRead(h, 1023, 1)\n"
|
"VbExDiskRead(h, 1023, 1)\n"
|
||||||
@@ -334,11 +334,11 @@ static void ReadWriteGptTest(void)
|
|||||||
Memset(mock_gpt_secondary, '\0', sizeof(*mock_gpt_secondary));
|
Memset(mock_gpt_secondary, '\0', sizeof(*mock_gpt_secondary));
|
||||||
TEST_EQ(AllocAndReadGptData(handle, &g), 0,
|
TEST_EQ(AllocAndReadGptData(handle, &g), 0,
|
||||||
"AllocAndRead secondary invalid");
|
"AllocAndRead secondary invalid");
|
||||||
TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.drive_sectors,
|
TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.streaming_drive_sectors,
|
||||||
g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
|
g.gpt_drive_sectors, 0),
|
||||||
0, "Primary header is valid");
|
0, "Primary header is valid");
|
||||||
TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.drive_sectors,
|
TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.streaming_drive_sectors,
|
||||||
g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
|
g.gpt_drive_sectors, 0),
|
||||||
1, "Secondary header is invalid");
|
1, "Secondary header is invalid");
|
||||||
TEST_CALLS("VbExDiskRead(h, 1, 1)\n"
|
TEST_CALLS("VbExDiskRead(h, 1, 1)\n"
|
||||||
"VbExDiskRead(h, 2, 32)\n"
|
"VbExDiskRead(h, 2, 32)\n"
|
||||||
@@ -354,11 +354,11 @@ static void ReadWriteGptTest(void)
|
|||||||
Memset(mock_gpt_secondary, '\0', sizeof(*mock_gpt_secondary));
|
Memset(mock_gpt_secondary, '\0', sizeof(*mock_gpt_secondary));
|
||||||
TEST_EQ(AllocAndReadGptData(handle, &g), 1,
|
TEST_EQ(AllocAndReadGptData(handle, &g), 1,
|
||||||
"AllocAndRead primary and secondary invalid");
|
"AllocAndRead primary and secondary invalid");
|
||||||
TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.drive_sectors,
|
TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.streaming_drive_sectors,
|
||||||
g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
|
g.gpt_drive_sectors, 0),
|
||||||
1, "Primary header is invalid");
|
1, "Primary header is invalid");
|
||||||
TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.drive_sectors,
|
TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.streaming_drive_sectors,
|
||||||
g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
|
g.gpt_drive_sectors, 0),
|
||||||
1, "Secondary header is invalid");
|
1, "Secondary header is invalid");
|
||||||
TEST_CALLS("VbExDiskRead(h, 1, 1)\n"
|
TEST_CALLS("VbExDiskRead(h, 1, 1)\n"
|
||||||
"VbExDiskRead(h, 1023, 1)\n");
|
"VbExDiskRead(h, 1023, 1)\n");
|
||||||
@@ -385,8 +385,8 @@ static void ReadWriteGptTest(void)
|
|||||||
"VbExDiskRead(h, 991, 32)\n"
|
"VbExDiskRead(h, 991, 32)\n"
|
||||||
"VbExDiskWrite(h, 1, 1)\n"
|
"VbExDiskWrite(h, 1, 1)\n"
|
||||||
"VbExDiskWrite(h, 2, 32)\n");
|
"VbExDiskWrite(h, 2, 32)\n");
|
||||||
TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.drive_sectors,
|
TEST_EQ(CheckHeader(mock_gpt_primary, 0, g.streaming_drive_sectors,
|
||||||
g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
|
g.gpt_drive_sectors, 0),
|
||||||
0, "Fix Primary GPT: Primary header is valid");
|
0, "Fix Primary GPT: Primary header is valid");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -410,8 +410,8 @@ static void ReadWriteGptTest(void)
|
|||||||
"VbExDiskRead(h, 1023, 1)\n"
|
"VbExDiskRead(h, 1023, 1)\n"
|
||||||
"VbExDiskWrite(h, 1023, 1)\n"
|
"VbExDiskWrite(h, 1023, 1)\n"
|
||||||
"VbExDiskWrite(h, 991, 32)\n");
|
"VbExDiskWrite(h, 991, 32)\n");
|
||||||
TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.drive_sectors,
|
TEST_EQ(CheckHeader(mock_gpt_secondary, 1, g.streaming_drive_sectors,
|
||||||
g.gpt_drive_sectors, GPT_STORED_ON_DEVICE),
|
g.gpt_drive_sectors, 0),
|
||||||
0, "Fix Secondary GPT: Secondary header is valid");
|
0, "Fix Secondary GPT: Secondary header is valid");
|
||||||
|
|
||||||
/* Data which is changed is written */
|
/* Data which is changed is written */
|
||||||
|
|||||||
Reference in New Issue
Block a user