mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-20 07:48:29 +00:00
Finish post-fs simple mount
This commit is contained in:
parent
a31c1e8084
commit
05ed29133b
@ -11,6 +11,7 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <selinux/selinux.h>
|
||||||
|
|
||||||
#include "magisk.h"
|
#include "magisk.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@ -140,7 +141,7 @@ static int merge_img(const char *source, const char *target) {
|
|||||||
|
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
if (!(dir = xopendir("/cache/source")))
|
if (!(dir = opendir("/cache/source")))
|
||||||
return 1;
|
return 1;
|
||||||
while ((entry = xreaddir(dir))) {
|
while ((entry = xreaddir(dir))) {
|
||||||
if (entry->d_type == DT_DIR) {
|
if (entry->d_type == DT_DIR) {
|
||||||
@ -286,7 +287,7 @@ static void construct_tree(const char *module, const char *path, struct node_ent
|
|||||||
|
|
||||||
snprintf(buf, PATH_MAX, "%s/%s/%s", MOUNTPOINT, module, path);
|
snprintf(buf, PATH_MAX, "%s/%s/%s", MOUNTPOINT, module, path);
|
||||||
|
|
||||||
if (!(dir = xopendir(buf)))
|
if (!(dir = opendir(buf)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while ((entry = xreaddir(dir))) {
|
while ((entry = xreaddir(dir))) {
|
||||||
@ -335,7 +336,8 @@ static void clone_skeleton(struct node_entry *node, const char *real_path) {
|
|||||||
struct node_entry *dummy, *child;
|
struct node_entry *dummy, *child;
|
||||||
|
|
||||||
// Clone the structure
|
// Clone the structure
|
||||||
dir = xopendir(real_path);
|
if (!(dir = opendir(real_path)))
|
||||||
|
return;
|
||||||
while ((entry = xreaddir(dir))) {
|
while ((entry = xreaddir(dir))) {
|
||||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||||
continue;
|
continue;
|
||||||
@ -380,7 +382,7 @@ static void clone_skeleton(struct node_entry *node, const char *real_path) {
|
|||||||
xreadlink(buf2, temp, PATH_MAX);
|
xreadlink(buf2, temp, PATH_MAX);
|
||||||
symlink(temp, buf);
|
symlink(temp, buf);
|
||||||
free(temp);
|
free(temp);
|
||||||
LOGD("cplink: %s -> %s\n", buf2, buf);
|
LOGI("cplink: %s -> %s\n", buf2, buf);
|
||||||
} else {
|
} else {
|
||||||
snprintf(buf, PATH_MAX, "%s/%s", real_path, child->name);
|
snprintf(buf, PATH_MAX, "%s/%s", real_path, child->name);
|
||||||
bind_mount(buf2, buf);
|
bind_mount(buf2, buf);
|
||||||
@ -415,6 +417,50 @@ static void magic_mount(struct node_entry *node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************
|
||||||
|
* Simple Mount *
|
||||||
|
****************/
|
||||||
|
|
||||||
|
static void simple_mount(const char *path) {
|
||||||
|
DIR *dir;
|
||||||
|
struct dirent *entry;
|
||||||
|
|
||||||
|
snprintf(buf, PATH_MAX, "%s%s", CACHEMOUNT, path);
|
||||||
|
if (!(dir = opendir(buf)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
while ((entry = xreaddir(dir))) {
|
||||||
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||||
|
continue;
|
||||||
|
// Target file path
|
||||||
|
snprintf(buf2, PATH_MAX, "%s/%s", path, entry->d_name);
|
||||||
|
// Only mount existing file
|
||||||
|
if (access(buf2, F_OK) == -1)
|
||||||
|
continue;
|
||||||
|
if (entry->d_type == DT_DIR) {
|
||||||
|
char *new_path = strdup(buf2);
|
||||||
|
simple_mount(new_path);
|
||||||
|
free(new_path);
|
||||||
|
} else if (entry->d_type == DT_REG) {
|
||||||
|
// Actual file path
|
||||||
|
snprintf(buf, PATH_MAX, "%s/%s", buf, entry->d_name);
|
||||||
|
// Clone all attributes
|
||||||
|
struct stat s;
|
||||||
|
xstat(buf2, &s);
|
||||||
|
chmod(buf, s.st_mode & 0777);
|
||||||
|
chown(buf, s.st_uid, s.st_gid);
|
||||||
|
char *con;
|
||||||
|
getfilecon(buf2, &con);
|
||||||
|
setfilecon(buf, con);
|
||||||
|
free(con);
|
||||||
|
// Finally, mount the file
|
||||||
|
bind_mount(buf, buf2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
}
|
||||||
|
|
||||||
/****************
|
/****************
|
||||||
* Entry points *
|
* Entry points *
|
||||||
****************/
|
****************/
|
||||||
@ -441,12 +487,13 @@ void post_fs(int client) {
|
|||||||
if (access(UNINSTALLER, F_OK) == 0 || access(DISABLEFILE, F_OK) == 0)
|
if (access(UNINSTALLER, F_OK) == 0 || access(DISABLEFILE, F_OK) == 0)
|
||||||
goto unblock;
|
goto unblock;
|
||||||
|
|
||||||
// TODO: Simple bind mounts
|
|
||||||
|
|
||||||
// Allocate buffer
|
// Allocate buffer
|
||||||
buf = xmalloc(PATH_MAX);
|
buf = xmalloc(PATH_MAX);
|
||||||
buf2 = xmalloc(PATH_MAX);
|
buf2 = xmalloc(PATH_MAX);
|
||||||
|
|
||||||
|
simple_mount("/system");
|
||||||
|
simple_mount("/vendor");
|
||||||
|
|
||||||
unblock:
|
unblock:
|
||||||
unblock_boot_process();
|
unblock_boot_process();
|
||||||
}
|
}
|
||||||
@ -506,8 +553,7 @@ void post_fs_data(int client) {
|
|||||||
char *module;
|
char *module;
|
||||||
struct node_entry *sys_root, *ven_root = NULL, *child;
|
struct node_entry *sys_root, *ven_root = NULL, *child;
|
||||||
|
|
||||||
if (!(dir = xopendir(MOUNTPOINT)))
|
dir = xopendir(MOUNTPOINT);
|
||||||
goto unblock;
|
|
||||||
|
|
||||||
// Create the system root entry
|
// Create the system root entry
|
||||||
sys_root = xcalloc(sizeof(*sys_root), 1);
|
sys_root = xcalloc(sizeof(*sys_root), 1);
|
||||||
@ -586,7 +632,7 @@ void post_fs_data(int client) {
|
|||||||
snprintf(buf2, PATH_MAX, "%s/system", MIRRDIR);
|
snprintf(buf2, PATH_MAX, "%s/system", MIRRDIR);
|
||||||
xmkdir_p(buf2, 0755);
|
xmkdir_p(buf2, 0755);
|
||||||
xmount(buf, buf2, "ext4", MS_RDONLY, NULL);
|
xmount(buf, buf2, "ext4", MS_RDONLY, NULL);
|
||||||
LOGD("mount: %s -> %s\n", buf, buf2);
|
LOGI("mount: %s -> %s\n", buf, buf2);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strstr(line, " /vendor ")) {
|
if (strstr(line, " /vendor ")) {
|
||||||
@ -595,7 +641,7 @@ void post_fs_data(int client) {
|
|||||||
snprintf(buf2, PATH_MAX, "%s/vendor", MIRRDIR);
|
snprintf(buf2, PATH_MAX, "%s/vendor", MIRRDIR);
|
||||||
xmkdir_p(buf2, 0755);
|
xmkdir_p(buf2, 0755);
|
||||||
xmount(buf, buf2, "ext4", MS_RDONLY, NULL);
|
xmount(buf, buf2, "ext4", MS_RDONLY, NULL);
|
||||||
LOGD("mount: %s -> %s\n", buf, buf2);
|
LOGI("mount: %s -> %s\n", buf, buf2);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -604,7 +650,7 @@ void post_fs_data(int client) {
|
|||||||
snprintf(buf, PATH_MAX, "%s/system/vendor", MIRRDIR);
|
snprintf(buf, PATH_MAX, "%s/system/vendor", MIRRDIR);
|
||||||
snprintf(buf2, PATH_MAX, "%s/vendor", MIRRDIR);
|
snprintf(buf2, PATH_MAX, "%s/vendor", MIRRDIR);
|
||||||
symlink(buf, buf2);
|
symlink(buf, buf2);
|
||||||
LOGD("link: %s -> %s\n", buf, buf2);
|
LOGI("link: %s -> %s\n", buf, buf2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Magic!!
|
// Magic!!
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#define MAGISKTMP "/dev/magisk"
|
#define MAGISKTMP "/dev/magisk"
|
||||||
#define MIRRDIR MAGISKTMP "/mirror"
|
#define MIRRDIR MAGISKTMP "/mirror"
|
||||||
#define DUMMDIR MAGISKTMP "/dummy"
|
#define DUMMDIR MAGISKTMP "/dummy"
|
||||||
|
#define CACHEMOUNT "/cache/magisk_mount"
|
||||||
|
|
||||||
#define SELINUX_PATH "/sys/fs/selinux/"
|
#define SELINUX_PATH "/sys/fs/selinux/"
|
||||||
#define SELINUX_ENFORCE SELINUX_PATH "enforce"
|
#define SELINUX_ENFORCE SELINUX_PATH "enforce"
|
||||||
|
@ -93,13 +93,6 @@ int main(int argc, char *argv[]) {
|
|||||||
int fd = connect_daemon();
|
int fd = connect_daemon();
|
||||||
write_int(fd, LATE_START);
|
write_int(fd, LATE_START);
|
||||||
return read_int(fd);
|
return read_int(fd);
|
||||||
} else if (strcmp(argv[1], "--test") == 0) {
|
|
||||||
// Temporary testing entry
|
|
||||||
// int fd = connect_daemon();
|
|
||||||
// write_int(fd, TEST);
|
|
||||||
// return read_int(fd);
|
|
||||||
// test();
|
|
||||||
return 0;
|
|
||||||
} else {
|
} else {
|
||||||
// It's calling applets
|
// It's calling applets
|
||||||
--argc;
|
--argc;
|
||||||
|
@ -267,6 +267,7 @@ int mkdir_p(const char *pathname, mode_t mode) {
|
|||||||
int bind_mount(const char *from, const char *to) {
|
int bind_mount(const char *from, const char *to) {
|
||||||
int ret = xmount(from, to, NULL, MS_BIND, NULL);
|
int ret = xmount(from, to, NULL, MS_BIND, NULL);
|
||||||
LOGD("bind_mount: %s -> %s\n", from, to);
|
LOGD("bind_mount: %s -> %s\n", from, to);
|
||||||
|
LOGI("bind_mount: %s\n", to);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user