mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-24 19:17:38 +00:00
Reuse tmpfs for magic mount
As we already have a tmpfs (magisktmp), we can reuse them for magic mount
This commit is contained in:
parent
3517e6d752
commit
4318ab5cd2
@ -88,6 +88,12 @@ static void mount_mirrors() {
|
|||||||
char buf1[4096];
|
char buf1[4096];
|
||||||
char buf2[4096];
|
char buf2[4096];
|
||||||
|
|
||||||
|
LOGI("* Prepare worker\n");
|
||||||
|
|
||||||
|
ssprintf(buf1, sizeof(buf1), "%s/" WORKERDIR, MAGISKTMP.data());
|
||||||
|
xmount(buf1, buf1, nullptr, MS_BIND, nullptr);
|
||||||
|
xmount(nullptr, buf1, nullptr, MS_PRIVATE, nullptr);
|
||||||
|
|
||||||
LOGI("* Mounting mirrors\n");
|
LOGI("* Mounting mirrors\n");
|
||||||
|
|
||||||
parse_mnt("/proc/mounts", [&](mntent *me) {
|
parse_mnt("/proc/mounts", [&](mntent *me) {
|
||||||
|
@ -31,10 +31,10 @@ class module_node;
|
|||||||
class root_node;
|
class root_node;
|
||||||
|
|
||||||
template<class T> static bool isa(node_entry *node);
|
template<class T> static bool isa(node_entry *node);
|
||||||
static int bind_mount(const char *from, const char *to) {
|
static int bind_mount(const char *reason, const char *from, const char *to) {
|
||||||
int ret = xmount(from, to, nullptr, MS_BIND, nullptr);
|
int ret = xmount(from, to, nullptr, MS_BIND, nullptr);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
VLOGD("bind_mnt", from, to);
|
VLOGD(reason, from, to);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ protected:
|
|||||||
template<class T>
|
template<class T>
|
||||||
explicit node_entry(T*) : _file_type(0), node_type(type_id<T>()) {}
|
explicit node_entry(T*) : _file_type(0), node_type(type_id<T>()) {}
|
||||||
|
|
||||||
void create_and_mount(const string &src);
|
void create_and_mount(const char *reason, const string &src);
|
||||||
|
|
||||||
// Use top bit of _file_type for node exist status
|
// Use top bit of _file_type for node exist status
|
||||||
bool exist() { return static_cast<bool>(_file_type & (1 << 7)); }
|
bool exist() { return static_cast<bool>(_file_type & (1 << 7)); }
|
||||||
@ -254,7 +254,7 @@ class mirror_node : public node_entry {
|
|||||||
public:
|
public:
|
||||||
explicit mirror_node(dirent *entry) : node_entry(entry->d_name, entry->d_type, this) {}
|
explicit mirror_node(dirent *entry) : node_entry(entry->d_name, entry->d_type, this) {}
|
||||||
void mount() override {
|
void mount() override {
|
||||||
create_and_mount(mirror_path());
|
create_and_mount("mirror", mirror_path());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -413,7 +413,7 @@ bool dir_node::prepare() {
|
|||||||
// Tell parent to upgrade self to tmpfs
|
// Tell parent to upgrade self to tmpfs
|
||||||
to_tmpfs = true;
|
to_tmpfs = true;
|
||||||
// If child is inter_node and it does not (need to) exist, upgrade to module
|
// If child is inter_node and it does not (need to) exist, upgrade to module
|
||||||
if (auto dn = dyn_cast<inter_node>(it->second); dn) {
|
if (auto dn = dyn_cast<inter_node>(it->second)) {
|
||||||
if (!dn->exist()) {
|
if (!dn->exist()) {
|
||||||
if (auto nit = upgrade<module_node, inter_node>(it); nit != children.end()) {
|
if (auto nit = upgrade<module_node, inter_node>(it); nit != children.end()) {
|
||||||
it = nit;
|
it = nit;
|
||||||
@ -467,7 +467,7 @@ bool dir_node::collect_files(const char *module, int dfd) {
|
|||||||
* Mount Implementations
|
* Mount Implementations
|
||||||
************************/
|
************************/
|
||||||
|
|
||||||
void node_entry::create_and_mount(const string &src) {
|
void node_entry::create_and_mount(const char *reason, const string &src) {
|
||||||
const string &dest = node_path();
|
const string &dest = node_path();
|
||||||
if (is_lnk()) {
|
if (is_lnk()) {
|
||||||
VLOGD("cp_link", src.data(), dest.data());
|
VLOGD("cp_link", src.data(), dest.data());
|
||||||
@ -479,7 +479,7 @@ void node_entry::create_and_mount(const string &src) {
|
|||||||
close(xopen(dest.data(), O_RDONLY | O_CREAT | O_CLOEXEC, 0));
|
close(xopen(dest.data(), O_RDONLY | O_CREAT | O_CLOEXEC, 0));
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
bind_mount(src.data(), dest.data());
|
bind_mount(reason, src.data(), dest.data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,9 +488,9 @@ void module_node::mount() {
|
|||||||
if (exist())
|
if (exist())
|
||||||
clone_attr(mirror_path().data(), src.data());
|
clone_attr(mirror_path().data(), src.data());
|
||||||
if (isa<tmpfs_node>(parent()))
|
if (isa<tmpfs_node>(parent()))
|
||||||
create_and_mount(src);
|
create_and_mount("module", src);
|
||||||
else if (is_dir() || is_reg())
|
else if (is_dir() || is_reg())
|
||||||
bind_mount(src.data(), node_path().data());
|
bind_mount("module", src.data(), node_path().data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void tmpfs_node::mount() {
|
void tmpfs_node::mount() {
|
||||||
@ -503,11 +503,13 @@ void tmpfs_node::mount() {
|
|||||||
getattr(src.data(), &a);
|
getattr(src.data(), &a);
|
||||||
else
|
else
|
||||||
getattr(parent()->node_path().data(), &a);
|
getattr(parent()->node_path().data(), &a);
|
||||||
mkdir(dest.data(), 0);
|
|
||||||
if (!isa<tmpfs_node>(parent())) {
|
if (!isa<tmpfs_node>(parent())) {
|
||||||
// We don't need another layer of tmpfs if parent is skel
|
// We don't need another layer of tmpfs if parent is skel
|
||||||
xmount("tmpfs", dest.data(), "tmpfs", 0, nullptr);
|
auto worker_dir = MAGISKTMP + "/" WORKERDIR + dest;
|
||||||
VLOGD("mnt_tmp", "tmpfs", dest.data());
|
mkdirs(worker_dir.data(), 0);
|
||||||
|
create_and_mount("tmpfs", worker_dir);
|
||||||
|
} else {
|
||||||
|
mkdir(dest.data(), 0);
|
||||||
}
|
}
|
||||||
setattr(dest.data(), &a);
|
setattr(dest.data(), &a);
|
||||||
dir_node::mount();
|
dir_node::mount();
|
||||||
@ -538,7 +540,7 @@ public:
|
|||||||
VLOGD("create", "./magiskpolicy", dest.data());
|
VLOGD("create", "./magiskpolicy", dest.data());
|
||||||
xsymlink("./magiskpolicy", dest.data());
|
xsymlink("./magiskpolicy", dest.data());
|
||||||
}
|
}
|
||||||
create_and_mount(src);
|
create_and_mount("magisk", src);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -574,7 +576,7 @@ if (access("/system/bin/app_process" #bit, F_OK) == 0) {
|
|||||||
close(out); \
|
close(out); \
|
||||||
close(src); \
|
close(src); \
|
||||||
clone_attr("/system/bin/app_process" #bit, zbin.data()); \
|
clone_attr("/system/bin/app_process" #bit, zbin.data()); \
|
||||||
bind_mount(zbin.data(), "/system/bin/app_process" #bit); \
|
bind_mount("zygisk", zbin.data(), "/system/bin/app_process" #bit); \
|
||||||
}
|
}
|
||||||
|
|
||||||
void magic_mount() {
|
void magic_mount() {
|
||||||
@ -672,7 +674,7 @@ static void prepare_modules() {
|
|||||||
auto src = MAGISKTMP + "/" MIRRDIR MODULEROOT;
|
auto src = MAGISKTMP + "/" MIRRDIR MODULEROOT;
|
||||||
auto dest = MAGISKTMP + "/" MODULEMNT;
|
auto dest = MAGISKTMP + "/" MODULEMNT;
|
||||||
xmkdir(dest.data(), 0755);
|
xmkdir(dest.data(), 0755);
|
||||||
bind_mount(src.data(), dest.data());
|
bind_mount("mod_mnt", src.data(), dest.data());
|
||||||
|
|
||||||
restorecon();
|
restorecon();
|
||||||
chmod(SECURE_DIR, 0700);
|
chmod(SECURE_DIR, 0700);
|
||||||
|
@ -20,11 +20,12 @@ extern std::string MAGISKTMP;
|
|||||||
#define MIRRDIR INTLROOT "/mirror"
|
#define MIRRDIR INTLROOT "/mirror"
|
||||||
#define RULESDIR MIRRDIR "/sepolicy.rules"
|
#define RULESDIR MIRRDIR "/sepolicy.rules"
|
||||||
#define BLOCKDIR INTLROOT "/block"
|
#define BLOCKDIR INTLROOT "/block"
|
||||||
|
#define WORKERDIR INTLROOT "/worker"
|
||||||
#define MODULEMNT INTLROOT "/modules"
|
#define MODULEMNT INTLROOT "/modules"
|
||||||
#define BBPATH INTLROOT "/busybox"
|
#define BBPATH INTLROOT "/busybox"
|
||||||
#define ROOTOVL INTLROOT "/rootdir"
|
#define ROOTOVL INTLROOT "/rootdir"
|
||||||
#define SHELLPTS INTLROOT "/pts"
|
#define SHELLPTS INTLROOT "/pts"
|
||||||
#define ROOTMNT ROOTOVL "/.mount_list"
|
#define ROOTMNT ROOTOVL "/.mount_list"
|
||||||
#define ZYGISKBIN INTLROOT "/zygisk"
|
#define ZYGISKBIN INTLROOT "/zygisk"
|
||||||
#define SELINUXMOCK INTLROOT "/selinux"
|
#define SELINUXMOCK INTLROOT "/selinux"
|
||||||
|
|
||||||
|
@ -311,6 +311,7 @@ void MagiskInit::setup_tmp(const char *path) {
|
|||||||
xmkdir(INTLROOT, 0755);
|
xmkdir(INTLROOT, 0755);
|
||||||
xmkdir(MIRRDIR, 0);
|
xmkdir(MIRRDIR, 0);
|
||||||
xmkdir(BLOCKDIR, 0);
|
xmkdir(BLOCKDIR, 0);
|
||||||
|
xmkdir(WORKERDIR, 0);
|
||||||
|
|
||||||
mount_rules_dir();
|
mount_rules_dir();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user