mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-28 20:45:24 +00:00
New pre-init magic mount implementation
This commit is contained in:
parent
0d229dac3b
commit
696ab677be
@ -245,20 +245,18 @@ static void recreate_sbin(const char *mirror, bool use_bind_mount) {
|
|||||||
|
|
||||||
static string magic_mount_list;
|
static string magic_mount_list;
|
||||||
|
|
||||||
static void magic_mount(int dirfd, const string &path) {
|
static void magic_mount(const string &sdir, const string &ddir = "") {
|
||||||
DIR *dir = xfdopendir(dirfd);
|
auto dir = xopen_dir(sdir.data());
|
||||||
for (dirent *entry; (entry = readdir(dir));) {
|
for (dirent *entry; (entry = readdir(dir.get()));) {
|
||||||
if (entry->d_name == "."sv || entry->d_name == ".."sv)
|
if (entry->d_name == "."sv || entry->d_name == ".."sv)
|
||||||
continue;
|
continue;
|
||||||
string dest = path + "/" + entry->d_name;
|
string src = sdir + "/" + entry->d_name;
|
||||||
|
string dest = ddir + "/" + entry->d_name;
|
||||||
if (access(dest.data(), F_OK) == 0) {
|
if (access(dest.data(), F_OK) == 0) {
|
||||||
if (entry->d_type == DT_DIR) {
|
if (entry->d_type == DT_DIR) {
|
||||||
// Recursive
|
// Recursive
|
||||||
int fd = xopenat(dirfd, entry->d_name, O_RDONLY | O_CLOEXEC);
|
magic_mount(src, dest);
|
||||||
magic_mount(fd, dest);
|
|
||||||
close(fd);
|
|
||||||
} else {
|
} else {
|
||||||
string src = ROOTOVL + dest;
|
|
||||||
LOGD("Mount [%s] -> [%s]\n", src.data(), dest.data());
|
LOGD("Mount [%s] -> [%s]\n", src.data(), dest.data());
|
||||||
xmount(src.data(), dest.data(), nullptr, MS_BIND, nullptr);
|
xmount(src.data(), dest.data(), nullptr, MS_BIND, nullptr);
|
||||||
magic_mount_list += dest;
|
magic_mount_list += dest;
|
||||||
@ -360,9 +358,7 @@ void SARBase::patch_rootdir() {
|
|||||||
clone_attr("/init.rc", ROOTOVL "/init.rc");
|
clone_attr("/init.rc", ROOTOVL "/init.rc");
|
||||||
|
|
||||||
// Mount rootdir
|
// Mount rootdir
|
||||||
src = xopen(ROOTOVL, O_RDONLY | O_CLOEXEC);
|
magic_mount(ROOTOVL);
|
||||||
magic_mount(src, "");
|
|
||||||
close(src);
|
|
||||||
dest = xopen(ROOTMNT, O_WRONLY | O_CREAT | O_CLOEXEC);
|
dest = xopen(ROOTMNT, O_WRONLY | O_CREAT | O_CLOEXEC);
|
||||||
write(dest, magic_mount_list.data(), magic_mount_list.length());
|
write(dest, magic_mount_list.data(), magic_mount_list.length());
|
||||||
close(dest);
|
close(dest);
|
||||||
|
Loading…
Reference in New Issue
Block a user