From 3e479726ecc9c33fe61622cc5a1d1fc222cbedd1 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 25 Jan 2021 00:19:10 -0800 Subject: [PATCH] Fix legacy rootfs devices --- gradle.properties | 2 +- native/build.gradle.kts | 2 +- native/jni/init/mount.cpp | 2 +- native/jni/init/rootdir.cpp | 11 ++++++----- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/gradle.properties b/gradle.properties index cf8009c0f..234f3da65 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,6 +28,6 @@ kapt.incremental.apt=true # Magisk magisk.stubVersion=16 -magisk.versionCode=21402 +magisk.versionCode=21403 magisk.ndkVersion=21d magisk.fullNdkVersion=21.3.6528147 diff --git a/native/build.gradle.kts b/native/build.gradle.kts index 59bc7ae97..ccbcc3182 100644 --- a/native/build.gradle.kts +++ b/native/build.gradle.kts @@ -14,7 +14,7 @@ android { externalNativeBuild { ndkBuild { // Pass arguments to ndk-build. - arguments("B_MAGISK=1", "B_INIT64=1", "B_BOOT=1", "B_TEST=1", + arguments("B_MAGISK=1", "B_INIT=1", "B_BOOT=1", "B_TEST=1", "MAGISK_DEBUG=1", "MAGISK_VERSION=debug", "MAGISK_VER_CODE=INT_MAX") } } diff --git a/native/jni/init/mount.cpp b/native/jni/init/mount.cpp index 6303b4f18..1776252e2 100644 --- a/native/jni/init/mount.cpp +++ b/native/jni/init/mount.cpp @@ -86,7 +86,7 @@ static int64_t setup_block(bool write_block) { sprintf(blk_info.block_dev, "/dev/block/%s", dev.devname); } dev_t rdev = makedev(dev.major, dev.minor); - mknod(blk_info.block_dev, S_IFBLK | 0600, rdev); + xmknod(blk_info.block_dev, S_IFBLK | 0600, rdev); return rdev; } // Wait 10ms and try again diff --git a/native/jni/init/rootdir.cpp b/native/jni/init/rootdir.cpp index 8edee7c4f..0ee1f47cf 100644 --- a/native/jni/init/rootdir.cpp +++ b/native/jni/init/rootdir.cpp @@ -322,8 +322,14 @@ void SARBase::patch_rootdir() { #define TMP_RULESDIR "/.backup/.sepolicy.rules" void RootFSInit::patch_rootfs() { + // Create hardlink mirror of /sbin to /root + mkdir("/root", 0777); + clone_attr("/sbin", "/root"); + link_path("/sbin", "/root"); + // Handle custom sepolicy rules xmkdir(TMP_MNTDIR, 0755); + xmkdir("/dev/block", 0755); mount_rules_dir("/dev/block", TMP_MNTDIR); // Preserve custom rule path if (!custom_rules_dir.empty()) { @@ -346,11 +352,6 @@ void RootFSInit::patch_rootfs() { patch_init_rc("/init.rc", "/init.p.rc", "/sbin"); rename("/init.p.rc", "/init.rc"); - // Create hardlink mirror of /sbin to /root - mkdir("/root", 0750); - clone_attr("/sbin", "/root"); - link_path("/sbin", "/root"); - // Dump magiskinit as magisk int fd = xopen("/sbin/magisk", O_WRONLY | O_CREAT, 0755); write(fd, self.buf, self.sz);