diff options
author | Yo Chiang <yochiang@google.com> | 2021-04-07 05:38:47 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-04-07 05:38:47 +0000 |
commit | d56f6e14cd698a1d9fdafc8e7a273e902c51ebd3 (patch) | |
tree | c98ee7d781b61e2930680e13da57cd0a2cb9009a | |
parent | 908ec8b03bc8040e140deb2efb044500ba0ccab7 (diff) | |
parent | b20e9a36061f324f1775d100663779a962b033eb (diff) | |
download | core-d56f6e14cd698a1d9fdafc8e7a273e902c51ebd3.tar.gz |
Merge "fs_mgr: SkipMountingPartitions() support glob patterns" am: b20e9a3606
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1660038
Change-Id: I5c2bcaa4bd5ade9efb43e2e8449aca75a706a93b
-rw-r--r-- | fs_mgr/fs_mgr_fstab.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/fs_mgr/fs_mgr_fstab.cpp b/fs_mgr/fs_mgr_fstab.cpp index 950fc9676..ad48dd105 100644 --- a/fs_mgr/fs_mgr_fstab.cpp +++ b/fs_mgr/fs_mgr_fstab.cpp @@ -17,6 +17,7 @@ #include <ctype.h> #include <dirent.h> #include <errno.h> +#include <fnmatch.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -779,21 +780,31 @@ bool SkipMountingPartitions(Fstab* fstab, bool verbose) { return true; } - for (const auto& skip_mount_point : Split(skip_config, "\n")) { - if (skip_mount_point.empty()) { + std::vector<std::string> skip_mount_patterns; + for (const auto& line : Split(skip_config, "\n")) { + if (line.empty() || StartsWith(line, "#")) { continue; } - auto it = std::remove_if(fstab->begin(), fstab->end(), - [&skip_mount_point](const auto& entry) { - return entry.mount_point == skip_mount_point; - }); - if (it == fstab->end()) continue; - fstab->erase(it, fstab->end()); - if (verbose) { - LINFO << "Skip mounting partition: " << skip_mount_point; - } + skip_mount_patterns.push_back(line); } + // Returns false if mount_point matches any of the skip mount patterns, so that the FstabEntry + // would be partitioned to the second group. + auto glob_pattern_mismatch = [&skip_mount_patterns](const FstabEntry& entry) -> bool { + for (const auto& pattern : skip_mount_patterns) { + if (!fnmatch(pattern.c_str(), entry.mount_point.c_str(), 0 /* flags */)) { + return false; + } + } + return true; + }; + auto remove_from = std::stable_partition(fstab->begin(), fstab->end(), glob_pattern_mismatch); + if (verbose) { + for (auto it = remove_from; it != fstab->end(); ++it) { + LINFO << "Skip mounting mountpoint: " << it->mount_point; + } + } + fstab->erase(remove_from, fstab->end()); return true; } #endif |