From 57184b5bf4c4b895cd1a0ddf5f6600afb409bc9c Mon Sep 17 00:00:00 2001 From: Nullptr Date: Fri, 5 Jan 2024 13:33:45 +0800 Subject: [PATCH 1/3] Fix temp dir on Android 10 or below --- userspace/ksud/src/cli.rs | 7 +++++++ userspace/ksud/src/defs.rs | 3 ++- userspace/ksud/src/event.rs | 2 +- userspace/ksud/src/utils.rs | 12 ++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/userspace/ksud/src/cli.rs b/userspace/ksud/src/cli.rs index 9c8f156c61d5..1e918df5a7a6 100644 --- a/userspace/ksud/src/cli.rs +++ b/userspace/ksud/src/cli.rs @@ -48,6 +48,9 @@ enum Commands { command: Profile, }, + /// Print KernelSU tmpfs path + Path, + /// For developers Debug { #[command(subcommand)] @@ -228,6 +231,10 @@ pub fn run() -> Result<()> { Profile::DeleteTemplate { id } => crate::profile::delete_template(id), Profile::ListTemplates => crate::profile::list_templates(), }, + Commands::Path => { + println!("{}", utils::get_tmp_path()); + Ok(()) + }, Commands::Debug { command } => match command { Debug::SetManager { apk } => debug::set_manager(&apk), diff --git a/userspace/ksud/src/defs.rs b/userspace/ksud/src/defs.rs index 5e6e24ba3841..d00c64d4ce9f 100644 --- a/userspace/ksud/src/defs.rs +++ b/userspace/ksud/src/defs.rs @@ -25,7 +25,8 @@ pub const MODULE_UPDATE_TMP_IMG: &str = concatcp!(WORKING_DIR, "update_tmp.img") // warning: this directory should not change, or you need to change the code in module_installer.sh!!! pub const MODULE_UPDATE_TMP_DIR: &str = concatcp!(ADB_DIR, "modules_update/"); -pub const TEMP_DIR: &str = "/debug_ramdisk/"; +pub const TEMP_DIR: &str = "/debug_ramdisk"; +pub const TEMP_DIR_LEGACY: &str = "/sbin"; pub const DISABLE_FILE_NAME: &str = "disable"; pub const UPDATE_FILE_NAME: &str = "update"; diff --git a/userspace/ksud/src/event.rs b/userspace/ksud/src/event.rs index b2106ee66f30..738c64a0a06e 100644 --- a/userspace/ksud/src/event.rs +++ b/userspace/ksud/src/event.rs @@ -179,7 +179,7 @@ pub fn on_post_data_fs() -> Result<()> { } // mount temp dir - if let Err(e) = mount::mount_tmpfs(defs::TEMP_DIR) { + if let Err(e) = mount::mount_tmpfs(utils::get_tmp_path()) { warn!("do temp dir mount failed: {}", e); } diff --git a/userspace/ksud/src/utils.rs b/userspace/ksud/src/utils.rs index 510f0fd9eafd..e4cdf15b9075 100644 --- a/userspace/ksud/src/utils.rs +++ b/userspace/ksud/src/utils.rs @@ -7,8 +7,10 @@ use std::{ #[allow(unused_imports)] use std::fs::{set_permissions, Permissions}; +use std::fs::metadata; #[cfg(unix)] use std::os::unix::prelude::PermissionsExt; +use crate::defs; pub fn ensure_clean_dir(dir: &str) -> Result<()> { let path = Path::new(dir); @@ -163,3 +165,13 @@ pub fn umask(_mask: u32) { pub fn has_magisk() -> bool { which::which("magisk").is_ok() } + +pub fn get_tmp_path() -> &'static str { + if metadata(defs::TEMP_DIR).is_ok() { + return defs::TEMP_DIR; + } + if metadata(defs::TEMP_DIR_LEGACY).is_ok() { + return defs::TEMP_DIR_LEGACY; + } + "" +} From 1e329d8ec8336b0565308ba8e1f97acbc3d18d66 Mon Sep 17 00:00:00 2001 From: Ylarod Date: Fri, 5 Jan 2024 14:29:43 +0800 Subject: [PATCH 2/3] fmt --- userspace/ksud/src/cli.rs | 2 +- userspace/ksud/src/utils.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/userspace/ksud/src/cli.rs b/userspace/ksud/src/cli.rs index 1e918df5a7a6..485ae223577f 100644 --- a/userspace/ksud/src/cli.rs +++ b/userspace/ksud/src/cli.rs @@ -234,7 +234,7 @@ pub fn run() -> Result<()> { Commands::Path => { println!("{}", utils::get_tmp_path()); Ok(()) - }, + } Commands::Debug { command } => match command { Debug::SetManager { apk } => debug::set_manager(&apk), diff --git a/userspace/ksud/src/utils.rs b/userspace/ksud/src/utils.rs index e4cdf15b9075..cdb401277018 100644 --- a/userspace/ksud/src/utils.rs +++ b/userspace/ksud/src/utils.rs @@ -5,12 +5,12 @@ use std::{ path::Path, }; +use crate::defs; +use std::fs::metadata; #[allow(unused_imports)] use std::fs::{set_permissions, Permissions}; -use std::fs::metadata; #[cfg(unix)] use std::os::unix::prelude::PermissionsExt; -use crate::defs; pub fn ensure_clean_dir(dir: &str) -> Result<()> { let path = Path::new(dir); From f9ef7626666d75857f6afade6f969c3b07fbf332 Mon Sep 17 00:00:00 2001 From: Ylarod Date: Fri, 5 Jan 2024 14:35:52 +0800 Subject: [PATCH 3/3] use sbin first --- userspace/ksud/src/utils.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/userspace/ksud/src/utils.rs b/userspace/ksud/src/utils.rs index cdb401277018..50b969621ac1 100644 --- a/userspace/ksud/src/utils.rs +++ b/userspace/ksud/src/utils.rs @@ -167,11 +167,11 @@ pub fn has_magisk() -> bool { } pub fn get_tmp_path() -> &'static str { - if metadata(defs::TEMP_DIR).is_ok() { - return defs::TEMP_DIR; - } if metadata(defs::TEMP_DIR_LEGACY).is_ok() { return defs::TEMP_DIR_LEGACY; } + if metadata(defs::TEMP_DIR).is_ok() { + return defs::TEMP_DIR; + } "" }