Use our own device nodes for mirrors

This commit is contained in:
topjohnwu 2019-04-07 23:03:49 -04:00
parent bc286fd4d3
commit dab32e1599
3 changed files with 17 additions and 22 deletions

View File

@ -301,19 +301,17 @@ static int bind_mount(const char *from, const char *to, bool log) {
return ret; return ret;
} }
char *system_block; #define MIRRMNT(part) MIRRDIR "/" #part
char *vendor_block; #define PARTBLK(part) BLOCKDIR "/" #part
char *data_block;
static char *&system_root_block = system_block;
#define MIRRPNT(part) MIRRDIR "/" #part #define mount_mirror(part, flag) { \
sscanf(line.data(), "%s %*s %s", buf, buf2); \
#define mount_mirror(part, flag) \ xstat(buf, &st); \
sscanf(line.data(), "%s %*s %s", buf, buf2); \ mknod(PARTBLK(part), S_IFBLK | 0600, st.st_rdev); \
part##_block = strdup(buf); \ xmkdir(MIRRMNT(part), 0755); \
xmkdir(MIRRPNT(part), 0755); \ xmount(PARTBLK(part), MIRRMNT(part), buf2, flag, nullptr); \
xmount(part##_block, MIRRPNT(part), buf2, flag, nullptr); \ VLOGI("mount", PARTBLK(part), MIRRMNT(part)); \
VLOGI("mount", part##_block, MIRRPNT(part)) }
static bool magisk_env() { static bool magisk_env() {
LOGI("* Initializing Magisk environment\n"); LOGI("* Initializing Magisk environment\n");
@ -348,7 +346,8 @@ static bool magisk_env() {
symlink(MODULEMNT, MAGISKTMP "/img"); symlink(MODULEMNT, MAGISKTMP "/img");
// Directories in tmpfs overlay // Directories in tmpfs overlay
xmkdirs(MIRRPNT(system), 0755); xmkdir(MIRRDIR, 0);
xmkdir(BLOCKDIR, 0);
xmkdir(BBPATH, 0755); xmkdir(BBPATH, 0755);
xmkdir(MODULEMNT, 0755); xmkdir(MODULEMNT, 0755);
@ -360,10 +359,11 @@ static bool magisk_env() {
LOGI("* Mounting mirrors"); LOGI("* Mounting mirrors");
bool system_as_root = false; bool system_as_root = false;
struct stat st;
file_readline("/proc/mounts", [&](string_view line) -> bool { file_readline("/proc/mounts", [&](string_view line) -> bool {
if (str_contains(line, " /system_root ")) { if (str_contains(line, " /system_root ")) {
mount_mirror(system_root, MS_RDONLY); mount_mirror(system_root, MS_RDONLY);
bind_mount(MIRRPNT(system_root) "/system", MIRRPNT(system)); xsymlink(MIRRMNT(system_root) "/system", MIRRMNT(system));
system_as_root = true; system_as_root = true;
} else if (!system_as_root && str_contains(line, " /system ")) { } else if (!system_as_root && str_contains(line, " /system ")) {
mount_mirror(system, MS_RDONLY); mount_mirror(system, MS_RDONLY);

View File

@ -11,6 +11,7 @@
#define DISABLEFILE "/cache/.disable_magisk" #define DISABLEFILE "/cache/.disable_magisk"
#define MAGISKTMP "/sbin/.magisk" #define MAGISKTMP "/sbin/.magisk"
#define MIRRDIR MAGISKTMP "/mirror" #define MIRRDIR MAGISKTMP "/mirror"
#define BLOCKDIR MAGISKTMP "/block"
#define BBPATH MAGISKTMP "/busybox" #define BBPATH MAGISKTMP "/busybox"
#define MODULEMNT MAGISKTMP "/modules" #define MODULEMNT MAGISKTMP "/modules"
#define SECURE_DIR "/data/adb" #define SECURE_DIR "/data/adb"

View File

@ -28,10 +28,6 @@
using namespace std; using namespace std;
extern char *system_block;
extern char *vendor_block;
extern char *data_block;
static int inotify_fd = -1; static int inotify_fd = -1;
static void term_thread(int sig = SIGTERMTHRD); static void term_thread(int sig = SIGTERMTHRD);
@ -202,11 +198,9 @@ static void hide_daemon(int pid) {
lazy_unmount(s.data()); lazy_unmount(s.data());
targets.clear(); targets.clear();
// Unmount everything under /system, /vendor, and data mounts // Unmount all Magisk created mounts
file_readline("/proc/self/mounts", [&](string_view s) -> bool { file_readline("/proc/self/mounts", [&](string_view s) -> bool {
if ((str_contains(s, " /system/") || str_contains(s, " /vendor/")) && if (str_contains(s, BLOCKDIR)) {
(str_contains(s, system_block) || str_contains(s, vendor_block) ||
str_contains(s, data_block))) {
char *path = (char *) s.data(); char *path = (char *) s.data();
// Skip first token // Skip first token
strtok_r(nullptr, " ", &path); strtok_r(nullptr, " ", &path);