mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-05 03:20:46 -05:00
Enable mount for nix
This commit is contained in:
@@ -14,3 +14,4 @@ cxx-gen = { workspace = true }
|
||||
base = { path = "../base" }
|
||||
magiskpolicy = { path = "../sepolicy", default-features = false }
|
||||
cxx = { workspace = true }
|
||||
num-traits = { workspace = true }
|
||||
|
||||
+28
-31
@@ -1,12 +1,15 @@
|
||||
use crate::ffi::MagiskInit;
|
||||
use base::libc::{TMPFS_MAGIC, statfs};
|
||||
use base::{
|
||||
Directory, FsPathBuilder, LibcReturn, LoggedResult, ResultExt, Utf8CStr, cstr, debug, libc,
|
||||
libc::{chdir, chroot, execve, exit, mount},
|
||||
parse_mount_info, raw_cstr,
|
||||
nix, parse_mount_info, raw_cstr,
|
||||
};
|
||||
use cxx::CxxString;
|
||||
use std::ffi::c_long;
|
||||
use nix::{
|
||||
mount::MsFlags,
|
||||
sys::statfs::{FsType, TMPFS_MAGIC, statfs},
|
||||
unistd::{chdir, chroot},
|
||||
};
|
||||
use num_traits::AsPrimitive;
|
||||
use std::{
|
||||
collections::BTreeSet,
|
||||
ops::Bound::{Excluded, Unbounded},
|
||||
@@ -43,11 +46,9 @@ pub(crate) fn switch_root(path: &Utf8CStr) {
|
||||
target.move_mount_to(&new_path)?;
|
||||
mounts.insert(info.target);
|
||||
}
|
||||
unsafe {
|
||||
chdir(path.as_ptr()).check_err()?;
|
||||
path.move_mount_to(cstr!("/"))?;
|
||||
chroot(raw_cstr!("."));
|
||||
}
|
||||
chdir(path)?;
|
||||
path.move_mount_to(cstr!("/"))?;
|
||||
chroot(cstr!("."))?;
|
||||
|
||||
debug!("Cleaning rootfs");
|
||||
rootfs.remove_all()?;
|
||||
@@ -65,13 +66,13 @@ pub(crate) fn is_device_mounted(dev: u64, target: Pin<&mut CxxString>) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
const RAMFS_MAGIC: u64 = 0x858458f6;
|
||||
const RAMFS_MAGIC: u32 = 0x858458f6;
|
||||
|
||||
pub(crate) fn is_rootfs() -> bool {
|
||||
unsafe {
|
||||
let mut sfs: statfs = std::mem::zeroed();
|
||||
statfs(raw_cstr!("/"), &mut sfs);
|
||||
sfs.f_type as u64 == RAMFS_MAGIC || sfs.f_type as c_long == TMPFS_MAGIC
|
||||
if let Ok(s) = statfs(cstr!("/")) {
|
||||
s.filesystem_type() == FsType(RAMFS_MAGIC.as_()) || s.filesystem_type() == TMPFS_MAGIC
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,23 +80,19 @@ impl MagiskInit {
|
||||
pub(crate) fn prepare_data(&self) {
|
||||
debug!("Setup data tmp");
|
||||
cstr!("/data").mkdir(0o755).log_ok();
|
||||
unsafe {
|
||||
mount(
|
||||
raw_cstr!("magisk"),
|
||||
raw_cstr!("/data"),
|
||||
raw_cstr!("tmpfs"),
|
||||
0,
|
||||
raw_cstr!("mode=755").cast(),
|
||||
)
|
||||
}
|
||||
.check_err()
|
||||
nix::mount::mount(
|
||||
Some(cstr!("magisk")),
|
||||
cstr!("/data"),
|
||||
Some(cstr!("tmpfs")),
|
||||
MsFlags::empty(),
|
||||
Some(cstr!("mode=755")),
|
||||
)
|
||||
.check_os_err("mount", Some("/data"), Some("tmpfs"))
|
||||
.log_ok();
|
||||
|
||||
cstr!("/init").copy_to(cstr!("/data/magiskinit")).log_ok();
|
||||
cstr!("/.backup").copy_to(cstr!("/data/.backup")).log_ok();
|
||||
cstr!("/overlay.d")
|
||||
.copy_to(cstr!("/data/overlay.d"))
|
||||
.log_ok();
|
||||
cstr!("/init").copy_to(cstr!("/data/magiskinit")).ok();
|
||||
cstr!("/.backup").copy_to(cstr!("/data/.backup")).ok();
|
||||
cstr!("/overlay.d").copy_to(cstr!("/data/overlay.d")).ok();
|
||||
}
|
||||
|
||||
pub(crate) fn exec_init(&mut self) {
|
||||
@@ -106,10 +103,10 @@ impl MagiskInit {
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
execve(raw_cstr!("/init"), self.argv.cast(), environ.cast())
|
||||
libc::execve(raw_cstr!("/init"), self.argv.cast(), environ.cast())
|
||||
.check_err()
|
||||
.log_ok();
|
||||
exit(1);
|
||||
}
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user