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

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

Merge "liblp: refactor MetadataBuilder::NewForUpdate"

parents 36acd1d2 6079cd01
Loading
Loading
Loading
Loading
+21 −10
Original line number Diff line number Diff line
@@ -159,16 +159,27 @@ std::unique_ptr<MetadataBuilder> MetadataBuilder::NewForUpdate(const IPartitionO
        return nullptr;
    }

    // On non-retrofit devices there is only one location for metadata: the
    // super partition. update_engine will remove and resize partitions as
    // needed. On the other hand, for retrofit devices, we'll need to
    // translate block device and group names to update their slot suffixes.
    // On retrofit DAP devices, modify the metadata so that it is suitable for being written
    // to the target slot later. We detect retrofit DAP devices by checking the super partition
    // name and system properties.
    // See comments for UpdateMetadataForOtherSuper.
    auto super_device = GetMetadataSuperBlockDevice(*metadata.get());
    if (GetBlockDevicePartitionName(*super_device) == "super" ||
        !IsRetrofitDynamicPartitionsDevice()) {
    if (GetBlockDevicePartitionName(*super_device) != "super" &&
        IsRetrofitDynamicPartitionsDevice()) {
        if (!UpdateMetadataForOtherSuper(metadata.get(), source_slot_number, target_slot_number)) {
            return nullptr;
        }
    }

    return New(*metadata.get(), &opener);
}

// For retrofit DAP devices, there are (conceptually) two super partitions. We'll need to translate
// block device and group names to update their slot suffixes.
// (On the other hand, On non-retrofit DAP devices there is only one location for metadata: the
// super partition. update_engine will remove and resize partitions as needed.)
bool MetadataBuilder::UpdateMetadataForOtherSuper(LpMetadata* metadata, uint32_t source_slot_number,
                                                  uint32_t target_slot_number) {
    // Clear partitions and extents, since they have no meaning on the target
    // slot. We also clear groups since they are re-added during OTA.
    metadata->partitions.clear();
@@ -188,7 +199,7 @@ std::unique_ptr<MetadataBuilder> MetadataBuilder::NewForUpdate(const IPartitionO
            // refers to a target or unknown block device.
            LERROR << "Invalid block device for slot " << source_slot_suffix << ": "
                   << partition_name;
            return nullptr;
            return false;
        }
        std::string new_name =
                partition_name.substr(0, partition_name.size() - slot_suffix.size()) +
@@ -197,12 +208,12 @@ std::unique_ptr<MetadataBuilder> MetadataBuilder::NewForUpdate(const IPartitionO
        auto new_device = source_block_device;
        if (!UpdateBlockDevicePartitionName(&new_device, new_name)) {
            LERROR << "Partition name too long: " << new_name;
            return nullptr;
            return false;
        }
        metadata->block_devices.emplace_back(new_device);
    }

    return New(*metadata.get(), &opener);
    return true;
}

MetadataBuilder::MetadataBuilder() : auto_slot_suffixing_(false) {
+3 −0
Original line number Diff line number Diff line
@@ -345,6 +345,9 @@ class MetadataBuilder {
                                                    const std::vector<Interval>& free_list,
                                                    uint64_t sectors_needed) const;

    static bool UpdateMetadataForOtherSuper(LpMetadata* metadata, uint32_t source_slot_number,
                                            uint32_t target_slot_number);

    LpMetadataGeometry geometry_;
    LpMetadataHeader header_;
    std::vector<std::unique_ptr<Partition>> partitions_;