diff options
author | Albert Chaulk <achaulk@chromium.org> | 2013-06-25 11:30:46 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-07-03 16:02:34 -0700 |
commit | 289b604f6154b118f3c47aa35b09e99a4e144814 (patch) | |
tree | 2db004eff5ba2fc4d3b80d056df970650b74a92b /cgpt | |
parent | 7d401c5cd58ec422e239b28c334fc2e94778f565 (diff) | |
download | vboot-289b604f6154b118f3c47aa35b09e99a4e144814.tar.gz |
Port MTD structures to use 64-bit byte offsets instead of sectors.
As per the discussion on issue 221745 we will be using 64-bit byte offsets
for the MTD partition table and converting to/from sectors internally in cgpt.
Existing interfaces do not change, eg sizes are still reported in sectors, only
the on-disk representation is affected.
BRANCH=none
BUG=chromium:221745
TEST=unit tests pass
Change-Id: Id312d42783acfdabe6eb8aea11dcbd298e00a100
Reviewed-on: https://gerrit.chromium.org/gerrit/60919
Commit-Queue: Albert Chaulk <achaulk@chromium.org>
Reviewed-by: Albert Chaulk <achaulk@chromium.org>
Tested-by: Albert Chaulk <achaulk@chromium.org>
Diffstat (limited to 'cgpt')
-rw-r--r-- | cgpt/cgpt_add.c | 17 | ||||
-rw-r--r-- | cgpt/cgpt_create.c | 4 | ||||
-rw-r--r-- | cgpt/cgpt_find.c | 6 | ||||
-rw-r--r-- | cgpt/cgpt_show.c | 31 |
4 files changed, 32 insertions, 26 deletions
diff --git a/cgpt/cgpt_add.c b/cgpt/cgpt_add.c index 8332f222..e0e24b81 100644 --- a/cgpt/cgpt_add.c +++ b/cgpt/cgpt_add.c @@ -103,9 +103,14 @@ static int MtdSetEntryAttributes(struct drive *drive, entry = MtdGetEntry(&drive->mtd, PRIMARY, index); if (params->set_begin) - entry->starting_lba = params->begin; - if (params->set_size) - entry->ending_lba = entry->starting_lba + params->size - 1; + memcpy(&entry->starting_offset, ¶ms->begin, sizeof(params->begin)); + if (params->set_size) { + uint64_t start; + uint64_t end; + MtdGetPartitionSize(entry, &start, NULL, NULL); + end = start + params->size - 1; + memcpy(&entry->ending_offset, &end, sizeof(end)); + } if (params->set_type) MtdSetEntryType(entry, LookupMtdTypeForGuid(¶ms->type_guid)); @@ -273,14 +278,10 @@ int CgptGetPartitionDetails(CgptAddParams *params) { if(drive.is_mtd) { MtdDiskPartition *entry = MtdGetEntry(&drive.mtd, PRIMARY, index); - uint64_t start_lba, end_lba; const Guid *guid = LookupGuidForMtdType(MtdGetEntryType(entry)); memcpy(¶ms->type_guid, guid, sizeof(params->type_guid)); memset(¶ms->unique_guid, 0, sizeof(params->unique_guid)); - start_lba = entry->starting_lba; - end_lba = entry->ending_lba; - params->begin = start_lba; - params->size = end_lba - start_lba + 1; + MtdGetPartitionSizeInSectors(entry, ¶ms->begin, NULL, ¶ms->size); params->raw_value = entry->flags; } else { // GPT-specific code diff --git a/cgpt/cgpt_create.c b/cgpt/cgpt_create.c index 0b116b2b..e7cbadf8 100644 --- a/cgpt/cgpt_create.c +++ b/cgpt/cgpt_create.c @@ -60,8 +60,8 @@ int MtdCreate(struct drive *drive, CgptCreateParams *params) { // Prep basic parameters memcpy(h->signature, MTD_DRIVE_SIGNATURE, sizeof(h->signature)); h->size = sizeof(*h); - h->first_lba = 0; - h->last_lba = drive->mtd.drive_sectors - 1; + h->first_offset = 0; + h->last_offset = (drive->mtd.drive_sectors * drive->mtd.sector_bytes) - 1; h->crc32 = MtdHeaderCrc(h); } diff --git a/cgpt/cgpt_find.c b/cgpt/cgpt_find.c index df6c4d39..fc223a02 100644 --- a/cgpt/cgpt_find.c +++ b/cgpt/cgpt_find.c @@ -150,13 +150,13 @@ static int mtd_match_type_to_guid(const MtdDiskPartition *e, const Guid *guid) { static int mtd_match_content(CgptFindParams *params, struct drive *drive, MtdDiskPartition *entry) { - uint64_t part_size; + uint64_t start, part_size; if (!params->matchlen) return 1; // Ensure that the region we want to match against is inside the partition. - part_size = LBA_SIZE * (entry->ending_lba - entry->starting_lba + 1); + MtdGetPartitionSize(entry, &start, NULL, &part_size); if (params->matchoffset + params->matchlen > part_size) { return 0; } @@ -164,7 +164,7 @@ static int mtd_match_content(CgptFindParams *params, struct drive *drive, // Read the partition data. if (!FillBuffer(params, drive->fd, - (LBA_SIZE * entry->starting_lba) + params->matchoffset, + start + params->matchoffset, params->matchlen)) { Error("unable to read partition data\n"); return 0; diff --git a/cgpt/cgpt_show.c b/cgpt/cgpt_show.c index c3c222eb..78a285c7 100644 --- a/cgpt/cgpt_show.c +++ b/cgpt/cgpt_show.c @@ -73,8 +73,10 @@ void MtdHeaderDetails(MtdDiskLayout *header, const char *indent, int raw) { printf("%sSize: %d\n", indent, header->size); printf("%sCRC: 0x%08x %s\n", indent, header->crc32, (MtdHeaderCrc(header) != header->crc32) ? "(INVALID)" : ""); - printf("%sFirst LBA: %u\n", indent, header->first_lba); - printf("%sLast LBA: %u\n", indent, header->last_lba); + printf("%sFirst LBA: %llu\n", indent, + (unsigned long long)header->first_offset); + printf("%sLast LBA: %llu\n", indent, + (unsigned long long)header->last_offset); } static void HeaderDetails(GptHeader *header, GptEntry *entries, @@ -110,20 +112,19 @@ static void HeaderDetails(GptHeader *header, GptEntry *entries, void MtdEntryDetails(MtdDiskPartition *entry, uint32_t index, int raw) { const Guid *guid = LookupGuidForMtdType(MtdGetEntryType(entry)); char buf[256]; // scratch buffer for formatting output + uint64_t start, size; if (guid) { ResolveType(guid, buf); } else { snprintf(buf, sizeof(buf), "MTD partition type %d", MtdGetEntryType(entry)); } + MtdGetPartitionSizeInSectors(entry, &start, NULL, &size); + if (!raw) { - printf(PARTITION_FMT, (int)entry->starting_lba, - (int)(entry->ending_lba - entry->starting_lba + 1), - index+1, buf); + printf(PARTITION_FMT, (int)start, (int)size, index+1, buf); } else { - printf(PARTITION_FMT, (int)entry->starting_lba, - (int)(entry->ending_lba - entry->starting_lba + 1), - index+1, buf); + printf(PARTITION_FMT, (int)start, (int)size, index+1, buf); } } @@ -257,14 +258,17 @@ int MtdShow(struct drive *drive, CgptShowParams *params) { MtdDiskPartition *entry = MtdGetEntry(&drive->mtd, ANY_VALID, index); char buf[256]; // scratch buffer for string conversion const Guid *guid; + uint64_t start, size; + + MtdGetPartitionSizeInSectors(entry, &start, NULL, &size); if (params->single_item) { switch(params->single_item) { case 'b': - printf("%u\n", entry->starting_lba); + printf("%u\n", (int)start); break; case 's': - printf("%u\n", entry->ending_lba - entry->starting_lba + 1); + printf("%u\n", (int)size); break; case 't': guid = LookupGuidForMtdType(MtdGetEntryType(entry)); @@ -295,6 +299,9 @@ int MtdShow(struct drive *drive, CgptShowParams *params) { for (i = 0; i < GetNumberOfEntries(drive); ++i) { MtdDiskPartition *entry = MtdGetEntry(&drive->mtd, ANY_VALID, i); const Guid *guid = LookupGuidForMtdType(MtdGetEntryType(entry)); + uint64_t start, size; + + MtdGetPartitionSizeInSectors(entry, &start, NULL, &size); if (IsUnused(drive, ANY_VALID, i)) continue; @@ -305,9 +312,7 @@ int MtdShow(struct drive *drive, CgptShowParams *params) { snprintf(type, sizeof(type), "MTD partition type %d", MtdGetEntryType(entry)); } - printf(PARTITION_FMT, (int)entry->starting_lba, - (int)(entry->ending_lba - entry->starting_lba + 1), - i+1, type); + printf(PARTITION_FMT, (int)start, (int)size, i+1, type); } } else { // show all partitions if (params->debug || params->verbose) { |