From f7ce9c38e1efbc0fa56d3aa26bd495e790173ef2 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 28 Nov 2025 19:56:51 -0800 Subject: [PATCH] Run through clippy and rustfmt --- native/src/base/mount.rs | 77 ++++++++++++++++++++----------------- native/src/core/mount.rs | 6 ++- native/src/init/init.rs | 8 ++-- native/src/init/mount.rs | 15 +++++--- native/src/init/twostage.rs | 4 +- 5 files changed, 63 insertions(+), 47 deletions(-) diff --git a/native/src/base/mount.rs b/native/src/base/mount.rs index f71fcf5f7..62bdd0845 100644 --- a/native/src/base/mount.rs +++ b/native/src/base/mount.rs @@ -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}; impl Utf8CStr { @@ -83,44 +84,50 @@ impl Utf8CStr { } pub fn occupy(&self) { - Directory::open(self).and_then(|mut dir| { - dir.pre_order_walk(|entry| { - let mut path = Utf8CStrBufArr::default(); - entry.resolve_path(&mut path)?; - let path = path.as_utf8_cstr(); - mount( - Some(path), - path, - None::<&Utf8CStr>, - MsFlags::MS_BIND | MsFlags::MS_RDONLY, - None::<&Utf8CStr>, - ).check_os_err("occupy", Some(path), None)?; - Ok(Continue) - }).log_ok(); - Ok(()) - }).log_ok(); + Directory::open(self) + .map(|mut dir| { + dir.pre_order_walk(|entry| { + let mut path = Utf8CStrBufArr::default(); + entry.resolve_path(&mut path)?; + let path = path.as_utf8_cstr(); + mount( + Some(path), + path, + None::<&Utf8CStr>, + MsFlags::MS_BIND | MsFlags::MS_RDONLY, + None::<&Utf8CStr>, + ) + .check_os_err("occupy", Some(path), None)?; + Ok(Continue) + }) + .log_ok(); + }) + .log_ok(); } pub fn unoccupy(&self) -> bool { let mut ok = false; - Directory::open(self).and_then(|mut dir| { - ok = dir.pre_order_walk(|entry| { - let mut path = Utf8CStrBufArr::default(); - entry.resolve_path(&mut path)?; - let path = path.as_utf8_cstr(); - umount2( - path, - MntFlags::MNT_DETACH, - ).check_os_err("unoccupy", Some(path), None)?; - if entry.is_dir() { - Ok(Skip) - } else { - Ok(Continue) - } - }).is_ok(); - Ok(()) - }).log_ok(); + Directory::open(self) + .map(|mut dir| { + ok = dir + .pre_order_walk(|entry| { + let mut path = Utf8CStrBufArr::default(); + entry.resolve_path(&mut path)?; + let path = path.as_utf8_cstr(); + umount2(path, MntFlags::MNT_DETACH).check_os_err( + "unoccupy", + Some(path), + None, + )?; + if entry.is_dir() { + Ok(Skip) + } else { + Ok(Continue) + } + }) + .is_ok(); + }) + .log_ok(); ok } - } diff --git a/native/src/core/mount.rs b/native/src/core/mount.rs index 3877aae04..0795a4da6 100644 --- a/native/src/core/mount.rs +++ b/native/src/core/mount.rs @@ -221,8 +221,10 @@ pub fn revert_unmount(pid: i32) { // Unmount Magisk tmpfs and mounts from module files for info in parse_mount_info("self") { - if info.source == "magisk" || info.root.starts_with("/adb/modules") || - (info.fs_type == "rootfs" && info.root.starts_with("/magisk")) { + if info.source == "magisk" + || info.root.starts_with("/adb/modules") + || (info.fs_type == "rootfs" && info.root.starts_with("/magisk")) + { targets.push(info.target); } } diff --git a/native/src/init/init.rs b/native/src/init/init.rs index 7db0b3eac..600730d31 100644 --- a/native/src/init/init.rs +++ b/native/src/init/init.rs @@ -3,10 +3,10 @@ use crate::logging::setup_klog; use crate::mount::is_rootfs; use crate::twostage::hexpatch_init_for_second_stage; 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::ptr::null; -use base::nix::mount::MsFlags; impl MagiskInit { fn new(argv: *mut *mut c_char) -> Self { @@ -60,8 +60,8 @@ impl MagiskInit { MsFlags::MS_REMOUNT, Some(cstr!("size=100%")), ) - .check_os_err("mount", Some("/data"), Some("tmpfs")) - .log_ok(); + .check_os_err("mount", Some("/data"), Some("tmpfs")) + .log_ok(); } cstr!("/init").unmount().ok(); diff --git a/native/src/init/mount.rs b/native/src/init/mount.rs index 73a36b08a..d29c94288 100644 --- a/native/src/init/mount.rs +++ b/native/src/init/mount.rs @@ -81,14 +81,19 @@ impl MagiskInit { if use_rootfs { 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(); } 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!("/overlay.d").rename_to(cstr!("/magisk/overlay.d")).ok(); + cstr!("/overlay.d") + .rename_to(cstr!("/magisk/overlay.d")) + .ok(); } else { nix::mount::mount( Some(cstr!("magisk")), @@ -97,8 +102,8 @@ impl MagiskInit { MsFlags::empty(), Some(cstr!("mode=755")), ) - .check_os_err("mount", Some("/data"), Some("tmpfs")) - .log_ok(); + .check_os_err("mount", Some("/data"), Some("tmpfs")) + .log_ok(); cstr!("/init").copy_to(cstr!("/data/magiskinit")).ok(); cstr!("/.backup").copy_to(cstr!("/data/.backup")).ok(); diff --git a/native/src/init/twostage.rs b/native/src/init/twostage.rs index 1ca1130ec..ed4d467e6 100644 --- a/native/src/init/twostage.rs +++ b/native/src/init/twostage.rs @@ -86,7 +86,9 @@ impl MagiskInit { } // 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") .bind_mount_to(cstr!("/sdcard"), false) .log_ok();