Merge "liblp: Add block device size to LpMetadataGeometry."

This commit is contained in:
Treehugger Robot 2018-07-16 17:07:58 +00:00 committed by Gerrit Code Review
commit f78c9643e0
4 changed files with 21 additions and 2 deletions

View file

@ -250,6 +250,7 @@ bool MetadataBuilder::Init(const BlockDeviceInfo& device_info, uint32_t metadata
geometry_.metadata_slot_count = metadata_slot_count;
geometry_.alignment = device_info_.alignment;
geometry_.alignment_offset = device_info_.alignment_offset;
geometry_.block_device_size = device_info_.size;
return true;
}

View file

@ -129,6 +129,11 @@ typedef struct LpMetadataGeometry {
* If it cannot be determined, it is assumed to be 0.
*/
uint32_t alignment_offset;
/* 72: Block device size, as specified when the metadata was created. This
* can be used to verify the geometry against a target device.
*/
uint64_t block_device_size;
} __attribute__((packed)) LpMetadataGeometry;
/* The logical partition metadata has a number of tables; they are described

View file

@ -31,8 +31,16 @@ TEST(liblp, SlotNumberForSlotSuffix) {
}
TEST(liblp, GetMetadataOffset) {
LpMetadataGeometry geometry = {
LP_METADATA_GEOMETRY_MAGIC, sizeof(geometry), {0}, 16384, 4, 10000, 80000, 0, 0};
LpMetadataGeometry geometry = {LP_METADATA_GEOMETRY_MAGIC,
sizeof(geometry),
{0},
16384,
4,
10000,
80000,
0,
0,
1024 * 1024};
EXPECT_EQ(GetPrimaryMetadataOffset(geometry, 0), 4096);
EXPECT_EQ(GetPrimaryMetadataOffset(geometry, 1), 4096 + 16384);
EXPECT_EQ(GetPrimaryMetadataOffset(geometry, 2), 4096 + 16384 * 2);

View file

@ -108,6 +108,11 @@ static bool ValidateAndSerializeMetadata(int fd, const LpMetadata& metadata, std
LERROR << "Not enough space to backup all logical partition metadata slots.";
return false;
}
if (blockdevice_size != metadata.geometry.block_device_size) {
LERROR << "Block device size " << blockdevice_size
<< " does not match metadata requested size " << metadata.geometry.block_device_size;
return false;
}
// Make sure all partition entries reference valid extents.
for (const auto& partition : metadata.partitions) {