Use rootfs for magisktmp if possible

This commit is contained in:
LoveSy
2025-11-29 00:13:41 -08:00
committed by John Wu
parent 283fc0f46f
commit bdbfb40383
6 changed files with 103 additions and 33 deletions
+43 -1
View File
@@ -1,4 +1,4 @@
use crate::{LibcReturn, OsResult, Utf8CStr};
use crate::{Directory, LibcReturn, OsResult, ResultExt, Utf8CStr, Utf8CStrBufArr, WalkResult::{Continue, Skip}};
use nix::mount::{MntFlags, MsFlags, mount, umount2};
impl Utf8CStr {
@@ -81,4 +81,46 @@ impl Utf8CStr {
)
.check_os_err("set_mount_private", Some(self), None)
}
pub fn occupy(&self) {
Directory::open(self).and_then(|mut dir| {
dir.pre_order_walk(|entry| {
let mut path = Utf8CStrBufArr::default();
entry.resolve_path(&mut path)?;
let path = path.as_utf8_cstr();
mount(
Some(path),
path,
None::<&Utf8CStr>,
MsFlags::MS_BIND | MsFlags::MS_RDONLY,
None::<&Utf8CStr>,
).check_os_err("occupy", Some(path), None)?;
Ok(Continue)
}).log_ok();
Ok(())
}).log_ok();
}
pub fn unoccupy(&self) -> bool {
let mut ok = false;
Directory::open(self).and_then(|mut dir| {
ok = dir.pre_order_walk(|entry| {
let mut path = Utf8CStrBufArr::default();
entry.resolve_path(&mut path)?;
let path = path.as_utf8_cstr();
umount2(
path,
MntFlags::MNT_DETACH,
).check_os_err("unoccupy", Some(path), None)?;
if entry.is_dir() {
Ok(Skip)
} else {
Ok(Continue)
}
}).is_ok();
Ok(())
}).log_ok();
ok
}
}