mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-29 22:14:27 +02:00
Move MagiskInit::prepare_data to rust
This commit is contained in:
parent
a85c4c6528
commit
449204e380
@ -55,6 +55,10 @@ pub mod ffi {
|
||||
fn reset_overlay_contexts();
|
||||
unsafe fn start_magisk_init(argv: *mut *mut c_char);
|
||||
}
|
||||
|
||||
extern "Rust" {
|
||||
fn prepare_data(self: &MagiskInit);
|
||||
}
|
||||
|
||||
unsafe extern "C++" {
|
||||
include!("../base/include/base.hpp");
|
||||
@ -70,7 +74,6 @@ pub mod ffi {
|
||||
unsafe fn setup_tmp(self: &MagiskInit, path: *const c_char);
|
||||
fn collect_devices(self: &MagiskInit);
|
||||
fn mount_preinit_dir(self: &MagiskInit);
|
||||
fn prepare_data(self: &MagiskInit);
|
||||
unsafe fn find_block(self: &MagiskInit, partname: *const c_char) -> u64;
|
||||
fn mount_system_root(self: &mut MagiskInit) -> bool;
|
||||
|
||||
|
@ -221,16 +221,6 @@ void MagiskInit::exec_init() const noexcept {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void MagiskInit::prepare_data() const noexcept {
|
||||
LOGD("Setup data tmp\n");
|
||||
xmkdir("/data", 0755);
|
||||
xmount("magisk", "/data", "tmpfs", 0, "mode=755");
|
||||
|
||||
cp_afc("/init", REDIR_PATH);
|
||||
cp_afc("/.backup", "/data/.backup");
|
||||
cp_afc("/overlay.d", "/data/overlay.d");
|
||||
}
|
||||
|
||||
void MagiskInit::setup_tmp(const char *path) const noexcept {
|
||||
LOGD("Setup Magisk tmp at %s\n", path);
|
||||
chdir("/data");
|
||||
|
@ -7,10 +7,11 @@ use std::{
|
||||
|
||||
use cxx::CxxString;
|
||||
|
||||
use crate::ffi::MagiskInit;
|
||||
use base::{
|
||||
cstr, debug,
|
||||
libc::{chdir, chroot, mount, MS_MOVE},
|
||||
parse_mount_info, raw_cstr, Directory, LibcReturn, LoggedResult, StringExt, Utf8CStr,
|
||||
parse_mount_info, raw_cstr, Directory, FsPath, LibcReturn, LoggedResult, StringExt, Utf8CStr,
|
||||
};
|
||||
|
||||
pub fn switch_root(path: &Utf8CStr) {
|
||||
@ -68,3 +69,29 @@ pub fn is_device_mounted(dev: u64, target: Pin<&mut CxxString>) -> bool {
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
impl MagiskInit {
|
||||
pub(crate) fn prepare_data(&self) {
|
||||
debug!("Setup data tmp");
|
||||
fn inner() -> LoggedResult<()> {
|
||||
FsPath::from(cstr!("/data")).mkdir(0o755)?;
|
||||
unsafe {
|
||||
mount(
|
||||
raw_cstr!("magisk"),
|
||||
raw_cstr!("/data"),
|
||||
raw_cstr!("tmpfs"),
|
||||
0,
|
||||
raw_cstr!("mode=755").cast(),
|
||||
)
|
||||
}
|
||||
.as_os_err()?;
|
||||
|
||||
FsPath::from(cstr!("/init")).copy_to(FsPath::from(cstr!("/data/magiskinit")))?;
|
||||
FsPath::from(cstr!("/.backup")).copy_to(FsPath::from(cstr!("/data/.backup")))?;
|
||||
FsPath::from(cstr!("/overlay.d")).copy_to(FsPath::from(cstr!("/data/overlay.d")))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
inner().ok();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user