diff --git a/fs_mgr/fs_mgr_overlayfs_control.cpp b/fs_mgr/fs_mgr_overlayfs_control.cpp index 50d8280e9..9be236d1e 100644 --- a/fs_mgr/fs_mgr_overlayfs_control.cpp +++ b/fs_mgr/fs_mgr_overlayfs_control.cpp @@ -347,33 +347,6 @@ static std::string GetDsuScratchDevice() { return ""; } -// This returns the scratch device that was detected during early boot (first- -// stage init). If the device was created later, for example during setup for -// the adb remount command, it can return an empty string since it does not -// query ImageManager. (Note that ImageManager in first-stage init will always -// use device-mapper, since /data is not available to use loop devices.) -static std::string GetBootScratchDevice() { - // Note: fs_mgr_is_dsu_running() always returns false in recovery or fastbootd. - if (fs_mgr_is_dsu_running()) { - return GetDsuScratchDevice(); - } - - auto& dm = DeviceMapper::Instance(); - - // If there is a scratch partition allocated in /data or on super, we - // automatically prioritize that over super_other or system_other. - // Some devices, for example, have a write-protected eMMC and the - // super partition cannot be used even if it exists. - std::string device; - auto partition_name = android::base::Basename(kScratchMountPoint); - if (dm.GetState(partition_name) != DmDeviceState::INVALID && - dm.GetDmDevicePathByName(partition_name, &device)) { - return device; - } - - return ""; -} - bool MakeScratchFilesystem(const std::string& scratch_device) { // Force mkfs by design for overlay support of adb remount, simplify and // thus do not rely on fsck to correct problems that could creep in. @@ -922,6 +895,33 @@ void CleanupOldScratchFiles() { } } +// This returns the scratch device that was detected during early boot (first- +// stage init). If the device was created later, for example during setup for +// the adb remount command, it can return an empty string since it does not +// query ImageManager. (Note that ImageManager in first-stage init will always +// use device-mapper, since /data is not available to use loop devices.) +std::string GetBootScratchDevice() { + // Note: fs_mgr_is_dsu_running() always returns false in recovery or fastbootd. + if (fs_mgr_is_dsu_running()) { + return GetDsuScratchDevice(); + } + + auto& dm = DeviceMapper::Instance(); + + // If there is a scratch partition allocated in /data or on super, we + // automatically prioritize that over super_other or system_other. + // Some devices, for example, have a write-protected eMMC and the + // super partition cannot be used even if it exists. + std::string device; + auto partition_name = android::base::Basename(kScratchMountPoint); + if (dm.GetState(partition_name) != DmDeviceState::INVALID && + dm.GetDmDevicePathByName(partition_name, &device)) { + return device; + } + + return ""; +} + void TeardownAllOverlayForMountPoint(const std::string& mount_point) { if (!OverlayfsTeardownAllowed()) { return; diff --git a/fs_mgr/fs_mgr_overlayfs_control.h b/fs_mgr/fs_mgr_overlayfs_control.h index b17510158..3516c462d 100644 --- a/fs_mgr/fs_mgr_overlayfs_control.h +++ b/fs_mgr/fs_mgr_overlayfs_control.h @@ -38,5 +38,7 @@ namespace fs_mgr { void CleanupOldScratchFiles(); +std::string GetBootScratchDevice(); + } // namespace fs_mgr } // namespace android diff --git a/fs_mgr/fs_mgr_overlayfs_mount.cpp b/fs_mgr/fs_mgr_overlayfs_mount.cpp index e0b6721ad..e1684366b 100644 --- a/fs_mgr/fs_mgr_overlayfs_mount.cpp +++ b/fs_mgr/fs_mgr_overlayfs_mount.cpp @@ -42,15 +42,14 @@ #include #include #include -#include #include #include +#include "fs_mgr_overlayfs_control.h" #include "fs_mgr_overlayfs_mount.h" #include "fs_mgr_priv.h" using namespace std::literals; -using namespace android::dm; using namespace android::fs_mgr; using namespace android::storage_literals; @@ -593,45 +592,6 @@ bool MountScratch(const std::string& device_path, bool readonly) { return true; } -// Note: The scratch partition of DSU is managed by gsid, and should be initialized during -// first-stage-mount. Just check if the DM device for DSU scratch partition is created or not. -static std::string GetDsuScratchDevice() { - auto& dm = DeviceMapper::Instance(); - std::string device; - if (dm.GetState(android::gsi::kDsuScratch) != DmDeviceState::INVALID && - dm.GetDmDevicePathByName(android::gsi::kDsuScratch, &device)) { - return device; - } - return ""; -} - -// This returns the scratch device that was detected during early boot (first- -// stage init). If the device was created later, for example during setup for -// the adb remount command, it can return an empty string since it does not -// query ImageManager. (Note that ImageManager in first-stage init will always -// use device-mapper, since /data is not available to use loop devices.) -static std::string GetBootScratchDevice() { - // Note: fs_mgr_is_dsu_running() always returns false in recovery or fastbootd. - if (fs_mgr_is_dsu_running()) { - return GetDsuScratchDevice(); - } - - auto& dm = DeviceMapper::Instance(); - - // If there is a scratch partition allocated in /data or on super, we - // automatically prioritize that over super_other or system_other. - // Some devices, for example, have a write-protected eMMC and the - // super partition cannot be used even if it exists. - std::string device; - auto partition_name = android::base::Basename(kScratchMountPoint); - if (dm.GetState(partition_name) != DmDeviceState::INVALID && - dm.GetDmDevicePathByName(partition_name, &device)) { - return device; - } - - return ""; -} - // NOTE: OverlayfsSetupAllowed() must be "stricter" than OverlayfsTeardownAllowed(). // Setup is allowed only if teardown is also allowed. bool OverlayfsSetupAllowed(bool verbose) {