Merge "libfstab: Add const overload of GetEntryForMountPoint()"
This commit is contained in:
commit
acac60d5a4
2 changed files with 32 additions and 19 deletions
|
@ -488,13 +488,21 @@ std::set<std::string> ExtraBootDevices(const Fstab& fstab) {
|
|||
return boot_devices;
|
||||
}
|
||||
|
||||
template <typename Pred>
|
||||
std::vector<FstabEntry*> GetEntriesByPred(Fstab* fstab, const Pred& pred) {
|
||||
// Helper class that maps Fstab* -> FstabEntry; const Fstab* -> const FstabEntry.
|
||||
template <typename FstabPtr>
|
||||
struct FstabPtrEntry {
|
||||
using is_const_fstab = std::is_const<std::remove_pointer_t<FstabPtr>>;
|
||||
using type = std::conditional_t<is_const_fstab::value, const FstabEntry, FstabEntry>;
|
||||
};
|
||||
|
||||
template <typename FstabPtr, typename FstabPtrEntryType = typename FstabPtrEntry<FstabPtr>::type,
|
||||
typename Pred>
|
||||
std::vector<FstabPtrEntryType*> GetEntriesByPred(FstabPtr fstab, const Pred& pred) {
|
||||
if (fstab == nullptr) {
|
||||
return {};
|
||||
}
|
||||
std::vector<FstabEntry*> entries;
|
||||
for (auto&& entry : *fstab) {
|
||||
std::vector<FstabPtrEntryType*> entries;
|
||||
for (FstabPtrEntryType& entry : *fstab) {
|
||||
if (pred(entry)) {
|
||||
entries.push_back(&entry);
|
||||
}
|
||||
|
@ -835,25 +843,27 @@ bool ReadDefaultFstab(Fstab* fstab) {
|
|||
return !fstab->empty();
|
||||
}
|
||||
|
||||
FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string& path) {
|
||||
if (fstab == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (auto& entry : *fstab) {
|
||||
if (entry.mount_point == path) {
|
||||
return &entry;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<FstabEntry*> GetEntriesForMountPoint(Fstab* fstab, const std::string& path) {
|
||||
return GetEntriesByPred(fstab,
|
||||
[&path](const FstabEntry& entry) { return entry.mount_point == path; });
|
||||
}
|
||||
|
||||
std::vector<const FstabEntry*> GetEntriesForMountPoint(const Fstab* fstab,
|
||||
const std::string& path) {
|
||||
return GetEntriesByPred(fstab,
|
||||
[&path](const FstabEntry& entry) { return entry.mount_point == path; });
|
||||
}
|
||||
|
||||
FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string& path) {
|
||||
std::vector<FstabEntry*> entries = GetEntriesForMountPoint(fstab, path);
|
||||
return entries.empty() ? nullptr : entries.front();
|
||||
}
|
||||
|
||||
const FstabEntry* GetEntryForMountPoint(const Fstab* fstab, const std::string& path) {
|
||||
std::vector<const FstabEntry*> entries = GetEntriesForMountPoint(fstab, path);
|
||||
return entries.empty() ? nullptr : entries.front();
|
||||
}
|
||||
|
||||
std::set<std::string> GetBootDevices() {
|
||||
// First check bootconfig, then kernel commandline, then the device tree
|
||||
std::string dt_file_name = get_android_dt_dir() + "/boot_devices";
|
||||
|
|
|
@ -105,10 +105,13 @@ bool ReadFstabFromDt(Fstab* fstab, bool verbose = true);
|
|||
bool ReadDefaultFstab(Fstab* fstab);
|
||||
bool SkipMountingPartitions(Fstab* fstab, bool verbose = false);
|
||||
|
||||
FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string& path);
|
||||
// The Fstab can contain multiple entries for the same mount point with different configurations.
|
||||
std::vector<FstabEntry*> GetEntriesForMountPoint(Fstab* fstab, const std::string& path);
|
||||
|
||||
// Like GetEntriesForMountPoint() but return only the first entry or nullptr if no entry is found.
|
||||
FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string& path);
|
||||
const FstabEntry* GetEntryForMountPoint(const Fstab* fstab, const std::string& path);
|
||||
|
||||
// This method builds DSU fstab entries and transfer the fstab.
|
||||
//
|
||||
// fstab points to the unmodified fstab.
|
||||
|
|
Loading…
Reference in a new issue