mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-05 11:30:47 -05:00
Enable mount for nix
This commit is contained in:
+63
-70
@@ -1,91 +1,84 @@
|
||||
use crate::{LibcReturn, OsResult, Utf8CStr};
|
||||
use libc::c_ulong;
|
||||
use std::ptr;
|
||||
use nix::mount::{MntFlags, MsFlags, mount, umount2};
|
||||
|
||||
impl Utf8CStr {
|
||||
pub fn bind_mount_to<'a>(&'a self, path: &'a Utf8CStr, rec: bool) -> OsResult<'a, ()> {
|
||||
let flag = if rec { libc::MS_REC } else { 0 };
|
||||
unsafe {
|
||||
libc::mount(
|
||||
self.as_ptr(),
|
||||
path.as_ptr(),
|
||||
ptr::null(),
|
||||
libc::MS_BIND | flag,
|
||||
ptr::null(),
|
||||
)
|
||||
.check_os_err("bind_mount", Some(self), Some(path))
|
||||
}
|
||||
let flag = if rec {
|
||||
MsFlags::MS_REC
|
||||
} else {
|
||||
MsFlags::empty()
|
||||
};
|
||||
mount(
|
||||
Some(self),
|
||||
path,
|
||||
None::<&Utf8CStr>,
|
||||
flag | MsFlags::MS_BIND,
|
||||
None::<&Utf8CStr>,
|
||||
)
|
||||
.check_os_err("bind_mount", Some(self), Some(path))
|
||||
}
|
||||
|
||||
pub fn remount_mount_point_flags(&self, flags: c_ulong) -> OsResult<'_, ()> {
|
||||
unsafe {
|
||||
libc::mount(
|
||||
ptr::null(),
|
||||
self.as_ptr(),
|
||||
ptr::null(),
|
||||
libc::MS_BIND | libc::MS_REMOUNT | flags,
|
||||
ptr::null(),
|
||||
)
|
||||
.check_os_err("remount", Some(self), None)
|
||||
}
|
||||
pub fn remount_mount_point_flags(&self, flags: MsFlags) -> OsResult<'_, ()> {
|
||||
mount(
|
||||
None::<&Utf8CStr>,
|
||||
self,
|
||||
None::<&Utf8CStr>,
|
||||
MsFlags::MS_BIND | MsFlags::MS_REMOUNT | flags,
|
||||
None::<&Utf8CStr>,
|
||||
)
|
||||
.check_os_err("remount", Some(self), None)
|
||||
}
|
||||
|
||||
pub fn remount_mount_flags(&self, flags: c_ulong) -> OsResult<'_, ()> {
|
||||
unsafe {
|
||||
libc::mount(
|
||||
ptr::null(),
|
||||
self.as_ptr(),
|
||||
ptr::null(),
|
||||
libc::MS_REMOUNT | flags,
|
||||
ptr::null(),
|
||||
)
|
||||
.check_os_err("remount", Some(self), None)
|
||||
}
|
||||
pub fn remount_mount_flags(&self, flags: MsFlags) -> OsResult<'_, ()> {
|
||||
mount(
|
||||
None::<&Utf8CStr>,
|
||||
self,
|
||||
None::<&Utf8CStr>,
|
||||
MsFlags::MS_REMOUNT | flags,
|
||||
None::<&Utf8CStr>,
|
||||
)
|
||||
.check_os_err("remount", Some(self), None)
|
||||
}
|
||||
|
||||
pub fn remount_with_data(&self, data: &Utf8CStr) -> OsResult<'_, ()> {
|
||||
unsafe {
|
||||
libc::mount(
|
||||
ptr::null(),
|
||||
self.as_ptr(),
|
||||
ptr::null(),
|
||||
libc::MS_REMOUNT,
|
||||
data.as_ptr().cast(),
|
||||
)
|
||||
.check_os_err("remount", Some(self), None)
|
||||
}
|
||||
mount(
|
||||
None::<&Utf8CStr>,
|
||||
self,
|
||||
None::<&Utf8CStr>,
|
||||
MsFlags::MS_REMOUNT,
|
||||
Some(data),
|
||||
)
|
||||
.check_os_err("remount", Some(self), None)
|
||||
}
|
||||
|
||||
pub fn move_mount_to<'a>(&'a self, path: &'a Utf8CStr) -> OsResult<'a, ()> {
|
||||
unsafe {
|
||||
libc::mount(
|
||||
self.as_ptr(),
|
||||
path.as_ptr(),
|
||||
ptr::null(),
|
||||
libc::MS_MOVE,
|
||||
ptr::null(),
|
||||
)
|
||||
.check_os_err("move_mount", Some(self), Some(path))
|
||||
}
|
||||
mount(
|
||||
Some(self),
|
||||
path,
|
||||
None::<&Utf8CStr>,
|
||||
MsFlags::MS_MOVE,
|
||||
None::<&Utf8CStr>,
|
||||
)
|
||||
.check_os_err("move_mount", Some(self), Some(path))
|
||||
}
|
||||
|
||||
pub fn unmount(&self) -> OsResult<'_, ()> {
|
||||
unsafe {
|
||||
libc::umount2(self.as_ptr(), libc::MNT_DETACH).check_os_err("unmount", Some(self), None)
|
||||
}
|
||||
umount2(self, MntFlags::MNT_DETACH).check_os_err("unmount", Some(self), None)
|
||||
}
|
||||
|
||||
pub fn set_mount_private(&self, recursive: bool) -> OsResult<'_, ()> {
|
||||
let flag = if recursive { libc::MS_REC } else { 0 };
|
||||
unsafe {
|
||||
libc::mount(
|
||||
ptr::null(),
|
||||
self.as_ptr(),
|
||||
ptr::null(),
|
||||
libc::MS_PRIVATE | flag,
|
||||
ptr::null(),
|
||||
)
|
||||
.check_os_err("set_mount_private", Some(self), None)
|
||||
}
|
||||
pub fn set_mount_private(&self, rec: bool) -> OsResult<'_, ()> {
|
||||
let flag = if rec {
|
||||
MsFlags::MS_REC
|
||||
} else {
|
||||
MsFlags::empty()
|
||||
};
|
||||
mount(
|
||||
None::<&Utf8CStr>,
|
||||
self,
|
||||
None::<&Utf8CStr>,
|
||||
flag | MsFlags::MS_PRIVATE,
|
||||
None::<&Utf8CStr>,
|
||||
)
|
||||
.check_os_err("set_mount_private", Some(self), None)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user