From 6b313de3e3b09cf194e284e30c781025472d3980 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 29 Aug 2018 10:44:33 -0700 Subject: [PATCH] fs_mgr: fs_mgr_overlayfs_mount_scratch try alternate Harden fs_mgr_overlayfs_mount_scratch to try alternate filesystem mount type just in case (f2fs <-> ext4). Cleanup remove any unnecessary string literals. Test: manual Bug: 109821105 Change-Id: I36ea974ffeeae392553fff779939dc76a12ab96e --- fs_mgr/fs_mgr_overlayfs.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs_mgr/fs_mgr_overlayfs.cpp b/fs_mgr/fs_mgr_overlayfs.cpp index bca233755..767b73a67 100644 --- a/fs_mgr/fs_mgr_overlayfs.cpp +++ b/fs_mgr/fs_mgr_overlayfs.cpp @@ -589,8 +589,18 @@ bool fs_mgr_overlayfs_mount_scratch(const std::string& device_path, const std::s fsrec->fs_type = strdup(mnt_type.c_str()); fsrec->flags = MS_RELATIME; fsrec->fs_options = strdup(""); - auto mounted = fs_mgr_do_mount_one(fsrec) == 0; auto save_errno = errno; + auto mounted = fs_mgr_do_mount_one(fsrec) == 0; + if (!mounted) { + free(fsrec->fs_type); + if (mnt_type == "f2fs") { + fsrec->fs_type = strdup("ext4"); + } else { + fsrec->fs_type = strdup("f2fs"); + } + mounted = fs_mgr_do_mount_one(fsrec) == 0; + if (!mounted) save_errno = errno; + } setfscreatecon(nullptr); if (!mounted) rmdir(kScratchMountPoint.c_str()); errno = save_errno; @@ -600,6 +610,7 @@ bool fs_mgr_overlayfs_mount_scratch(const std::string& device_path, const std::s const std::string kMkF2fs("/system/bin/make_f2fs"); const std::string kMkExt4("/system/bin/mke2fs"); +// Only a suggestion for _first_ try during mounting std::string fs_mgr_overlayfs_scratch_mount_type() { if (!access(kMkF2fs.c_str(), X_OK)) return "f2fs"; if (!access(kMkExt4.c_str(), X_OK)) return "ext4";