From e8b73ba6d1d142b623b7d4da0c2acb8be674407b Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 29 Jun 2019 14:19:10 -0700 Subject: [PATCH] Add separate product partition support --- native/jni/core/bootstages.cpp | 19 +++++++++++++++++-- native/jni/init/rootdir.cpp | 6 +++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/native/jni/core/bootstages.cpp b/native/jni/core/bootstages.cpp index 079c29e38..e02b7c2b3 100644 --- a/native/jni/core/bootstages.cpp +++ b/native/jni/core/bootstages.cpp @@ -88,12 +88,14 @@ node_entry::~node_entry() { delete node; } +#define SPECIAL_NODE (parent->parent ? false : (name == "vendor" || name == "product")) + bool node_entry::is_special() { - return parent ? (parent->parent ? false : name == "vendor") : false; + return parent ? SPECIAL_NODE : false; } bool node_entry::is_root() { - return parent ? (parent->parent ? false : name == "vendor") : true; + return parent ? SPECIAL_NODE : true; } string node_entry::get_path() { @@ -374,6 +376,8 @@ static bool magisk_env() { mount_mirror(system, MS_RDONLY); } else if (DIR_IS(vendor)) { mount_mirror(vendor, MS_RDONLY); + } else if (DIR_IS(product)) { + mount_mirror(product, MS_RDONLY); } else if (DIR_IS(data) && me->mnt_type != "tmpfs"sv) { mount_mirror(data, 0); } else if (SDK_INT >= 24 && DIR_IS(proc) && !strstr(me->mnt_opts, "hidepid=2")) { @@ -661,6 +665,13 @@ void post_fs_data(int client) { unlink(buf2); xsymlink(buf, buf2); } + // If /system/product exists in module, create a link outside + snprintf(buf, PATH_MAX, "%s/%s/system/product", MODULEROOT, module); + if (access(buf, F_OK) == 0) { + snprintf(buf2, PATH_MAX, "%s/%s/product", MODULEROOT, module); + unlink(buf2); + xsymlink(buf, buf2); + } sys_root->create_module_tree(module); } @@ -671,6 +682,10 @@ void post_fs_data(int client) { special->magic_mount(); delete special; } + if ((special = sys_root->extract("product"))) { + special->magic_mount(); + delete special; + } sys_root->magic_mount(); } diff --git a/native/jni/init/rootdir.cpp b/native/jni/init/rootdir.cpp index bab70a887..11e0231bc 100644 --- a/native/jni/init/rootdir.cpp +++ b/native/jni/init/rootdir.cpp @@ -201,9 +201,9 @@ void SARCommon::patch_rootdir() { sbin_overlay(self, config); // Mount system_root mirror - xmkdir(MIRRDIR, 0777); - xmkdir(ROOTMIR, 0777); - xmkdir(BLOCKDIR, 0777); + xmkdir(MIRRDIR, 0); + xmkdir(ROOTMIR, 0755); + xmkdir(BLOCKDIR, 0); mknod(ROOTBLK, S_IFBLK | 0600, system_dev); if (xmount(ROOTBLK, ROOTMIR, "ext4", MS_RDONLY, nullptr)) xmount(ROOTBLK, ROOTMIR, "erofs", MS_RDONLY, nullptr);