mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-12 08:32:07 +00:00
Migrate magiskinit selinux.cpp to Rust
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use cxx::{type_id, ExternType};
|
||||
use cxx::{ExternType, type_id};
|
||||
use libc::c_char;
|
||||
use std::borrow::Borrow;
|
||||
use std::cmp::min;
|
||||
@@ -479,6 +479,11 @@ impl FsPath {
|
||||
unsafe { mem::transmute(value.as_ref()) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub const fn from_utfcstr(value: &Utf8CStr) -> &FsPath {
|
||||
unsafe { mem::transmute(value) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn from_mut<T: AsMut<Utf8CStr> + ?Sized>(value: &mut T) -> &mut FsPath {
|
||||
unsafe { mem::transmute(value.as_mut()) }
|
||||
@@ -781,14 +786,10 @@ macro_rules! cstr {
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! raw_cstr {
|
||||
($str:expr) => {{
|
||||
$crate::cstr!($str).as_ptr()
|
||||
}};
|
||||
($str:expr) => {{ $crate::cstr!($str).as_ptr() }};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! path {
|
||||
($str:expr) => {{
|
||||
$crate::FsPath::from($crate::cstr!($str))
|
||||
}};
|
||||
($str:expr) => {{ $crate::FsPath::from_utfcstr($crate::cstr!($str)) }};
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ impl FsPath {
|
||||
}
|
||||
|
||||
pub fn create(&self, flags: i32, mode: mode_t) -> io::Result<File> {
|
||||
Ok(File::from(open_fd!(self, flags, mode)?))
|
||||
Ok(File::from(open_fd!(self, O_CREAT | flags, mode)?))
|
||||
}
|
||||
|
||||
pub fn exists(&self) -> bool {
|
||||
@@ -431,6 +431,10 @@ impl FsPath {
|
||||
pub fn create_symlink_to(&self, target: &FsPath) -> io::Result<()> {
|
||||
unsafe { libc::symlink(target.as_ptr(), self.as_ptr()).as_os_err() }
|
||||
}
|
||||
|
||||
pub fn mkfifo(&self, mode: mode_t) -> io::Result<()> {
|
||||
unsafe { libc::mkfifo(self.as_ptr(), mode).as_os_err() }
|
||||
}
|
||||
}
|
||||
|
||||
impl FsPathFollow {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{FsPath, LibcReturn};
|
||||
use crate::{FsPath, LibcReturn, Utf8CStr};
|
||||
use libc::c_ulong;
|
||||
use std::ptr;
|
||||
|
||||
@@ -29,6 +29,19 @@ impl FsPath {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remount_with_data(&self, data: &Utf8CStr) -> std::io::Result<()> {
|
||||
unsafe {
|
||||
libc::mount(
|
||||
ptr::null(),
|
||||
self.as_ptr(),
|
||||
ptr::null(),
|
||||
libc::MS_REMOUNT,
|
||||
data.as_ptr().cast(),
|
||||
)
|
||||
.as_os_err()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_mount_to(&self, path: &FsPath) -> std::io::Result<()> {
|
||||
unsafe {
|
||||
libc::mount(
|
||||
|
||||
Reference in New Issue
Block a user