Merge "libsnapshot: Add RecoveryCreateSnapshotDevices(device)" into rvc-dev
diff --git a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
index 957c26c..5c276b4 100644
--- a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
+++ b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
@@ -230,8 +230,14 @@
// 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);
diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp
index 7e84c48..2d59f0c 100644
--- a/fs_mgr/libsnapshot/snapshot.cpp
+++ b/fs_mgr/libsnapshot/snapshot.cpp
@@ -2584,6 +2584,20 @@
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) {