From 22a683c7aa8648fdc66503ae68c8e3e22d7d26aa Mon Sep 17 00:00:00 2001 From: Ahmad Chaudhry Date: Fri, 5 Jul 2024 05:12:21 +0000 Subject: [PATCH] fs_mgr: libfstab: allow recovery.fstab with suffix Some platforms may need different fstab configs. Accordingly, allow recovery init to select a recovery.fstab with a suffix provided through bootconfigs or cmdline during runtime, to make a single recovery.img work on different environments. Change-Id: I0c2f61ffe9ddeb03afc54d8acc43b4917d65b846 --- fs_mgr/libfstab/fstab.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/fs_mgr/libfstab/fstab.cpp b/fs_mgr/libfstab/fstab.cpp index f00e0dc26..21d2e2ef3 100644 --- a/fs_mgr/libfstab/fstab.cpp +++ b/fs_mgr/libfstab/fstab.cpp @@ -520,6 +520,24 @@ std::vector GetEntriesByPred(FstabPtr fstab, const Pred& pre } // namespace +// Return the path to the recovery fstab file. There may be multiple fstab files; +// the one that is returned will be the first that exists of recovery.fstab., +// recovery.fstab., and recovery.fstab.. +std::string GetRecoveryFstabPath() { + for (const char* prop : {"fstab_suffix", "hardware", "hardware.platform"}) { + std::string suffix; + + if (!fs_mgr_get_boot_config(prop, &suffix)) continue; + + std::string fstab_path = "/etc/recovery.fstab." + suffix; + if (access(fstab_path.c_str(), F_OK) == 0) { + return fstab_path; + } + } + + return "/etc/recovery.fstab"; +} + // Return the path to the fstab file. There may be multiple fstab files; the // one that is returned will be the first that exists of fstab., // fstab., and fstab.. The fstab is searched for @@ -529,7 +547,7 @@ std::vector GetEntriesByPred(FstabPtr fstab, const Pred& pre // the system/etc directory is supported too and is the preferred location. std::string GetFstabPath() { if (InRecovery()) { - return "/etc/recovery.fstab"; + return GetRecoveryFstabPath(); } for (const char* prop : {"fstab_suffix", "hardware", "hardware.platform"}) { std::string suffix;