From 6cdee65b8b13760535c52c482a318d6e62b4bcda Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Wed, 24 Apr 2024 14:17:20 -0700 Subject: [PATCH] Allow querying for fstab for a mount point with fstype Test: th Bug: 293313353 Change-Id: I8e12c465d0a3e886fcfa0cebf546b145b785c220 --- fs_mgr/libfstab/fstab.cpp | 8 ++++++++ fs_mgr/libfstab/include/fstab/fstab.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/fs_mgr/libfstab/fstab.cpp b/fs_mgr/libfstab/fstab.cpp index 6fa22fee5..6273ee2e8 100644 --- a/fs_mgr/libfstab/fstab.cpp +++ b/fs_mgr/libfstab/fstab.cpp @@ -849,6 +849,14 @@ std::vector GetEntriesForMountPoint(Fstab* fstab, const std::string [&path](const FstabEntry& entry) { return entry.mount_point == path; }); } +FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string_view path, + const std::string_view fstype) { + auto&& vec = GetEntriesByPred(fstab, [&path, fstype](const FstabEntry& entry) { + return entry.mount_point == path && entry.fs_type == fstype; + }); + return vec.empty() ? nullptr : vec.front(); +} + std::vector GetEntriesForMountPoint(const Fstab* fstab, const std::string& path) { return GetEntriesByPred(fstab, diff --git a/fs_mgr/libfstab/include/fstab/fstab.h b/fs_mgr/libfstab/include/fstab/fstab.h index 5e4019ca1..dea723831 100644 --- a/fs_mgr/libfstab/include/fstab/fstab.h +++ b/fs_mgr/libfstab/include/fstab/fstab.h @@ -108,6 +108,9 @@ std::vector GetEntriesForMountPoint(Fstab* fstab, const std::string FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string& path); const FstabEntry* GetEntryForMountPoint(const Fstab* fstab, const std::string& path); +FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string_view path, + const std::string_view fstype); + // This method builds DSU fstab entries and transfer the fstab. // // fstab points to the unmodified fstab.