Run through clippy and rustfmt

This commit is contained in:
topjohnwu
2025-11-28 19:56:51 -08:00
committed by John Wu
parent bdbfb40383
commit f7ce9c38e1
5 changed files with 63 additions and 47 deletions
+42 -35
View File
@@ -1,4 +1,5 @@
use crate::{Directory, LibcReturn, OsResult, ResultExt, Utf8CStr, Utf8CStrBufArr, WalkResult::{Continue, Skip}}; use crate::WalkResult::{Continue, Skip};
use crate::{Directory, LibcReturn, OsResult, ResultExt, Utf8CStr, Utf8CStrBufArr};
use nix::mount::{MntFlags, MsFlags, mount, umount2}; use nix::mount::{MntFlags, MsFlags, mount, umount2};
impl Utf8CStr { impl Utf8CStr {
@@ -83,44 +84,50 @@ impl Utf8CStr {
} }
pub fn occupy(&self) { pub fn occupy(&self) {
Directory::open(self).and_then(|mut dir| { Directory::open(self)
dir.pre_order_walk(|entry| { .map(|mut dir| {
let mut path = Utf8CStrBufArr::default(); dir.pre_order_walk(|entry| {
entry.resolve_path(&mut path)?; let mut path = Utf8CStrBufArr::default();
let path = path.as_utf8_cstr(); entry.resolve_path(&mut path)?;
mount( let path = path.as_utf8_cstr();
Some(path), mount(
path, Some(path),
None::<&Utf8CStr>, path,
MsFlags::MS_BIND | MsFlags::MS_RDONLY, None::<&Utf8CStr>,
None::<&Utf8CStr>, MsFlags::MS_BIND | MsFlags::MS_RDONLY,
).check_os_err("occupy", Some(path), None)?; None::<&Utf8CStr>,
Ok(Continue) )
}).log_ok(); .check_os_err("occupy", Some(path), None)?;
Ok(()) Ok(Continue)
}).log_ok(); })
.log_ok();
})
.log_ok();
} }
pub fn unoccupy(&self) -> bool { pub fn unoccupy(&self) -> bool {
let mut ok = false; let mut ok = false;
Directory::open(self).and_then(|mut dir| { Directory::open(self)
ok = dir.pre_order_walk(|entry| { .map(|mut dir| {
let mut path = Utf8CStrBufArr::default(); ok = dir
entry.resolve_path(&mut path)?; .pre_order_walk(|entry| {
let path = path.as_utf8_cstr(); let mut path = Utf8CStrBufArr::default();
umount2( entry.resolve_path(&mut path)?;
path, let path = path.as_utf8_cstr();
MntFlags::MNT_DETACH, umount2(path, MntFlags::MNT_DETACH).check_os_err(
).check_os_err("unoccupy", Some(path), None)?; "unoccupy",
if entry.is_dir() { Some(path),
Ok(Skip) None,
} else { )?;
Ok(Continue) if entry.is_dir() {
} Ok(Skip)
}).is_ok(); } else {
Ok(()) Ok(Continue)
}).log_ok(); }
})
.is_ok();
})
.log_ok();
ok ok
} }
} }
+4 -2
View File
@@ -221,8 +221,10 @@ pub fn revert_unmount(pid: i32) {
// Unmount Magisk tmpfs and mounts from module files // Unmount Magisk tmpfs and mounts from module files
for info in parse_mount_info("self") { for info in parse_mount_info("self") {
if info.source == "magisk" || info.root.starts_with("/adb/modules") || if info.source == "magisk"
(info.fs_type == "rootfs" && info.root.starts_with("/magisk")) { || info.root.starts_with("/adb/modules")
|| (info.fs_type == "rootfs" && info.root.starts_with("/magisk"))
{
targets.push(info.target); targets.push(info.target);
} }
} }
+4 -4
View File
@@ -3,10 +3,10 @@ use crate::logging::setup_klog;
use crate::mount::is_rootfs; use crate::mount::is_rootfs;
use crate::twostage::hexpatch_init_for_second_stage; use crate::twostage::hexpatch_init_for_second_stage;
use base::libc::{basename, getpid, mount, umask}; use base::libc::{basename, getpid, mount, umask};
use base::{LibcReturn, LoggedResult, ResultExt, cstr, info, raw_cstr, nix, Utf8CStr}; use base::nix::mount::MsFlags;
use base::{LibcReturn, LoggedResult, ResultExt, Utf8CStr, cstr, info, nix, raw_cstr};
use std::ffi::{CStr, c_char}; use std::ffi::{CStr, c_char};
use std::ptr::null; use std::ptr::null;
use base::nix::mount::MsFlags;
impl MagiskInit { impl MagiskInit {
fn new(argv: *mut *mut c_char) -> Self { fn new(argv: *mut *mut c_char) -> Self {
@@ -60,8 +60,8 @@ impl MagiskInit {
MsFlags::MS_REMOUNT, MsFlags::MS_REMOUNT,
Some(cstr!("size=100%")), Some(cstr!("size=100%")),
) )
.check_os_err("mount", Some("/data"), Some("tmpfs")) .check_os_err("mount", Some("/data"), Some("tmpfs"))
.log_ok(); .log_ok();
} }
cstr!("/init").unmount().ok(); cstr!("/init").unmount().ok();
+10 -5
View File
@@ -81,14 +81,19 @@ impl MagiskInit {
if use_rootfs { if use_rootfs {
cstr!("/magisk").mkdir(0o755).log_ok(); cstr!("/magisk").mkdir(0o755).log_ok();
rootfs_magisktmp = cstr!("/magisk").bind_mount_to(cstr!("/data"), false) rootfs_magisktmp = cstr!("/magisk")
.bind_mount_to(cstr!("/data"), false)
.is_ok(); .is_ok();
} }
if rootfs_magisktmp { if rootfs_magisktmp {
cstr!("/init").rename_to(cstr!("/magisk/magiskinit")).log_ok(); cstr!("/init")
.rename_to(cstr!("/magisk/magiskinit"))
.log_ok();
cstr!("/.backup").copy_to(cstr!("/magisk/.backup")).ok(); cstr!("/.backup").copy_to(cstr!("/magisk/.backup")).ok();
cstr!("/overlay.d").rename_to(cstr!("/magisk/overlay.d")).ok(); cstr!("/overlay.d")
.rename_to(cstr!("/magisk/overlay.d"))
.ok();
} else { } else {
nix::mount::mount( nix::mount::mount(
Some(cstr!("magisk")), Some(cstr!("magisk")),
@@ -97,8 +102,8 @@ impl MagiskInit {
MsFlags::empty(), MsFlags::empty(),
Some(cstr!("mode=755")), Some(cstr!("mode=755")),
) )
.check_os_err("mount", Some("/data"), Some("tmpfs")) .check_os_err("mount", Some("/data"), Some("tmpfs"))
.log_ok(); .log_ok();
cstr!("/init").copy_to(cstr!("/data/magiskinit")).ok(); cstr!("/init").copy_to(cstr!("/data/magiskinit")).ok();
cstr!("/.backup").copy_to(cstr!("/data/.backup")).ok(); cstr!("/.backup").copy_to(cstr!("/data/.backup")).ok();
+3 -1
View File
@@ -86,7 +86,9 @@ impl MagiskInit {
} }
// Binding mounting from rootfs is not supported before Linux 3.12 // Binding mounting from rootfs is not supported before Linux 3.12
cstr!("/sdcard").create(OFlag::O_RDONLY | OFlag::O_CLOEXEC, 0).log_ok(); cstr!("/sdcard")
.create(OFlag::O_RDONLY | OFlag::O_CLOEXEC, 0)
.log_ok();
cstr!("/data/magiskinit") cstr!("/data/magiskinit")
.bind_mount_to(cstr!("/sdcard"), false) .bind_mount_to(cstr!("/sdcard"), false)
.log_ok(); .log_ok();