liblp: Add block device size to LpMetadataGeometry.
This makes it easier to validate the device and make assumptions about the device layout without having actual access. Bug: 79173901 Test: liblp_test gtest Change-Id: I53d24684020ec9210c8a17d155e738b3b2405806
This commit is contained in:
parent
9154fbc8df
commit
4813823e73
4 changed files with 21 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue