Format code

This commit is contained in:
LoveSy 2025-02-04 20:52:03 +08:00 committed by John Wu
parent caad129d69
commit b1e17706a4
5 changed files with 43 additions and 41 deletions

View File

@ -1,12 +1,16 @@
use crate::ffi::{magisk_proxy_main, BootConfig, MagiskInit}; use crate::{
use crate::logging::setup_klog; ffi::{magisk_proxy_main, BootConfig, MagiskInit},
logging::setup_klog,
};
use base::{ use base::{
cstr, debug, info, cstr, debug, info,
libc::{basename, getpid, mount, umask}, libc::{basename, getpid, mount, umask},
raw_cstr, FsPath, LibcReturn, LoggedResult, ResultExt, Utf8CStr, raw_cstr, FsPath, LibcReturn, LoggedResult, ResultExt, Utf8CStr,
}; };
use std::ffi::{c_char, CStr}; use std::{
use std::ptr::null as nullptr; ffi::{c_char, CStr},
ptr::null,
};
impl MagiskInit { impl MagiskInit {
fn new(argv: *mut *mut c_char) -> Self { fn new(argv: *mut *mut c_char) -> Self {
@ -83,7 +87,7 @@ impl MagiskInit {
raw_cstr!("/proc"), raw_cstr!("/proc"),
raw_cstr!("proc"), raw_cstr!("proc"),
0, 0,
nullptr(), null(),
) )
} }
.as_os_err()?; .as_os_err()?;
@ -97,7 +101,7 @@ impl MagiskInit {
raw_cstr!("/sys"), raw_cstr!("/sys"),
raw_cstr!("sysfs"), raw_cstr!("sysfs"),
0, 0,
nullptr(), null(),
) )
} }
.as_os_err()?; .as_os_err()?;

View File

@ -1,12 +1,17 @@
use base::libc::{ use base::{
makedev, mknod, syscall, SYS_dup3, O_CLOEXEC, O_RDWR, O_WRONLY, STDERR_FILENO, STDIN_FILENO, cstr,
STDOUT_FILENO, S_IFCHR, libc::{
makedev, mknod, syscall, SYS_dup3, O_CLOEXEC, O_RDWR, O_WRONLY, STDERR_FILENO,
STDIN_FILENO, STDOUT_FILENO, S_IFCHR,
},
open_fd, raw_cstr, FsPath, LogLevel, Logger, Utf8CStr, LOGGER,
};
use std::{
fs::File,
io::{IoSlice, Write},
mem,
os::fd::{FromRawFd, IntoRawFd, RawFd},
}; };
use base::{cstr, open_fd, raw_cstr, FsPath, LogLevel, Logger, Utf8CStr, LOGGER};
use std::fs::File;
use std::io::{IoSlice, Write};
use std::mem;
use std::os::fd::{FromRawFd, IntoRawFd, RawFd};
// SAFETY: magiskinit is single threaded // SAFETY: magiskinit is single threaded
static mut KMSG: RawFd = -1; static mut KMSG: RawFd = -1;

View File

@ -1,11 +1,3 @@
use cxx::CxxString;
use std::{
collections::BTreeSet,
ops::Bound::{Excluded, Unbounded},
pin::Pin,
ptr::null as nullptr,
};
use crate::ffi::MagiskInit; use crate::ffi::MagiskInit;
use base::{ use base::{
cstr, debug, libc, cstr, debug, libc,
@ -13,6 +5,13 @@ use base::{
parse_mount_info, raw_cstr, Directory, FsPath, LibcReturn, LoggedResult, ResultExt, StringExt, parse_mount_info, raw_cstr, Directory, FsPath, LibcReturn, LoggedResult, ResultExt, StringExt,
Utf8CStr, Utf8CStr,
}; };
use cxx::CxxString;
use std::{
collections::BTreeSet,
ops::Bound::{Excluded, Unbounded},
pin::Pin,
ptr::null as nullptr,
};
extern "C" { extern "C" {
static environ: *const *mut libc::c_char; static environ: *const *mut libc::c_char;

View File

@ -2,11 +2,13 @@ use base::{
debug, libc, Directory, LibcReturn, LoggedResult, ResultExt, Utf8CStr, Utf8CStrBuf, debug, libc, Directory, LibcReturn, LoggedResult, ResultExt, Utf8CStr, Utf8CStrBuf,
Utf8CStrBufArr, WalkResult, Utf8CStrBufArr, WalkResult,
}; };
use std::fs::File; use std::{
use std::io::Write; fs::File,
use std::mem; io::Write,
use std::os::fd::{FromRawFd, RawFd}; mem,
use std::sync::OnceLock; os::fd::{FromRawFd, RawFd},
sync::OnceLock,
};
pub static OVERLAY_ATTRS: OnceLock<Vec<(String, String)>> = OnceLock::new(); pub static OVERLAY_ATTRS: OnceLock<Vec<(String, String)>> = OnceLock::new();

View File

@ -1,16 +1,13 @@
use crate::ffi::MagiskInit; use crate::ffi::MagiskInit;
use base::libc::{mount, MS_BIND, O_WRONLY};
use base::{ use base::{
clone_attr, cstr, debug, error, info, clone_attr, cstr, debug, error, info,
libc::{ libc::{
fstatat, stat, statfs, umount2, AT_SYMLINK_NOFOLLOW, MNT_DETACH, O_CLOEXEC, O_CREAT, fstatat, mount, stat, statfs, umount2, AT_SYMLINK_NOFOLLOW, MNT_DETACH, MS_BIND, O_CLOEXEC,
O_RDONLY, TMPFS_MAGIC, O_CREAT, O_RDONLY, O_WRONLY, TMPFS_MAGIC,
}, },
raw_cstr, FsPath, LibcReturn, MappedFile, MutBytesExt, ResultExt, raw_cstr, FsPath, LibcReturn, MappedFile, MutBytesExt, ResultExt,
}; };
use std::ffi::c_long; use std::{ffi::c_long, io::Write, ptr::null};
use std::io::Write;
use std::ptr::null;
impl MagiskInit { impl MagiskInit {
pub(crate) fn first_stage(&self) { pub(crate) fn first_stage(&self) {
@ -19,16 +16,11 @@ impl MagiskInit {
if unsafe { if unsafe {
let mut st: stat = std::mem::zeroed(); let mut st: stat = std::mem::zeroed();
fstatat( fstatat(-1, raw_cstr!("/sdcard"), &mut st, AT_SYMLINK_NOFOLLOW) != 0
-1,
raw_cstr!("/sdcard"),
std::ptr::from_mut(&mut st),
AT_SYMLINK_NOFOLLOW,
) != 0
&& fstatat( && fstatat(
-1, -1,
raw_cstr!("/first_stage_ramdisk/sdcard"), raw_cstr!("/first_stage_ramdisk/sdcard"),
std::ptr::from_mut(&mut st), &mut st,
AT_SYMLINK_NOFOLLOW, AT_SYMLINK_NOFOLLOW,
) != 0 ) != 0
} { } {
@ -151,7 +143,7 @@ impl MagiskInit {
// Some weird devices like meizu, uses 2SI but still have legacy rootfs // Some weird devices like meizu, uses 2SI but still have legacy rootfs
let mut sfs: statfs = std::mem::zeroed(); let mut sfs: statfs = std::mem::zeroed();
statfs(raw_cstr!("/"), std::ptr::from_mut(&mut sfs)); statfs(raw_cstr!("/"), &mut sfs);
if sfs.f_type == 0x858458f6 || sfs.f_type as c_long == TMPFS_MAGIC { if sfs.f_type == 0x858458f6 || sfs.f_type as c_long == TMPFS_MAGIC {
// We are still on rootfs, so make sure we will execute the init of the 2nd stage // We are still on rootfs, so make sure we will execute the init of the 2nd stage
let init_path = FsPath::from(cstr!("/init")); let init_path = FsPath::from(cstr!("/init"));