From 44f13e4a1fc327f2100c42bc8d28df2ad43ef5e2 Mon Sep 17 00:00:00 2001 From: 5ec1cff Date: Fri, 22 Nov 2024 21:46:44 +0800 Subject: [PATCH] magic_mount: refine --- userspace/ksud/src/magic_mount.rs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/userspace/ksud/src/magic_mount.rs b/userspace/ksud/src/magic_mount.rs index d6793d75..22cfcc76 100644 --- a/userspace/ksud/src/magic_mount.rs +++ b/userspace/ksud/src/magic_mount.rs @@ -1,4 +1,6 @@ -use crate::defs::{KSU_MOUNT_SOURCE, MODULE_DIR, SKIP_MOUNT_FILE_NAME, TEMP_DIR}; +use crate::defs::{ + DISABLE_FILE_NAME, KSU_MOUNT_SOURCE, MODULE_DIR, SKIP_MOUNT_FILE_NAME, TEMP_DIR, +}; use crate::magic_mount::NodeFileType::{Directory, RegularFile, Symlink, Whiteout}; use crate::restorecon::{lgetfilecon, lsetfilecon}; use anyhow::{bail, Context, Result}; @@ -49,6 +51,7 @@ struct Node { // the module that owned this node module_path: Option, replace: bool, + skip: bool, } impl Node { @@ -82,6 +85,7 @@ impl Node { children: Default::default(), module_path: None, replace: false, + skip: false, } } @@ -108,6 +112,7 @@ impl Node { children: Default::default(), module_path: Some(path), replace, + skip: false, }); } } @@ -126,7 +131,8 @@ fn collect_module_files() -> Result> { continue; } - if entry.path().join("disable").exists() || entry.path().join(SKIP_MOUNT_FILE_NAME).exists() + if entry.path().join(DISABLE_FILE_NAME).exists() + || entry.path().join(SKIP_MOUNT_FILE_NAME).exists() { continue; } @@ -255,9 +261,10 @@ fn do_magic_mount, WP: AsRef>( } } Directory => { - let mut create_tmpfs = current.replace; + let mut create_tmpfs = !has_tmpfs && current.replace && current.module_path.is_some(); if !has_tmpfs && !create_tmpfs { - for (name, node) in ¤t.children { + for it in &mut current.children { + let (name, node) = it; let real_path = path.join(name); let need = match node.file_type { Symlink => true, @@ -274,6 +281,14 @@ fn do_magic_mount, WP: AsRef>( } }; if need { + if current.module_path.is_none() { + log::error!( + "cannot create tmpfs on {}, ignore: {name}", + path.display() + ); + node.skip = true; + continue; + } create_tmpfs = true; break; } @@ -320,6 +335,9 @@ fn do_magic_mount, WP: AsRef>( for entry in path.read_dir()?.flatten() { let name = entry.file_name().to_string_lossy().to_string(); let result = if let Some(node) = current.children.remove(&name) { + if node.skip { + continue; + } do_magic_mount(&path, &work_dir_path, node, has_tmpfs) .with_context(|| format!("magic mount {}/{name}", path.display())) } else if has_tmpfs { @@ -351,6 +369,9 @@ fn do_magic_mount, WP: AsRef>( } for (name, node) in current.children.into_iter() { + if node.skip { + continue; + } if let Err(e) = do_magic_mount(&path, &work_dir_path, node, has_tmpfs) .with_context(|| format!("magic mount {}/{name}", path.display())) {