mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 12:05:30 +00:00
No greedy match to find parent mount point
This fixes /sys is considered as a parent mount point of /system
This commit is contained in:
parent
b9213b7043
commit
1aade8f8a8
@ -3,7 +3,7 @@
|
||||
#include <sys/sysmacros.h>
|
||||
#include <linux/input.h>
|
||||
#include <libgen.h>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include <magisk.hpp>
|
||||
@ -54,14 +54,17 @@ static void mount_mirrors() {
|
||||
if (auto mirror_dir = MAGISKTMP + "/" MIRRDIR; !mount_mirror("/", mirror_dir)) {
|
||||
LOGI("fallback to mount subtree\n");
|
||||
// rootfs may fail, fallback to bind mount each mount point
|
||||
std::vector<string> mounted_dirs {{ MAGISKTMP }};
|
||||
set<string, greater<>> mounted_dirs {{ MAGISKTMP }};
|
||||
for (const auto &info: parse_mount_info("self")) {
|
||||
if (info.type == "rootfs"sv) continue;
|
||||
bool mounted = std::any_of(mounted_dirs.begin(), mounted_dirs.end(), [&](const auto &dir) {
|
||||
return str_starts(info.target, dir);
|
||||
});
|
||||
if (!mounted && mount_mirror(info.target, mirror_dir + info.target)) {
|
||||
mounted_dirs.emplace_back(info.target);
|
||||
// the greatest mount point that less than info.target, which is possibly a parent
|
||||
if (auto last_mount = mounted_dirs.upper_bound(info.target);
|
||||
last_mount != mounted_dirs.end() && info.target.starts_with(*last_mount + '/')) {
|
||||
continue;
|
||||
}
|
||||
if (mount_mirror(info.target, mirror_dir + info.target)) {
|
||||
LOGD("%-8s: %s <- %s\n", "rbind", (mirror_dir + info.target).data(), info.target.data());
|
||||
mounted_dirs.insert(info.target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,12 @@ void revert_unmount() {
|
||||
|
||||
if (targets.empty()) return;
|
||||
|
||||
for (auto last_target = targets.cbegin(), iter = next(targets.cbegin()); iter != targets.cend();) {
|
||||
if (iter->starts_with(*last_target)) {
|
||||
auto last_target = *targets.cbegin() + '/';
|
||||
for (auto iter = next(targets.cbegin()); iter != targets.cend();) {
|
||||
if (iter->starts_with(last_target)) {
|
||||
iter = targets.erase(iter);
|
||||
} else {
|
||||
last_target = iter++;
|
||||
last_target = *iter++ + '/';
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user