diff options
Diffstat (limited to 'fs_mgr/fs_mgr_roots.cpp')
-rw-r--r-- | fs_mgr/fs_mgr_roots.cpp | 50 |
1 files changed, 16 insertions, 34 deletions
diff --git a/fs_mgr/fs_mgr_roots.cpp b/fs_mgr/fs_mgr_roots.cpp index 2ad8125e7..fdaffbeb0 100644 --- a/fs_mgr/fs_mgr_roots.cpp +++ b/fs_mgr/fs_mgr_roots.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include "android-base/file.h" #include "fs_mgr/roots.h" #include <sys/mount.h> @@ -40,26 +39,18 @@ FstabEntry* GetEntryForPath(Fstab* fstab, const std::string& path) { while (true) { auto entry = GetEntryForMountPoint(fstab, str); if (entry != nullptr) return entry; - str = android::base::Dirname(str); - if (!str.compare(".") || !str.compare("/")) break; + if (str == "/") break; + auto slash = str.find_last_of('/'); + if (slash == std::string::npos) break; + if (slash == 0) { + str = "/"; + } else { + str = str.substr(0, slash); + } } return nullptr; } -std::vector<FstabEntry*> GetEntriesForPath(Fstab* fstab, const std::string& path) { - std::vector<FstabEntry*> entries; - if (path.empty()) return entries; - - std::string str(path); - while (true) { - entries = GetEntriesForMountPoint(fstab, str); - if (!entries.empty()) return entries; - str = android::base::Dirname(str); - if (!str.compare(".") || !str.compare("/")) break; - } - return entries; -} - enum class MountState { ERROR = -1, NOT_MOUNTED = 0, @@ -80,7 +71,12 @@ static MountState GetMountState(const std::string& mount_point) { return MountState::NOT_MOUNTED; } -bool TryPathMount(FstabEntry* rec, const std::string& mount_pt) { +bool EnsurePathMounted(Fstab* fstab, const std::string& path, const std::string& mount_pt) { + auto rec = GetEntryForPath(fstab, path); + if (rec == nullptr) { + LERROR << "unknown volume for path [" << path << "]"; + return false; + } if (rec->fs_type == "ramdisk") { // The ramdisk is always mounted. return true; @@ -125,7 +121,8 @@ bool TryPathMount(FstabEntry* rec, const std::string& mount_pt) { int result = fs_mgr_do_mount_one(*rec, mount_point); if (result == -1 && rec->fs_mgr_flags.formattable) { PERROR << "Failed to mount " << mount_point << "; formatting"; - if (fs_mgr_do_format(*rec) != 0) { + bool crypt_footer = rec->is_encryptable() && rec->key_loc == "footer"; + if (fs_mgr_do_format(*rec, crypt_footer) != 0) { PERROR << "Failed to format " << mount_point; return false; } @@ -139,21 +136,6 @@ bool TryPathMount(FstabEntry* rec, const std::string& mount_pt) { return true; } -bool EnsurePathMounted(Fstab* fstab, const std::string& path, const std::string& mount_point) { - auto entries = GetEntriesForPath(fstab, path); - if (entries.empty()) { - LERROR << "unknown volume for path [" << path << "]"; - return false; - } - - for (auto entry : entries) { - if (TryPathMount(entry, mount_point)) return true; - } - - LERROR << "Failed to mount for path [" << path << "]"; - return false; -} - bool EnsurePathUnmounted(Fstab* fstab, const std::string& path) { auto rec = GetEntryForPath(fstab, path); if (rec == nullptr) { |