ksud: fmt
This commit is contained in:
@@ -200,11 +200,7 @@ fn is_magisk_patched_vendor_init_boot(magiskboot: &Path, workdir: &Path) -> Resu
|
||||
.current_dir(workdir)
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.args([
|
||||
"cpio",
|
||||
vendor_init_boot_cpio.to_str().unwrap(),
|
||||
"test",
|
||||
])
|
||||
.args(["cpio", vendor_init_boot_cpio.to_str().unwrap(), "test"])
|
||||
.status()?;
|
||||
|
||||
// 0: stock, 1: magisk
|
||||
@@ -284,8 +280,12 @@ pub fn restore(
|
||||
|
||||
let no_ramdisk = !workdir.join("ramdisk.cpio").exists();
|
||||
let is_kernelsu_patched = is_kernelsu_patched(&magiskboot, workdir)?;
|
||||
let is_kernelsu_patched_vendor_init_boot = is_kernelsu_patched_vendor_init_boot(&magiskboot, workdir)?;
|
||||
ensure!(is_kernelsu_patched || is_kernelsu_patched_vendor_init_boot, "boot image is not patched by KernelSU");
|
||||
let is_kernelsu_patched_vendor_init_boot =
|
||||
is_kernelsu_patched_vendor_init_boot(&magiskboot, workdir)?;
|
||||
ensure!(
|
||||
is_kernelsu_patched || is_kernelsu_patched_vendor_init_boot,
|
||||
"boot image is not patched by KernelSU"
|
||||
);
|
||||
|
||||
let mut new_boot = None;
|
||||
let mut from_backup = false;
|
||||
@@ -321,7 +321,8 @@ pub fn restore(
|
||||
// vendor init_boot restore
|
||||
do_vendor_init_boot_cpio_cmd(&magiskboot, workdir, "rm kernelsu.ko")?;
|
||||
// if init.real exists, restore it
|
||||
let status = do_vendor_init_boot_cpio_cmd(&magiskboot, workdir, "exists init.real").is_ok();
|
||||
let status =
|
||||
do_vendor_init_boot_cpio_cmd(&magiskboot, workdir, "exists init.real").is_ok();
|
||||
if status {
|
||||
do_vendor_init_boot_cpio_cmd(&magiskboot, workdir, "mv init.real init")?;
|
||||
} else {
|
||||
@@ -524,7 +525,8 @@ fn do_patch(
|
||||
bail!("No compatible ramdisk found.");
|
||||
}
|
||||
let is_magisk_patched = is_magisk_patched(&magiskboot, workdir)?;
|
||||
let is_magisk_patched_vendor_init_boot = is_magisk_patched_vendor_init_boot(&magiskboot, workdir)?;
|
||||
let is_magisk_patched_vendor_init_boot =
|
||||
is_magisk_patched_vendor_init_boot(&magiskboot, workdir)?;
|
||||
ensure!(
|
||||
!is_magisk_patched || !is_magisk_patched_vendor_init_boot,
|
||||
"Cannot work with Magisk patched image"
|
||||
@@ -532,7 +534,8 @@ fn do_patch(
|
||||
|
||||
println!("- Adding KernelSU LKM");
|
||||
let is_kernelsu_patched = is_kernelsu_patched(&magiskboot, workdir)?;
|
||||
let is_kernelsu_patched_vendor_init_boot = is_kernelsu_patched_vendor_init_boot(&magiskboot, workdir)?;
|
||||
let is_kernelsu_patched_vendor_init_boot =
|
||||
is_kernelsu_patched_vendor_init_boot(&magiskboot, workdir)?;
|
||||
|
||||
let mut need_backup = false;
|
||||
if !is_kernelsu_patched || (no_ramdisk && !is_kernelsu_patched_vendor_init_boot) {
|
||||
@@ -740,7 +743,6 @@ fn find_boot_image(
|
||||
Path::new(&format!("/dev/block/by-name/init_boot{slot_suffix}")).exists();
|
||||
let vendor_boot_exist =
|
||||
Path::new(&format!("/dev/block/by-name/vendor_boot{slot_suffix}")).exists();
|
||||
|
||||
let boot_partition = if !is_replace_kernel && init_boot_exist && !skip_init {
|
||||
format!("/dev/block/by-name/init_boot{slot_suffix}")
|
||||
} else if !is_replace_kernel && vendor_boot_exist && !skip_init {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use crate::defs::{KSU_MOUNT_SOURCE, NO_MOUNT_PATH, NO_TMPFS_PATH};
|
||||
use crate::kpm;
|
||||
use crate::module::{handle_updated_modules, prune_modules};
|
||||
use crate::{assets, defs, ksucalls, restorecon, utils};
|
||||
use anyhow::{Context, Result};
|
||||
use log::{info, warn};
|
||||
use rustix::fs::{MountFlags, mount};
|
||||
use std::path::Path;
|
||||
use crate::kpm;
|
||||
|
||||
pub fn on_post_data_fs() -> Result<()> {
|
||||
ksucalls::report_post_fs_data();
|
||||
@@ -72,7 +72,13 @@ pub fn on_post_data_fs() -> Result<()> {
|
||||
|
||||
// mount temp dir
|
||||
if !Path::new(NO_TMPFS_PATH).exists() {
|
||||
if let Err(e) = mount(KSU_MOUNT_SOURCE, utils::get_tmp_path(), "tmpfs", MountFlags::empty(), "") {
|
||||
if let Err(e) = mount(
|
||||
KSU_MOUNT_SOURCE,
|
||||
utils::get_tmp_path(),
|
||||
"tmpfs",
|
||||
MountFlags::empty(),
|
||||
"",
|
||||
) {
|
||||
warn!("do temp dir mount failed: {}", e);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use anyhow::Result;
|
||||
use notify::{Watcher, RecursiveMode};
|
||||
use std::path::Path;
|
||||
use std::fs;
|
||||
use anyhow::anyhow;
|
||||
use notify::{RecursiveMode, Watcher};
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
pub const KPM_DIR: &str = "/data/adb/kpm";
|
||||
pub const KPMMGR_PATH: &str = "/data/adb/ksu/bin/kpmmgr";
|
||||
@@ -28,11 +28,9 @@ pub fn start_kpm_watcher() -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut watcher = notify::recommended_watcher(|res| {
|
||||
match res {
|
||||
let mut watcher = notify::recommended_watcher(|res| match res {
|
||||
Ok(event) => handle_kpm_event(event),
|
||||
Err(e) => log::error!("monitoring error: {:?}", e),
|
||||
}
|
||||
})?;
|
||||
|
||||
watcher.watch(Path::new(KPM_DIR), RecursiveMode::NonRecursive)?;
|
||||
@@ -80,7 +78,9 @@ fn handle_modify_event(paths: Vec<std::path::PathBuf>) {
|
||||
|
||||
// 加载 KPM 模块
|
||||
pub fn load_kpm(path: &Path) -> Result<()> {
|
||||
let path_str = path.to_str().ok_or_else(|| anyhow!("Invalid path: {}", path.display()))?;
|
||||
let path_str = path
|
||||
.to_str()
|
||||
.ok_or_else(|| anyhow!("Invalid path: {}", path.display()))?;
|
||||
let status = std::process::Command::new(KPMMGR_PATH)
|
||||
.args(["load", path_str, ""])
|
||||
.status()?;
|
||||
@@ -168,7 +168,6 @@ pub fn load_kpm_modules() -> Result<()> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if path.extension().is_some_and(|ext| ext == "kpm") {
|
||||
match load_kpm(&path) {
|
||||
Ok(()) => log::info!("Successfully loaded KPM module: {}", path.display()),
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use crate::defs::{
|
||||
DISABLE_FILE_NAME, KSU_MOUNT_SOURCE, MODULE_DIR, SKIP_MOUNT_FILE_NAME,
|
||||
};
|
||||
use crate::defs::{DISABLE_FILE_NAME, KSU_MOUNT_SOURCE, MODULE_DIR, SKIP_MOUNT_FILE_NAME};
|
||||
use crate::magic_mount::NodeFileType::{Directory, RegularFile, Symlink, Whiteout};
|
||||
use crate::restorecon::{lgetfilecon, lsetfilecon};
|
||||
use crate::utils::{ensure_dir_exists, get_work_dir};
|
||||
|
||||
@@ -5,6 +5,7 @@ mod cli;
|
||||
mod debug;
|
||||
mod defs;
|
||||
mod init_event;
|
||||
mod kpm;
|
||||
mod ksucalls;
|
||||
#[cfg(target_os = "android")]
|
||||
mod magic_mount;
|
||||
@@ -14,7 +15,6 @@ mod restorecon;
|
||||
mod sepolicy;
|
||||
mod su;
|
||||
mod utils;
|
||||
mod kpm;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
cli::run()
|
||||
|
||||
@@ -187,13 +187,7 @@ fn is_ok_empty(dir: &str) -> bool {
|
||||
}
|
||||
|
||||
pub fn get_tmp_path() -> String {
|
||||
let dirs = [
|
||||
"/debug_ramdisk",
|
||||
"/patch_hw",
|
||||
"/oem",
|
||||
"/root",
|
||||
"/sbin",
|
||||
];
|
||||
let dirs = ["/debug_ramdisk", "/patch_hw", "/oem", "/root", "/sbin"];
|
||||
|
||||
// find empty directory
|
||||
for dir in dirs {
|
||||
|
||||
Reference in New Issue
Block a user