mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-17 14:48:29 +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 <sys/sysmacros.h>
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <vector>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <magisk.hpp>
|
#include <magisk.hpp>
|
||||||
@ -54,14 +54,17 @@ static void mount_mirrors() {
|
|||||||
if (auto mirror_dir = MAGISKTMP + "/" MIRRDIR; !mount_mirror("/", mirror_dir)) {
|
if (auto mirror_dir = MAGISKTMP + "/" MIRRDIR; !mount_mirror("/", mirror_dir)) {
|
||||||
LOGI("fallback to mount subtree\n");
|
LOGI("fallback to mount subtree\n");
|
||||||
// rootfs may fail, fallback to bind mount each mount point
|
// 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")) {
|
for (const auto &info: parse_mount_info("self")) {
|
||||||
if (info.type == "rootfs"sv) continue;
|
if (info.type == "rootfs"sv) continue;
|
||||||
bool mounted = std::any_of(mounted_dirs.begin(), mounted_dirs.end(), [&](const auto &dir) {
|
// the greatest mount point that less than info.target, which is possibly a parent
|
||||||
return str_starts(info.target, dir);
|
if (auto last_mount = mounted_dirs.upper_bound(info.target);
|
||||||
});
|
last_mount != mounted_dirs.end() && info.target.starts_with(*last_mount + '/')) {
|
||||||
if (!mounted && mount_mirror(info.target, mirror_dir + info.target)) {
|
continue;
|
||||||
mounted_dirs.emplace_back(info.target);
|
}
|
||||||
|
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;
|
if (targets.empty()) return;
|
||||||
|
|
||||||
for (auto last_target = targets.cbegin(), iter = next(targets.cbegin()); iter != targets.cend();) {
|
auto last_target = *targets.cbegin() + '/';
|
||||||
if (iter->starts_with(*last_target)) {
|
for (auto iter = next(targets.cbegin()); iter != targets.cend();) {
|
||||||
|
if (iter->starts_with(last_target)) {
|
||||||
iter = targets.erase(iter);
|
iter = targets.erase(iter);
|
||||||
} else {
|
} else {
|
||||||
last_target = iter++;
|
last_target = *iter++ + '/';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user