diff --git a/app/src/main/res/raw/manager.sh b/app/src/main/res/raw/manager.sh index 37bb5b35c..1d2342909 100644 --- a/app/src/main/res/raw/manager.sh +++ b/app/src/main/res/raw/manager.sh @@ -14,7 +14,7 @@ env_check() { [ -f "$MAGISKBIN/magiskpolicy" ] || return 1 fi if [ "$2" -ge 25210 ]; then - [ -b "$MAGISKTMP/.magisk/block/preinit" ] || return 2 + [ -b "$MAGISKTMP/.magisk/device/preinit" ] || [ -b "$MAGISKTMP/.magisk/block/preinit" ] || return 2 fi grep -xqF "MAGISK_VER='$1'" "$MAGISKBIN/util_functions.sh" || return 3 grep -xqF "MAGISK_VER_CODE=$2" "$MAGISKBIN/util_functions.sh" || return 3 diff --git a/native/src/core/bootstages.cpp b/native/src/core/bootstages.cpp index 4ba394389..19586bf34 100644 --- a/native/src/core/bootstages.cpp +++ b/native/src/core/bootstages.cpp @@ -72,6 +72,7 @@ static void setup_mounts() { // Prepare worker ssprintf(path, sizeof(path), "%s/" WORKERDIR, get_magisk_tmp()); + xmkdir(path, 0); xmount("worker", path, "tmpfs", 0, "mode=755"); xmount(nullptr, path, nullptr, MS_PRIVATE, nullptr); } diff --git a/native/src/include/consts.hpp b/native/src/include/consts.hpp index 7df3f96a6..4dd7952c2 100644 --- a/native/src/include/consts.hpp +++ b/native/src/include/consts.hpp @@ -13,8 +13,8 @@ #define INTLROOT ".magisk" #define MIRRDIR INTLROOT "/mirror" #define PREINITMIRR INTLROOT "/preinit" -#define BLOCKDIR INTLROOT "/block" -#define PREINITDEV BLOCKDIR "/preinit" +#define DEVICEDIR INTLROOT "/device" +#define PREINITDEV DEVICEDIR "/preinit" #define WORKERDIR INTLROOT "/worker" #define MODULEMNT INTLROOT "/modules" #define BBPATH INTLROOT "/busybox" @@ -23,8 +23,8 @@ #define ROOTMNT ROOTOVL "/.mount_list" #define SELINUXMOCK INTLROOT "/selinux" #define MAIN_CONFIG INTLROOT "/config" -#define MAIN_SOCKET INTLROOT "/socket" -#define LOG_PIPE INTLROOT "/log" +#define MAIN_SOCKET DEVICEDIR "/socket" +#define LOG_PIPE DEVICEDIR "/log" constexpr const char *applet_names[] = { "su", "resetprop", nullptr }; diff --git a/native/src/include/consts.rs b/native/src/include/consts.rs index 19fc45606..ac5ec6b8e 100644 --- a/native/src/include/consts.rs +++ b/native/src/include/consts.rs @@ -17,7 +17,7 @@ macro_rules! INTLROOT { #[macro_export] macro_rules! LOG_PIPE { () => { - concat!($crate::INTLROOT!(), "/log") + concat!($crate::INTLROOT!(), "/device/log") }; } diff --git a/native/src/init/mount.cpp b/native/src/init/mount.cpp index 63276901c..b00a836a3 100644 --- a/native/src/init/mount.cpp +++ b/native/src/init/mount.cpp @@ -100,8 +100,6 @@ static dev_t setup_block() { return 0; } -#define PREINITMNT MIRRDIR "/preinit" - static void mount_preinit_dir(string preinit_dev) { if (preinit_dev.empty()) return; strcpy(blk_info.partname, preinit_dev.data()); @@ -111,13 +109,13 @@ static void mount_preinit_dir(string preinit_dev) { LOGE("Cannot find preinit %s, abort!\n", preinit_dev.data()); return; } - xmkdir(PREINITMNT, 0); + xmkdir(MIRRDIR, 0); bool mounted = false; // First, find if it is already mounted std::string mnt_point; if (rust::is_device_mounted(dev, mnt_point)) { // Already mounted, just bind mount - xmount(mnt_point.data(), PREINITMNT, nullptr, MS_BIND, nullptr); + xmount(mnt_point.data(), MIRRDIR, nullptr, MS_BIND, nullptr); mounted = true; } @@ -125,9 +123,9 @@ static void mount_preinit_dir(string preinit_dev) { // as read-only, or else the kernel might crash due to crappy drivers. // After the device boots up, magiskd will properly bind mount the correct partition // on to PREINITMIRR as writable. For more details, check bootstages.cpp - if (mounted || mount(PREINITDEV, PREINITMNT, "ext4", MS_RDONLY, nullptr) == 0 || - mount(PREINITDEV, PREINITMNT, "f2fs", MS_RDONLY, nullptr) == 0) { - string preinit_dir = resolve_preinit_dir(PREINITMNT); + if (mounted || mount(PREINITDEV, MIRRDIR, "ext4", MS_RDONLY, nullptr) == 0 || + mount(PREINITDEV, MIRRDIR, "f2fs", MS_RDONLY, nullptr) == 0) { + string preinit_dir = resolve_preinit_dir(MIRRDIR); // Create bind mount xmkdirs(PREINITMIRR, 0); if (access(preinit_dir.data(), F_OK)) { @@ -136,7 +134,7 @@ static void mount_preinit_dir(string preinit_dev) { LOGD("preinit: %s\n", preinit_dir.data()); xmount(preinit_dir.data(), PREINITMIRR, nullptr, MS_BIND, nullptr); } - xumount2(PREINITMNT, MNT_DETACH); + xumount2(MIRRDIR, MNT_DETACH); } else { PLOGE("Failed to mount preinit %s\n", preinit_dev.data()); unlink(PREINITDEV); @@ -237,9 +235,7 @@ void MagiskInit::setup_tmp(const char *path) { chdir("/data"); xmkdir(INTLROOT, 0711); - xmkdir(MIRRDIR, 0); - xmkdir(BLOCKDIR, 0); - xmkdir(WORKERDIR, 0); + xmkdir(DEVICEDIR, 0711); mount_preinit_dir(preinit_dev); diff --git a/native/src/init/rootdir.cpp b/native/src/init/rootdir.cpp index e1df06acf..58f3f8f25 100644 --- a/native/src/init/rootdir.cpp +++ b/native/src/init/rootdir.cpp @@ -13,7 +13,6 @@ using namespace std; static vector rc_list; -#define ROOTMIR MIRRDIR "/system_root" #define NEW_INITRC_DIR "/system/etc/init/hw" #define INIT_RC "init.rc" @@ -250,10 +249,10 @@ void MagiskInit::patch_ro_root() { if (tmp_dir == "/sbin") { // Recreate original sbin structure - xmkdir(ROOTMIR, 0755); - xmount("/", ROOTMIR, nullptr, MS_BIND, nullptr); - recreate_sbin(ROOTMIR "/sbin", true); - xumount2(ROOTMIR, MNT_DETACH); + xmkdir(MIRRDIR, 0755); + xmount("/", MIRRDIR, nullptr, MS_BIND, nullptr); + recreate_sbin(MIRRDIR "/sbin", true); + xumount2(MIRRDIR, MNT_DETACH); } else { // Restore debug_ramdisk xmount("/data/debug_ramdisk", "/debug_ramdisk", nullptr, MS_MOVE, nullptr); diff --git a/scripts/avd_magisk.sh b/scripts/avd_magisk.sh index 2b6ba4702..1746a3493 100755 --- a/scripts/avd_magisk.sh +++ b/scripts/avd_magisk.sh @@ -138,9 +138,7 @@ ln -s ./magisk $MAGISKTMP/su ln -s ./magisk $MAGISKTMP/resetprop ln -s ./magiskpolicy $MAGISKTMP/supolicy -mkdir -p $MAGISKTMP/.magisk/mirror -mkdir $MAGISKTMP/.magisk/block -mkdir $MAGISKTMP/.magisk/worker +mkdir -p $MAGISKTMP/.magisk/device touch $MAGISKTMP/.magisk/config export MAGISKTMP