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.hpp b/pnor_partition_table.hpp
index fae03a9..d19ff4b 100644
--- a/pnor_partition_table.hpp
+++ b/pnor_partition_table.hpp
@@ -4,6 +4,7 @@
#include <memory>
#include <numeric>
#include <experimental/filesystem>
+#include "common.h"
#include "pnor_partition_defs.h"
namespace openpower
@@ -102,13 +103,34 @@
Table& operator=(Table&&) = delete;
~Table() = default;
- /** @brief Return size of partition table
+ /** @brief Return the exact size of partition table in bytes
*
- * @returns size_t - size of partition table in blocks
+ * @returns size_t - size of partition table in bytes
*/
size_t size() const
{
- return szBlocks;
+ return szBytes;
+ }
+
+ /** @brief Return aligned size of partition table in bytes
+ *
+ * The value returned will be greater-than or equal to size(), and
+ * aligned to blockSize.
+ *
+ * @returns size_t - capacity of partition table in bytes
+ */
+ size_t capacity() const
+ {
+ return align_up(szBytes, blockSize);
+ }
+
+ /** @brief Return the size of partition table in blocks
+ *
+ * @returns size_t - size of partition table in blocks
+ */
+ size_t blocks() const
+ {
+ return capacity() / blockSize;
}
/** @brief Return a partition table having byte-ordering
@@ -181,9 +203,8 @@
/** @brief Size of the PNOR partition table -
* sizeof(pnor_partition_table) +
* (no. of partitions * sizeof(pnor_partition)),
- * measured in erase-blocks.
*/
- size_t szBlocks;
+ size_t szBytes;
/** @brief Partition table */
PartitionTable tbl;