overlayfs: fs_mgr_overlayfs_setup() should accept Fstab as input

Right now fs_mgr_overlayfs_setup() always reads the default fstab and
this makes the "-T" option of remount useless.
Change it so that the fstab is passed in by the caller.

Bug: 243501054
Test: adb remount -vT <path/to/fstab>
Test: and check that overlay is active after reboot
Change-Id: Ia4101938a50c305f105c57018b02aec01f862dec
diff --git a/fs_mgr/fs_mgr_overlayfs.cpp b/fs_mgr/fs_mgr_overlayfs.cpp
index bb24abf..0f2a75a 100644
--- a/fs_mgr/fs_mgr_overlayfs.cpp
+++ b/fs_mgr/fs_mgr_overlayfs.cpp
@@ -1351,7 +1351,8 @@
     return ret;
 }
 
-bool fs_mgr_overlayfs_setup(const char* mount_point, bool* want_reboot, bool just_disabled_verity) {
+bool fs_mgr_overlayfs_setup(const Fstab& fstab, const char* mount_point, bool* want_reboot,
+                            bool just_disabled_verity) {
     if (!OverlayfsSetupAllowed(/*verbose=*/true)) {
         return false;
     }
@@ -1361,12 +1362,6 @@
         return false;
     }
 
-    Fstab fstab;
-    if (!ReadDefaultFstab(&fstab)) {
-        LOG(ERROR) << "Could not read fstab";
-        return false;
-    }
-
     auto candidates = fs_mgr_overlayfs_candidate_list(fstab);
     for (auto it = candidates.begin(); it != candidates.end();) {
         if (mount_point &&
diff --git a/fs_mgr/fs_mgr_priv_overlayfs.h b/fs_mgr/fs_mgr_priv_overlayfs.h
index 45b954d..2033701 100644
--- a/fs_mgr/fs_mgr_priv_overlayfs.h
+++ b/fs_mgr/fs_mgr_priv_overlayfs.h
@@ -29,8 +29,8 @@
 //
 // If |want_reboot| is non-null, and a reboot is needed to apply overlays, then
 // it will be true on return. The caller is responsible for initializing it.
-bool fs_mgr_overlayfs_setup(const char* mount_point = nullptr, bool* want_reboot = nullptr,
-                            bool just_disabled_verity = true);
+bool fs_mgr_overlayfs_setup(const android::fs_mgr::Fstab& fstab, const char* mount_point = nullptr,
+                            bool* want_reboot = nullptr, bool just_disabled_verity = true);
 
 enum class OverlayfsTeardownResult {
     Ok,
diff --git a/fs_mgr/fs_mgr_remount.cpp b/fs_mgr/fs_mgr_remount.cpp
index 23bc8e8..5fddf86 100644
--- a/fs_mgr/fs_mgr_remount.cpp
+++ b/fs_mgr/fs_mgr_remount.cpp
@@ -289,7 +289,7 @@
         if (fs_mgr_wants_overlayfs(&entry)) {
             bool want_reboot = false;
             bool force = result->disabled_verity;
-            if (!fs_mgr_overlayfs_setup(mount_point.c_str(), &want_reboot, force)) {
+            if (!fs_mgr_overlayfs_setup(*partitions, mount_point.c_str(), &want_reboot, force)) {
                 LOG(ERROR) << "Overlayfs setup for " << mount_point << " failed, skipping";
                 ok = false;
                 it = partitions->erase(it);
@@ -442,7 +442,12 @@
 bool SetupOrTeardownOverlayfs(bool enable) {
     bool want_reboot = false;
     if (enable) {
-        if (!fs_mgr_overlayfs_setup(nullptr, &want_reboot)) {
+        Fstab fstab;
+        if (!ReadDefaultFstab(&fstab)) {
+            LOG(ERROR) << "Could not read fstab.";
+            return want_reboot;
+        }
+        if (!fs_mgr_overlayfs_setup(fstab, nullptr, &want_reboot)) {
             LOG(ERROR) << "Overlayfs setup failed.";
             return want_reboot;
         }