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

Commit 14ae4d1d authored by David Anderson's avatar David Anderson
Browse files

libsnapshot: Round compressed COW sizes to the nearest block.

This is needed to create and stack device-mapper devices. The kernel
complains (or rejects) the table otherwise.

Bug: N/A
Test: manual test
Change-Id: I2bb3e55b7d999522c4c990b4ab7c46bcb78553a8
parent 56850e12
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ using RepeatedPtrField = google::protobuf::RepeatedPtrField<T>;
namespace android {
namespace snapshot {

static constexpr uint64_t kBlockSize = 4096;

using namespace android::storage_literals;

// Intersect two linear extents. If no intersection, return an extent with length 0.
@@ -149,7 +151,12 @@ uint64_t PartitionCowCreator::GetCowSize() {

        // Add an extra 2MB of wiggle room for any minor differences in labels/metadata
        // that might come up.
        return update->estimate_cow_size() + 2_MiB;
        auto size = update->estimate_cow_size() + 2_MiB;

        // Align to nearest block.
        size += kBlockSize - 1;
        size &= ~(kBlockSize - 1);
        return size;
    }

    // WARNING: The origin partition should be READ-ONLY