1- use  crate :: defs:: { KSU_MOUNT_SOURCE ,  MODULE_DIR ,  SKIP_MOUNT_FILE_NAME ,  TEMP_DIR } ; 
1+ use  crate :: defs:: { 
2+     DISABLE_FILE_NAME ,  KSU_MOUNT_SOURCE ,  MODULE_DIR ,  SKIP_MOUNT_FILE_NAME ,  TEMP_DIR , 
3+ } ; 
24use  crate :: magic_mount:: NodeFileType :: { Directory ,  RegularFile ,  Symlink ,  Whiteout } ; 
35use  crate :: restorecon:: { lgetfilecon,  lsetfilecon} ; 
46use  anyhow:: { bail,  Context ,  Result } ; 
@@ -49,6 +51,7 @@ struct Node {
4951    // the module that owned this node 
5052    module_path :  Option < PathBuf > , 
5153    replace :  bool , 
54+     skip :  bool , 
5255} 
5356
5457impl  Node  { 
@@ -82,6 +85,7 @@ impl Node {
8285            children :  Default :: default ( ) , 
8386            module_path :  None , 
8487            replace :  false , 
88+             skip :  false , 
8589        } 
8690    } 
8791
@@ -108,6 +112,7 @@ impl Node {
108112                    children :  Default :: default ( ) , 
109113                    module_path :  Some ( path) , 
110114                    replace, 
115+                     skip :  false , 
111116                } ) ; 
112117            } 
113118        } 
@@ -126,7 +131,8 @@ fn collect_module_files() -> Result<Option<Node>> {
126131            continue ; 
127132        } 
128133
129-         if  entry. path ( ) . join ( "disable" ) . exists ( )  || entry. path ( ) . join ( SKIP_MOUNT_FILE_NAME ) . exists ( ) 
134+         if  entry. path ( ) . join ( DISABLE_FILE_NAME ) . exists ( ) 
135+             || entry. path ( ) . join ( SKIP_MOUNT_FILE_NAME ) . exists ( ) 
130136        { 
131137            continue ; 
132138        } 
@@ -255,9 +261,10 @@ fn do_magic_mount<P: AsRef<Path>, WP: AsRef<Path>>(
255261            } 
256262        } 
257263        Directory  => { 
258-             let  mut  create_tmpfs = current. replace ; 
264+             let  mut  create_tmpfs = !has_tmpfs &&  current. replace  && current . module_path . is_some ( ) ; 
259265            if  !has_tmpfs && !create_tmpfs { 
260-                 for  ( name,  node)  in  & current. children  { 
266+                 for  it in  & mut  current. children  { 
267+                     let  ( name,  node)  = it; 
261268                    let  real_path = path. join ( name) ; 
262269                    let  need = match  node. file_type  { 
263270                        Symlink  => true , 
@@ -274,6 +281,14 @@ fn do_magic_mount<P: AsRef<Path>, WP: AsRef<Path>>(
274281                        } 
275282                    } ; 
276283                    if  need { 
284+                         if  current. module_path . is_none ( )  { 
285+                             log:: error!( 
286+                                 "cannot create tmpfs on {}, ignore: {name}" , 
287+                                 path. display( ) 
288+                             ) ; 
289+                             node. skip  = true ; 
290+                             continue ; 
291+                         } 
277292                        create_tmpfs = true ; 
278293                        break ; 
279294                    } 
@@ -320,6 +335,9 @@ fn do_magic_mount<P: AsRef<Path>, WP: AsRef<Path>>(
320335                for  entry in  path. read_dir ( ) ?. flatten ( )  { 
321336                    let  name = entry. file_name ( ) . to_string_lossy ( ) . to_string ( ) ; 
322337                    let  result = if  let  Some ( node)  = current. children . remove ( & name)  { 
338+                         if  node. skip  { 
339+                             continue ; 
340+                         } 
323341                        do_magic_mount ( & path,  & work_dir_path,  node,  has_tmpfs) 
324342                            . with_context ( || format ! ( "magic mount {}/{name}" ,  path. display( ) ) ) 
325343                    }  else  if  has_tmpfs { 
@@ -351,6 +369,9 @@ fn do_magic_mount<P: AsRef<Path>, WP: AsRef<Path>>(
351369            } 
352370
353371            for  ( name,  node)  in  current. children . into_iter ( )  { 
372+                 if  node. skip  { 
373+                     continue ; 
374+                 } 
354375                if  let  Err ( e)  = do_magic_mount ( & path,  & work_dir_path,  node,  has_tmpfs) 
355376                    . with_context ( || format ! ( "magic mount {}/{name}" ,  path. display( ) ) ) 
356377                { 
0 commit comments