Skip to content

Commit

Permalink
Rename dir name
Browse files Browse the repository at this point in the history
  • Loading branch information
vvb2060 committed Jan 7, 2024
1 parent bf98ce4 commit 40b336a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/src/main/res/raw/manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions native/src/core/bootstages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions native/src/include/consts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
#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"
#define ROOTOVL INTLROOT "/rootdir"
#define SHELLPTS INTLROOT "/pts"
#define SHELLPTS DEVICEDIR "/pts"
#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 };

Expand Down
2 changes: 1 addition & 1 deletion native/src/include/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ macro_rules! INTLROOT {
#[macro_export]
macro_rules! LOG_PIPE {
() => {
concat!($crate::INTLROOT!(), "/log")
concat!($crate::INTLROOT!(), "/device/log")
};
}

Expand Down
18 changes: 7 additions & 11 deletions native/src/init/mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ static void switch_root(const string &path) {
frm_rf(root);
}

#define PREINITMNT MIRRDIR "/preinit"

static void mount_preinit_dir(string preinit_dev) {
if (preinit_dev.empty()) return;
strcpy(blk_info.partname, preinit_dev.data());
Expand All @@ -134,13 +132,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
for (auto &info : parse_mount_info("self")) {
if (info.root == "/" && info.device == dev) {
// Already mounted, just bind mount
xmount(info.target.data(), PREINITMNT, nullptr, MS_BIND, nullptr);
xmount(info.target.data(), MIRRDIR, nullptr, MS_BIND, nullptr);
mounted = true;
break;
}
Expand All @@ -150,9 +148,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)) {
Expand All @@ -161,7 +159,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);
Expand Down Expand Up @@ -262,9 +260,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);

Expand Down
9 changes: 4 additions & 5 deletions native/src/init/rootdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ void MagiskInit::parse_config_file() {
});
}

#define ROOTMIR MIRRDIR "/system_root"
#define NEW_INITRC_DIR "/system/etc/init/hw"

void MagiskInit::patch_ro_root() {
Expand All @@ -266,10 +265,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);
Expand Down
4 changes: 1 addition & 3 deletions scripts/avd_magisk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 40b336a

Please sign in to comment.