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

Commit 94abcc5b authored by Alessio Balsini's avatar Alessio Balsini Committed by android-build-merger
Browse files

Merge "Helper function to mount snapshot devices in recovery"

am: 7cd37ba4

Change-Id: I4f032327aab79586e83c7d2b5bf1214c4ba53339
parents d4120b90 7cd37ba4
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -74,6 +74,12 @@ static constexpr const std::string_view kCowGroupName = "cow";

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

enum class CreateResult : unsigned int {
    ERROR,
    CREATED,
    NOT_CREATED,
};

enum class UpdateState : unsigned int {
    // No update or merge is in progress.
    None,
@@ -246,6 +252,17 @@ class SnapshotManager final {
    // optional callback fires periodically to query progress via GetUpdateState.
    bool HandleImminentDataWipe(const std::function<void()>& callback = {});

    // This method is only allowed in recovery and is used as a helper to
    // initialize the snapshot devices as a requirement to mount a snapshotted
    // /system in recovery.
    // This function returns:
    // - CreateResult::CREATED if snapshot devices were successfully created;
    // - CreateResult::NOT_CREATED if it was not necessary to create snapshot
    // devices;
    // - CreateResult::ERROR if a fatal error occurred, mounting /system should
    // be aborted.
    CreateResult RecoveryCreateSnapshotDevices();

    // Dump debug information.
    bool Dump(std::ostream& os);

+32 −0
Original line number Diff line number Diff line
@@ -2356,5 +2356,37 @@ bool SnapshotManager::EnsureNoOverflowSnapshot(LockedFile* lock) {
    return true;
}

CreateResult SnapshotManager::RecoveryCreateSnapshotDevices() {
    if (!device_->IsRecovery()) {
        LOG(ERROR) << __func__ << " is only allowed in recovery.";
        return CreateResult::NOT_CREATED;
    }

    auto mount = EnsureMetadataMounted();
    if (!mount || !mount->HasDevice()) {
        LOG(ERROR) << "Couldn't mount Metadata.";
        return CreateResult::NOT_CREATED;
    }

    auto state_file = GetStateFilePath();
    if (access(state_file.c_str(), F_OK) != 0 && errno == ENOENT) {
        LOG(ERROR) << "Couldn't access state file.";
        return CreateResult::NOT_CREATED;
    }

    if (!NeedSnapshotsInFirstStageMount()) {
        return CreateResult::NOT_CREATED;
    }

    auto slot_suffix = device_->GetOtherSlotSuffix();
    auto slot_number = SlotNumberForSlotSuffix(slot_suffix);
    auto super_path = device_->GetSuperDevice(slot_number);
    if (!CreateLogicalAndSnapshotPartitions(super_path)) {
        LOG(ERROR) << "Unable to map partitions.";
        return CreateResult::ERROR;
    }
    return CreateResult::CREATED;
}

}  // namespace snapshot
}  // namespace android