mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-06 07:20:47 -05:00
Move occupy and unoccupy out of base crate
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use crate::WalkResult::{Continue, Skip};
|
||||
use crate::{Directory, LibcReturn, OsResult, ResultExt, Utf8CStr, Utf8CStrBufArr};
|
||||
use crate::{LibcReturn, OsResult, Utf8CStr};
|
||||
use nix::mount::{MntFlags, MsFlags, mount, umount2};
|
||||
|
||||
impl Utf8CStr {
|
||||
@@ -82,52 +81,4 @@ impl Utf8CStr {
|
||||
)
|
||||
.check_os_err("set_mount_private", Some(self), None)
|
||||
}
|
||||
|
||||
pub fn occupy(&self) {
|
||||
Directory::open(self)
|
||||
.map(|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();
|
||||
})
|
||||
.log_ok();
|
||||
}
|
||||
|
||||
pub fn unoccupy(&self) -> bool {
|
||||
let mut ok = false;
|
||||
Directory::open(self)
|
||||
.map(|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();
|
||||
})
|
||||
.log_ok();
|
||||
ok
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user