Commit 94f6d54e authored by lorneli's avatar lorneli Committed by Jim Harris
Browse files

bdev/gpt: examine my_lba in primary header



Check my_lba in gpt's primary header equals to LBA1.

Set correct my_lba in unit test to pass the test, and update
related header_crc32.

Change-Id: I124a7a883e9304bd3955ce3de6b589596c4195ea
Signed-off-by: default avatarlorneli <lorneli@163.com>
Reviewed-on: https://review.gerrithub.io/c/439889


Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 8adbd909
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ spdk_gpt_read_header(struct spdk_gpt *gpt)
{
	uint32_t head_size;
	uint32_t new_crc, original_crc;
	uint64_t my_lba;
	struct spdk_gpt_header *head;

	head = (struct spdk_gpt_header *)(gpt->buf + GPT_PRIMARY_PARTITION_TABLE_LBA * gpt->sector_size);
@@ -149,6 +150,13 @@ spdk_gpt_read_header(struct spdk_gpt *gpt)
		return -1;
	}

	my_lba = from_le64(&head->my_lba);
	if (my_lba != GPT_PRIMARY_PARTITION_TABLE_LBA) {
		SPDK_ERRLOG("head my_lba(%" PRIu64 ") != expected(%d)\n",
			    my_lba, GPT_PRIMARY_PARTITION_TABLE_LBA);
		return -1;
	}

	if (spdk_gpt_lba_range_check(head, gpt->lba_end)) {
		SPDK_ERRLOG("lba range check error\n");
		return -1;
+11 −4
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ test_read_header(void)
	re = spdk_gpt_read_header(gpt);
	CU_ASSERT(re == -1);

	/* Set head->gpt_signature matched, lba_end usable_lba mismatch */
	/* Set head->gpt_signature matched, head->my_lba mismatch */
	to_le32(&head->header_crc32, 0xD637335A);
	head->gpt_signature[0] = 'E';
	head->gpt_signature[1] = 'F';
@@ -126,8 +126,14 @@ test_read_header(void)
	re = spdk_gpt_read_header(gpt);
	CU_ASSERT(re == -1);

	/* Set head->my_lba matched, lba_end usable_lba mismatch */
	to_le32(&head->header_crc32, 0xB3CDB2D2);
	to_le64(&head->my_lba, 0x1);
	re = spdk_gpt_read_header(gpt);
	CU_ASSERT(re == -1);

	/* Set gpt->lba_end usable_lba matched, passing case */
	to_le32(&head->header_crc32, 0x30CB7378);
	to_le32(&head->header_crc32, 0x5531F2F0);
	to_le64(&gpt->lba_start, 0x0);
	to_le64(&gpt->lba_end, 0x2E935FFE);
	to_le64(&head->first_usable_lba, 0xA);
@@ -239,7 +245,8 @@ test_parse(void)
	head->gpt_signature[5] = 'A';
	head->gpt_signature[6] = 'R';
	head->gpt_signature[7] = 'T';
	to_le32(&head->header_crc32, 0x30CB7378);
	to_le32(&head->header_crc32, 0x5531F2F0);
	to_le64(&head->my_lba, 0x1);
	to_le64(&gpt->lba_start, 0x0);
	to_le64(&gpt->lba_end, 0x2E935FFE);
	to_le64(&head->first_usable_lba, 0xA);
@@ -250,7 +257,7 @@ test_parse(void)
	/* Set read_partitions passed, all passed */
	to_le32(&head->size_of_partition_entry, 0x80);
	to_le64(&head->partition_entry_lba, 0x20);
	to_le32(&head->header_crc32, 0xE1A08822);
	to_le32(&head->header_crc32, 0x845A09AA);
	to_le32(&head->partition_entry_array_crc32, 0xEBEE44FB);
	to_le32(&head->num_partition_entries, 0x80);
	re = spdk_gpt_parse(gpt);