libsnapshot: Add RecoveryCreateSnapshotDevices(device)

... that doesn't auto mount/umount /metadata.

Test: builds
Bug: 151983957
Change-Id: If525a82c1635ddef221e7be20763bc2f27d3c417
Merged-In: If525a82c1635ddef221e7be20763bc2f27d3c417
This commit is contained in:
Yifan Hong 2020-03-19 19:26:28 -07:00
parent c0a5aff0df
commit c04d4a567c
2 changed files with 20 additions and 0 deletions

View File

@ -230,8 +230,14 @@ class SnapshotManager final {
// devices;
// - CreateResult::ERROR if a fatal error occurred, mounting /system should
// be aborted.
// This function mounts /metadata when called, and unmounts /metadata upon
// return.
CreateResult RecoveryCreateSnapshotDevices();
// Same as RecoveryCreateSnapshotDevices(), but does not auto mount/umount
// /metadata.
CreateResult RecoveryCreateSnapshotDevices(const std::unique_ptr<AutoDevice>& metadata_device);
// Dump debug information.
bool Dump(std::ostream& os);

View File

@ -2584,6 +2584,20 @@ CreateResult SnapshotManager::RecoveryCreateSnapshotDevices() {
LOG(ERROR) << "Couldn't mount Metadata.";
return CreateResult::NOT_CREATED;
}
return RecoveryCreateSnapshotDevices(mount);
}
CreateResult SnapshotManager::RecoveryCreateSnapshotDevices(
const std::unique_ptr<AutoDevice>& metadata_device) {
if (!device_->IsRecovery()) {
LOG(ERROR) << __func__ << " is only allowed in recovery.";
return CreateResult::NOT_CREATED;
}
if (metadata_device == nullptr || !metadata_device->HasDevice()) {
LOG(ERROR) << "Metadata not mounted.";
return CreateResult::NOT_CREATED;
}
auto state_file = GetStateFilePath();
if (access(state_file.c_str(), F_OK) != 0 && errno == ENOENT) {