From b1e17706a4e29af22282fd5ad086355c5234db3d Mon Sep 17 00:00:00 2001 From: LoveSy Date: Tue, 4 Feb 2025 20:52:03 +0800 Subject: [PATCH] Format code --- native/src/init/init.rs | 16 ++++++++++------ native/src/init/logging.rs | 21 +++++++++++++-------- native/src/init/mount.rs | 15 +++++++-------- native/src/init/rootdir.rs | 12 +++++++----- native/src/init/twostage.rs | 20 ++++++-------------- 5 files changed, 43 insertions(+), 41 deletions(-) diff --git a/native/src/init/init.rs b/native/src/init/init.rs index 1e74b659c..91ce43e68 100644 --- a/native/src/init/init.rs +++ b/native/src/init/init.rs @@ -1,12 +1,16 @@ -use crate::ffi::{magisk_proxy_main, BootConfig, MagiskInit}; -use crate::logging::setup_klog; +use crate::{ + ffi::{magisk_proxy_main, BootConfig, MagiskInit}, + logging::setup_klog, +}; use base::{ cstr, debug, info, libc::{basename, getpid, mount, umask}, raw_cstr, FsPath, LibcReturn, LoggedResult, ResultExt, Utf8CStr, }; -use std::ffi::{c_char, CStr}; -use std::ptr::null as nullptr; +use std::{ + ffi::{c_char, CStr}, + ptr::null, +}; impl MagiskInit { fn new(argv: *mut *mut c_char) -> Self { @@ -83,7 +87,7 @@ impl MagiskInit { raw_cstr!("/proc"), raw_cstr!("proc"), 0, - nullptr(), + null(), ) } .as_os_err()?; @@ -97,7 +101,7 @@ impl MagiskInit { raw_cstr!("/sys"), raw_cstr!("sysfs"), 0, - nullptr(), + null(), ) } .as_os_err()?; diff --git a/native/src/init/logging.rs b/native/src/init/logging.rs index a9e16c141..613aeecea 100644 --- a/native/src/init/logging.rs +++ b/native/src/init/logging.rs @@ -1,12 +1,17 @@ -use base::libc::{ - makedev, mknod, syscall, SYS_dup3, O_CLOEXEC, O_RDWR, O_WRONLY, STDERR_FILENO, STDIN_FILENO, - STDOUT_FILENO, S_IFCHR, +use base::{ + cstr, + 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 static mut KMSG: RawFd = -1; diff --git a/native/src/init/mount.rs b/native/src/init/mount.rs index ecac7252c..128328cdf 100644 --- a/native/src/init/mount.rs +++ b/native/src/init/mount.rs @@ -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 base::{ cstr, debug, libc, @@ -13,6 +5,13 @@ use base::{ parse_mount_info, raw_cstr, Directory, FsPath, LibcReturn, LoggedResult, ResultExt, StringExt, Utf8CStr, }; +use cxx::CxxString; +use std::{ + collections::BTreeSet, + ops::Bound::{Excluded, Unbounded}, + pin::Pin, + ptr::null as nullptr, +}; extern "C" { static environ: *const *mut libc::c_char; diff --git a/native/src/init/rootdir.rs b/native/src/init/rootdir.rs index 751eff9fb..24486a649 100644 --- a/native/src/init/rootdir.rs +++ b/native/src/init/rootdir.rs @@ -2,11 +2,13 @@ use base::{ debug, libc, Directory, LibcReturn, LoggedResult, ResultExt, Utf8CStr, Utf8CStrBuf, Utf8CStrBufArr, WalkResult, }; -use std::fs::File; -use std::io::Write; -use std::mem; -use std::os::fd::{FromRawFd, RawFd}; -use std::sync::OnceLock; +use std::{ + fs::File, + io::Write, + mem, + os::fd::{FromRawFd, RawFd}, + sync::OnceLock, +}; pub static OVERLAY_ATTRS: OnceLock> = OnceLock::new(); diff --git a/native/src/init/twostage.rs b/native/src/init/twostage.rs index c3f28a24e..8958db4f1 100644 --- a/native/src/init/twostage.rs +++ b/native/src/init/twostage.rs @@ -1,16 +1,13 @@ use crate::ffi::MagiskInit; -use base::libc::{mount, MS_BIND, O_WRONLY}; use base::{ clone_attr, cstr, debug, error, info, libc::{ - fstatat, stat, statfs, umount2, AT_SYMLINK_NOFOLLOW, MNT_DETACH, O_CLOEXEC, O_CREAT, - O_RDONLY, TMPFS_MAGIC, + fstatat, mount, stat, statfs, umount2, AT_SYMLINK_NOFOLLOW, MNT_DETACH, MS_BIND, O_CLOEXEC, + O_CREAT, O_RDONLY, O_WRONLY, TMPFS_MAGIC, }, raw_cstr, FsPath, LibcReturn, MappedFile, MutBytesExt, ResultExt, }; -use std::ffi::c_long; -use std::io::Write; -use std::ptr::null; +use std::{ffi::c_long, io::Write, ptr::null}; impl MagiskInit { pub(crate) fn first_stage(&self) { @@ -19,16 +16,11 @@ impl MagiskInit { if unsafe { let mut st: stat = std::mem::zeroed(); - fstatat( - -1, - raw_cstr!("/sdcard"), - std::ptr::from_mut(&mut st), - AT_SYMLINK_NOFOLLOW, - ) != 0 + fstatat(-1, raw_cstr!("/sdcard"), &mut st, AT_SYMLINK_NOFOLLOW) != 0 && fstatat( -1, raw_cstr!("/first_stage_ramdisk/sdcard"), - std::ptr::from_mut(&mut st), + &mut st, AT_SYMLINK_NOFOLLOW, ) != 0 } { @@ -151,7 +143,7 @@ impl MagiskInit { // Some weird devices like meizu, uses 2SI but still have legacy rootfs 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 { // We are still on rootfs, so make sure we will execute the init of the 2nd stage let init_path = FsPath::from(cstr!("/init"));