Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f78c9643 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

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

parents 39e7a1c9 4813823e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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;
}

+5 −0
Original line number Diff line number Diff line
@@ -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
+10 −2
Original line number Diff line number Diff line
@@ -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);
+5 −0
Original line number Diff line number Diff line
@@ -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) {