fs_mgr: SkipMountingPartitions() support glob patterns
Enhance skip_mount.cfg to be able to specify glob patterns. Bug: 184132970 Test: GSI Boot test Change-Id: I8e6528e4aff6ea176aa028c3c55d6cedaff3e181
This commit is contained in:
parent
a2b662cf23
commit
2f2fe4afaf
1 changed files with 22 additions and 11 deletions
|
@ -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>
|
||||
|
@ -767,21 +768,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
|
||||
|
|
Loading…
Reference in a new issue