diff --git a/README.md b/README.md index 08c4e45..20f10cd 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ export MAGISKTMP="$(magisk --path)" ## Donate -- I am having financial difficulties. If you like my work, you can donate at http://paypal.me/huskydg +- If you like my work, you can donate at http://paypal.me/huskydg ## Source code diff --git a/magisk-module/customize.sh b/magisk-module/customize.sh index 74a8388..0255649 100644 --- a/magisk-module/customize.sh +++ b/magisk-module/customize.sh @@ -132,7 +132,6 @@ if [ "$KSU" == true ] && [ "$KSU_VER_CODE" -ge 11210 ]; then mv -f "$MODPATH/post-fs-data.sh" "$MODPATH/post-mount.sh" fi -ui_print "- I am having financial difficulties" ui_print "- If you like my work, you can donate at http://paypal.me/huskydg" ui_print diff --git a/native/jni/main.cpp b/native/jni/main.cpp index 2d23169..2351e3c 100644 --- a/native/jni/main.cpp +++ b/native/jni/main.cpp @@ -26,31 +26,25 @@ const char *overlay_name = "overlay"; static std::vector collect_mounts() { // sort mountinfo, skip unnecessary mounts std::vector mountinfo; - do { - auto current_mount_info = parse_mount_info("self"); - std::reverse(current_mount_info.begin(), current_mount_info.end()); - for (auto &info : current_mount_info) { - for (auto &part : SYSTEM_PARTITIONS) { - if (starts_with(info.target.data(), string(part + "/").data()) || info.target == part) { - for (auto &s : reversed(mountinfo)) { - // /a/b/c <--- under a (skip) - // /a - // /a/b - if (s.target == info.target || starts_with(info.target.data(), string(s.target + "/").data())) { - LOGD("mountinfo: mountpoint %s is hidden under %s\n", info.target.data(), s.target.data()); - goto next_mountpoint; - } - } - LOGD("mountinfo: device (%u:%u)%s on %s type %s (%s)\n", major(info.device), minor(info.device), - (info.root != "/")? info.root.data() : "", info.target.data(), info.type.data(), info.fs_option.data()); - mountinfo.emplace_back(info); - break; + auto current_mount_info = parse_mount_info("self"); + std::reverse(current_mount_info.begin(), current_mount_info.end()); + for (auto &info : current_mount_info) { + for (auto &part : SYSTEM_PARTITIONS) + if (starts_with(info.target.data(), string(part + "/").data()) || info.target == part) { + for (auto &s : reversed(mountinfo)) { + if (s.target == info.target || starts_with(info.target.data(), string(s.target + "/").data())) { + LOGD("mountinfo: mountpoint %s is hidden under %s\n", info.target.data(), s.target.data()); + goto next_mountpoint; } } - next_mountpoint: - continue; + LOGD("mountinfo: device (%u:%u)%s on %s type %s (%s)\n", major(info.device), minor(info.device), + (info.root != "/")? info.root.data() : "", info.target.data(), info.type.data(), info.fs_option.data()); + mountinfo.emplace_back(info); + break; } - } while(false); + next_mountpoint: + continue; + } return mountinfo; } @@ -103,18 +97,6 @@ static int unmount_ksu_overlay() { return 0; } -static bool unshare_mount(const char *mnt_point) { - int fd = open(mnt_point, O_PATH); - if (fd < 0) - return false; - string fd_path = "/proc/self/fd/"; - fd_path += std::to_string(fd); - bool ret = !mount("", fd_path.data(), nullptr, MS_PRIVATE | MS_REC, nullptr) && - !mount("", fd_path.data(), nullptr, MS_SHARED | MS_REC, nullptr); - close(fd); - return ret; -} - static std::string get_lowerdirs(std::vector list, const char *sub) { std::string lowerdir = ""; for (auto it = list.begin(); it != list.end(); it++) { @@ -361,13 +343,13 @@ int main(int argc, const char **argv) { std::string upperdir = upper + info; std::string workerdir = worker + "/" + std::to_string(st.st_dev) + "/" + std::to_string(st.st_ino); std::string masterdir = overlay_tmpdir + "/master" + info; - bool module_node_is_dir = is_dir(masterdir.data()); - bool module_node_exist = fexist(masterdir.data()); - bool upper_node_is_dir = is_dir(upperdir.data()); - bool upper_node_exist = fexist(upperdir.data()); +#define module_node_is_dir (is_dir(masterdir.data())) +#define module_node_exist (fexist(masterdir.data())) +#define upper_node_is_dir (is_dir(upperdir.data())) +#define upper_node_exist (fexist(upperdir.data())) if (lstat(tmp_mount.data(), &st) != 0 || // target does not exist, it could be deleted by modules - (((upper_node_exist && !upper_node_is_dir) || - (!upper_node_exist && module_node_exist && !module_node_is_dir)) && S_ISDIR(st.st_mode))) // module add file but original is folder + (((upper_node_exist && !upper_node_is_dir) || // in upperdir, it is file + (!upper_node_exist && module_node_exist && !module_node_is_dir)) && S_ISDIR(st.st_mode))) // module node is file but in lowerdir it is folder continue; for (auto &s : mount_list) { // only care about mountpoint under overlayfs mounted subdirectories @@ -495,8 +477,6 @@ int main(int argc, const char **argv) { mounted.clear(); goto subtree_mounts; // fall back to mount subtree } - if (!unshare_mount(info.data())) - LOGE("unshare mount failed: [%s]\n", info.data()); mounted.emplace_back(info); } goto inject_mirrors; @@ -518,8 +498,6 @@ int main(int argc, const char **argv) { LOGE("mount failed, skip!\n"); continue; } - if (!unshare_mount(buf + strlen(overlay_tmpdir.data()))) - LOGE("unshare mount failed: [%s]\n", buf + strlen(overlay_tmpdir.data())); mounted.emplace_back(buf + strlen(overlay_tmpdir.data())); } closedir(dirfp); @@ -533,8 +511,6 @@ int main(int argc, const char **argv) { std::string mirror_dir = string(mirrors) + info; if (access(mirror_dir.data(), F_OK) == 0) { xmount(info.data(), mirror_dir.data(), nullptr, MS_BIND | MS_REC, nullptr); - if (!unshare_mount(mirror_dir.data())) - LOGE("unshare mount failed: [%s]\n", mirror_dir.data()); } } }