Use mountinfo for revert unmount

This commit is contained in:
LoveSy
2023-02-17 12:36:19 -08:00
committed by John Wu
parent b249832571
commit 79a85f5937
3 changed files with 109 additions and 20 deletions
+9 -20
View File
@@ -12,30 +12,19 @@ static void lazy_unmount(const char* mountpoint) {
LOGD("denylist: Unmounted (%s)\n", mountpoint);
}
#define TMPFS_MNT(dir) (mentry->mnt_type == "tmpfs"sv && str_starts(mentry->mnt_dir, "/" #dir))
void revert_unmount() {
vector<string> targets;
// Unmount dummy skeletons and MAGISKTMP
targets.push_back(MAGISKTMP);
parse_mnt("/proc/self/mounts", [&](mntent *mentry) {
if (TMPFS_MNT(system) || TMPFS_MNT(vendor) || TMPFS_MNT(product) || TMPFS_MNT(system_ext))
targets.emplace_back(mentry->mnt_dir);
return true;
});
// since mirror nodes are always mounted under skeleton, we don't have to specifically unmount
for (auto &info: parse_mount_info("self")) {
if (info.target.starts_with(MAGISKTMP) || // things in magisktmp
info.root.starts_with("/adb/modules") || // module nodes
info.root.starts_with("/" INTLROOT)) { // skeleton
targets.push_back(info.target);
}
}
for (auto &s : reversed(targets))
lazy_unmount(s.data());
targets.clear();
// Unmount all Magisk created mounts
parse_mnt("/proc/self/mounts", [&](mntent *mentry) {
if (str_contains(mentry->mnt_fsname, BLOCKDIR))
targets.emplace_back(mentry->mnt_dir);
return true;
});
for (auto &s : reversed(targets))
for (auto &s : targets)
lazy_unmount(s.data());
}