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

Commit ef2c39bd authored by Alessio Balsini's avatar Alessio Balsini Committed by Yifan Hong
Browse files

SOURCE_COPY operation: implement src == dst



Helper function to compare the source and destination extents of a
SOURCE_COPY InstallOperation.
The function returns true iff source and destination are identical with
the use of std::equal().

Bug: 141207436
Test: build
Change-Id: I146aeba1c8ede35f21cfef8e21d4af62274bda84
Signed-off-by: default avatarAlessio Balsini <balsini@google.com>
parent adb98df1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -72,6 +72,8 @@ class SnapshotStatus;

static constexpr const std::string_view kCowGroupName = "cow";

bool SourceCopyOperationIsClone(const chromeos_update_engine::InstallOperation& operation);

enum class UpdateState : unsigned int {
    // No update or merge is in progress.
    None,
+18 −0
Original line number Diff line number Diff line
@@ -62,6 +62,19 @@ bool PartitionCowCreator::HasExtent(Partition* p, Extent* e) {
    return false;
}

bool SourceCopyOperationIsClone(const InstallOperation& operation) {
    using ChromeOSExtent = chromeos_update_engine::Extent;
    if (operation.src_extents().size() != operation.dst_extents().size()) {
        return false;
    }
    return std::equal(operation.src_extents().begin(), operation.src_extents().end(),
                      operation.dst_extents().begin(),
                      [](const ChromeOSExtent& src, const ChromeOSExtent& dst) {
                          return src.start_block() == dst.start_block() &&
                                 src.num_blocks() == dst.num_blocks();
                      });
}

void WriteExtent(DmSnapCowSizeCalculator* sc, const chromeos_update_engine::Extent& de,
                 unsigned int sectors_per_block) {
    const auto block_boundary = de.start_block() + de.num_blocks();
@@ -88,6 +101,11 @@ uint64_t PartitionCowCreator::GetCowSize() {
    if (operations == nullptr) return sc.cow_size_bytes();

    for (const auto& iop : *operations) {
        // Do not allocate space for operations that are going to be skipped
        // during OTA application.
        if (iop.type() == InstallOperation::SOURCE_COPY && SourceCopyOperationIsClone(iop))
            continue;

        for (const auto& de : iop.dst_extents()) {
            WriteExtent(&sc, de, sectors_per_block);
        }