ksud: refine mount
- `magic_mount` now takes the tmp_path from its argument - `.notmpfs` and `.nomount` now behave the same skip: ksud: cache tmp path (74ce44de21963fddc83897846eed28eca89d78aa) Co-authored-by: shatyuka <shatyuka@qq.com> Signed-off-by: Faris <rsuntk@yukiprjkt.my.id>
This commit is contained in:
@@ -7,6 +7,7 @@ use crate::{
|
|||||||
module::{handle_updated_modules, prune_modules},
|
module::{handle_updated_modules, prune_modules},
|
||||||
restorecon, uid_scanner, utils,
|
restorecon, uid_scanner, utils,
|
||||||
};
|
};
|
||||||
|
use crate::utils::find_tmp_path;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use rustix::fs::{MountFlags, mount};
|
use rustix::fs::{MountFlags, mount};
|
||||||
@@ -86,11 +87,15 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
warn!("KPM: Failed to load KPM modules: {}", e);
|
warn!("KPM: Failed to load KPM modules: {}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tmpfs_path = find_tmp_path();
|
||||||
|
// for compatibility
|
||||||
|
let no_mount = Path::new(NO_TMPFS_PATH).exists() || Path::new(NO_MOUNT_PATH).exists();
|
||||||
|
|
||||||
// mount temp dir
|
// mount temp dir
|
||||||
if !Path::new(NO_TMPFS_PATH).exists() {
|
if !no_mount {
|
||||||
if let Err(e) = mount(
|
if let Err(e) = mount(
|
||||||
KSU_MOUNT_SOURCE,
|
KSU_MOUNT_SOURCE,
|
||||||
utils::get_tmp_path(),
|
&tmpfs_path,
|
||||||
"tmpfs",
|
"tmpfs",
|
||||||
MountFlags::empty(),
|
MountFlags::empty(),
|
||||||
"",
|
"",
|
||||||
@@ -113,9 +118,10 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mount module systemlessly by magic mount
|
// mount module systemlessly by magic mount
|
||||||
if !Path::new(NO_MOUNT_PATH).exists() {
|
#[cfg(target_os = "android")]
|
||||||
if let Err(e) = mount_modules_systemlessly() {
|
if !no_mount {
|
||||||
warn!("do systemless mount failed: {}", e);
|
if let Err(e) = crate::magic_mount::magic_mount(&tmpfs_path) {
|
||||||
|
warn!("do systemless mount failed: {e}");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info!("no mount requested");
|
info!("no mount requested");
|
||||||
@@ -148,7 +154,7 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
pub fn mount_modules_systemlessly() -> Result<()> {
|
pub fn mount_modules_systemlessly() -> Result<()> {
|
||||||
crate::magic_mount::magic_mount()
|
crate::magic_mount::magic_mount(&find_tmp_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use crate::{
|
|||||||
defs::{DISABLE_FILE_NAME, KSU_MOUNT_SOURCE, MODULE_DIR, SKIP_MOUNT_FILE_NAME},
|
defs::{DISABLE_FILE_NAME, KSU_MOUNT_SOURCE, MODULE_DIR, SKIP_MOUNT_FILE_NAME},
|
||||||
magic_mount::NodeFileType::{Directory, RegularFile, Symlink, Whiteout},
|
magic_mount::NodeFileType::{Directory, RegularFile, Symlink, Whiteout},
|
||||||
restorecon::{lgetfilecon, lsetfilecon},
|
restorecon::{lgetfilecon, lsetfilecon},
|
||||||
utils::{ensure_dir_exists, get_work_dir},
|
utils::get_work_dir,
|
||||||
};
|
};
|
||||||
|
|
||||||
const REPLACE_DIR_XATTR: &str = "trusted.overlay.opaque";
|
const REPLACE_DIR_XATTR: &str = "trusted.overlay.opaque";
|
||||||
@@ -435,10 +435,10 @@ fn do_magic_mount<P: AsRef<Path>, WP: AsRef<Path>>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn magic_mount() -> Result<()> {
|
pub fn magic_mount(tmp_path: &String) -> Result<()> {
|
||||||
if let Some(root) = collect_module_files()? {
|
if let Some(root) = collect_module_files()? {
|
||||||
log::debug!("collected: {:#?}", root);
|
log::debug!("collected: {:#?}", root);
|
||||||
let tmp_dir = PathBuf::from(get_work_dir());
|
let tmp_dir = Path::new(tmp_path).join("workdir");
|
||||||
ensure_dir_exists(&tmp_dir)?;
|
ensure_dir_exists(&tmp_dir)?;
|
||||||
mount(KSU_MOUNT_SOURCE, &tmp_dir, "tmpfs", MountFlags::empty(), "").context("mount tmp")?;
|
mount(KSU_MOUNT_SOURCE, &tmp_dir, "tmpfs", MountFlags::empty(), "").context("mount tmp")?;
|
||||||
mount_change(&tmp_dir, MountPropagationFlags::PRIVATE).context("make tmp private")?;
|
mount_change(&tmp_dir, MountPropagationFlags::PRIVATE).context("make tmp private")?;
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ fn is_ok_empty(dir: &str) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_tmp_path() -> String {
|
pub fn find_tmp_path() -> String {
|
||||||
let dirs = ["/debug_ramdisk", "/patch_hw", "/oem", "/root", "/sbin"];
|
let dirs = ["/debug_ramdisk", "/patch_hw", "/oem", "/root", "/sbin"];
|
||||||
|
|
||||||
// find empty directory
|
// find empty directory
|
||||||
@@ -195,11 +195,6 @@ pub fn get_tmp_path() -> String {
|
|||||||
"".to_string()
|
"".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_work_dir() -> String {
|
|
||||||
let tmp_path = get_tmp_path();
|
|
||||||
format!("{}/workdir/", tmp_path)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
fn link_ksud_to_bin() -> Result<()> {
|
fn link_ksud_to_bin() -> Result<()> {
|
||||||
let ksu_bin = PathBuf::from(defs::DAEMON_PATH);
|
let ksu_bin = PathBuf::from(defs::DAEMON_PATH);
|
||||||
|
|||||||
Reference in New Issue
Block a user