From c7df3ff5b302e5388b746e838da01773572c3a6c Mon Sep 17 00:00:00 2001 From: Michael Bestas Date: Sat, 16 Jan 2021 18:16:47 +0200 Subject: [PATCH] recovery: Add ability to unmount system * Correct system mount text while we are at it Change-Id: I955173e84767e61d729fb55b4e53a84e310e786e recovery: Fix typo when unmounting system Signed-off-by: Mohammad Hasan Keramat J Change-Id: I86c245c1e624bea045eac25657af02b45cd1d605 --- recovery.cpp | 27 +++++++++++++++++++-------- recovery_ui/device.cpp | 2 +- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/recovery.cpp b/recovery.cpp index 077a2d4bd..65c7942b2 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -608,16 +609,26 @@ static Device::BuiltinAction PromptAndWait(Device* device, InstallResult status) break; } - case Device::MOUNT_SYSTEM: - // For Virtual A/B, set up the snapshot devices (if exist). - if (!CreateSnapshotPartitions()) { - ui->Print("Virtual A/B: snapshot partitions creation failed.\n"); - break; - } - if (ensure_path_mounted_at(android::fs_mgr::GetSystemRoot(), "/mnt/system") != -1) { - ui->Print("Mounted /system.\n"); + case Device::MOUNT_SYSTEM: { + static bool mounted = false; + if (!mounted) { + // For Virtual A/B, set up the snapshot devices (if exist). + if (!logical_partitions_mapped() && !CreateSnapshotPartitions()) { + ui->Print("Virtual A/B: snapshot partitions creation failed.\n"); + break; + } + if (ensure_path_mounted_at(android::fs_mgr::GetSystemRoot(), "/mnt/system") != -1) { + ui->Print("Mounted /mnt/system.\n"); + mounted = true; + } + } else { + if (umount("/mnt/system") != -1) { + ui->Print("Unmounted /mnt/system.\n"); + mounted = false; + } } break; + } case Device::KEY_INTERRUPTED: return Device::KEY_INTERRUPTED; diff --git a/recovery_ui/device.cpp b/recovery_ui/device.cpp index 01e9b4966..1c335d15b 100644 --- a/recovery_ui/device.cpp +++ b/recovery_ui/device.cpp @@ -35,7 +35,7 @@ static std::vector> g_menu_actions { "Apply update from SD card", Device::APPLY_SDCARD }, { "Wipe data/factory reset", Device::WIPE_DATA }, { "Wipe cache partition", Device::WIPE_CACHE }, - { "Mount /system", Device::MOUNT_SYSTEM }, + { "Mount/unmount system", Device::MOUNT_SYSTEM }, { "View recovery logs", Device::VIEW_RECOVERY_LOGS }, { "Run graphics test", Device::RUN_GRAPHICS_TEST }, { "Run locale test", Device::RUN_LOCALE_TEST },