pnor_partition_table: Rework semantics of Table::size()
Table::size() now returns the exact table size in bytes,
Table::capacity() returns the block-aligned size in bytes (capacity in
terms of how much the table could grow before expanding to another
block), and Table::blocks() returns the size in blocks.
This helps out with code clarity around the codebase and enables the
introduction of ToC-related integration tests.
The one wrinkle is vpnor_get_partition_table_size(), which is modified
to call Table::blocks() but retains 'size' in its name. This is largely
unimportant as the function will go away shortly.
Change-Id: I3becf47f2201df5fe0bed86fcb92d7b94d06ab11
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/pnor_partition_table.cpp b/pnor_partition_table.cpp
index 54bb347..eb956d6 100644
--- a/pnor_partition_table.cpp
+++ b/pnor_partition_table.cpp
@@ -21,8 +21,8 @@
{
Table::Table(fs::path&& directory, size_t blockSize, size_t pnorSize) :
- szBlocks(0), directory(std::move(directory)), numParts(0),
- blockSize(blockSize), pnorSize(pnorSize)
+ szBytes(sizeof(pnor_partition_table)), directory(std::move(directory)),
+ numParts(0), blockSize(blockSize), pnorSize(pnorSize)
{
preparePartitions();
prepareHeader();
@@ -34,7 +34,7 @@
decltype(auto) table = getNativeTable();
table.data.magic = PARTITION_HEADER_MAGIC;
table.data.version = PARTITION_VERSION_1;
- table.data.size = szBlocks;
+ table.data.size = blocks();
table.data.entry_size = sizeof(pnor_partition);
table.data.entry_count = numParts;
table.data.block_size = blockSize;
@@ -62,11 +62,8 @@
}
}
- size_t totalSizeBytes =
- sizeof(pnor_partition_table) + (num * sizeof(pnor_partition));
- size_t totalSizeAligned = align_up(totalSizeBytes, blockSize);
- szBlocks = totalSizeAligned / blockSize;
- tbl.resize(totalSizeAligned);
+ szBytes = sizeof(pnor_partition_table) + (num * sizeof(pnor_partition));
+ tbl.resize(capacity());
}
void Table::preparePartitions()