@@ -22,11 +22,8 @@ use rustix::{
2222} ;
2323use serde:: Deserialize ;
2424
25- #[ cfg( feature = "install-to-disk" ) ]
26- use crate :: task:: Task ;
27-
2825/// Well known identifier for pid 1
29- pub ( crate ) const PID1 : Pid = const {
26+ pub const PID1 : Pid = const {
3027 match Pid :: from_raw ( 1 ) {
3128 Some ( v) => v,
3229 None => panic ! ( "Expected to parse pid1" ) ,
@@ -36,21 +33,21 @@ pub(crate) const PID1: Pid = const {
3633#[ derive( Deserialize , Debug ) ]
3734#[ serde( rename_all = "kebab-case" ) ]
3835#[ allow( dead_code) ]
39- pub ( crate ) struct Filesystem {
36+ pub struct Filesystem {
4037 // Note if you add an entry to this list, you need to change the --output invocation below too
41- pub ( crate ) source : String ,
42- pub ( crate ) target : String ,
38+ pub source : String ,
39+ pub target : String ,
4340 #[ serde( rename = "maj:min" ) ]
44- pub ( crate ) maj_min : String ,
45- pub ( crate ) fstype : String ,
46- pub ( crate ) options : String ,
47- pub ( crate ) uuid : Option < String > ,
48- pub ( crate ) children : Option < Vec < Filesystem > > ,
41+ pub maj_min : String ,
42+ pub fstype : String ,
43+ pub options : String ,
44+ pub uuid : Option < String > ,
45+ pub children : Option < Vec < Filesystem > > ,
4946}
5047
5148#[ derive( Deserialize , Debug ) ]
52- pub ( crate ) struct Findmnt {
53- pub ( crate ) filesystems : Vec < Filesystem > ,
49+ pub struct Findmnt {
50+ pub filesystems : Vec < Filesystem > ,
5451}
5552
5653fn run_findmnt ( args : & [ & str ] , path : & str ) -> Result < Findmnt > {
@@ -80,20 +77,19 @@ fn findmnt_filesystem(args: &[&str], path: &str) -> Result<Filesystem> {
8077#[ context( "Inspecting filesystem {path}" ) ]
8178/// Inspect a target which must be a mountpoint root - it is an error
8279/// if the target is not the mount root.
83- pub ( crate ) fn inspect_filesystem ( path : & Utf8Path ) -> Result < Filesystem > {
80+ pub fn inspect_filesystem ( path : & Utf8Path ) -> Result < Filesystem > {
8481 findmnt_filesystem ( & [ "--mountpoint" ] , path. as_str ( ) )
8582}
8683
8784#[ context( "Inspecting filesystem by UUID {uuid}" ) ]
8885/// Inspect a filesystem by partition UUID
89- pub ( crate ) fn inspect_filesystem_by_uuid ( uuid : & str ) -> Result < Filesystem > {
86+ pub fn inspect_filesystem_by_uuid ( uuid : & str ) -> Result < Filesystem > {
9087 findmnt_filesystem ( & [ "--source" ] , & ( format ! ( "UUID={uuid}" ) ) )
9188}
9289
9390// Check if a specified device contains an already mounted filesystem
9491// in the root mount namespace
95- #[ cfg( feature = "install-to-disk" ) ]
96- pub ( crate ) fn is_mounted_in_pid1_mountns ( path : & str ) -> Result < bool > {
92+ pub fn is_mounted_in_pid1_mountns ( path : & str ) -> Result < bool > {
9793 let o = run_findmnt ( & [ "-N" ] , "1" ) ?;
9894
9995 let mounted = o. filesystems . iter ( ) . any ( |fs| is_source_mounted ( path, fs) ) ;
@@ -102,8 +98,7 @@ pub(crate) fn is_mounted_in_pid1_mountns(path: &str) -> Result<bool> {
10298}
10399
104100// Recursively check a given filesystem to see if it contains an already mounted source
105- #[ cfg( feature = "install-to-disk" ) ]
106- pub ( crate ) fn is_source_mounted ( path : & str , mounted_fs : & Filesystem ) -> bool {
101+ pub fn is_source_mounted ( path : & str , mounted_fs : & Filesystem ) -> bool {
107102 if mounted_fs. source . contains ( path) {
108103 return true ;
109104 }
@@ -120,21 +115,18 @@ pub(crate) fn is_source_mounted(path: &str, mounted_fs: &Filesystem) -> bool {
120115}
121116
122117/// Mount a device to the target path.
123- #[ cfg( feature = "install-to-disk" ) ]
124- pub ( crate ) fn mount ( dev : & str , target : & Utf8Path ) -> Result < ( ) > {
125- Task :: new_and_run (
126- format ! ( "Mounting {target}" ) ,
127- "mount" ,
128- [ dev, target. as_str ( ) ] ,
129- )
118+ pub fn mount ( dev : & str , target : & Utf8Path ) -> Result < ( ) > {
119+ Command :: new ( "mount" )
120+ . args ( [ dev, target. as_str ( ) ] )
121+ . run_with_cmd_context ( )
130122}
131123
132124/// If the fsid of the passed path matches the fsid of the same path rooted
133125/// at /proc/1/root, it is assumed that these are indeed the same mounted
134126/// filesystem between container and host.
135127/// Path should be absolute.
136128#[ context( "Comparing filesystems at {path} and /proc/1/root/{path}" ) ]
137- pub ( crate ) fn is_same_as_host ( path : & Utf8Path ) -> Result < bool > {
129+ pub fn is_same_as_host ( path : & Utf8Path ) -> Result < bool > {
138130 // Add a leading '/' in case a relative path is passed
139131 let path = Utf8Path :: new ( "/" ) . join ( path) ;
140132
@@ -155,7 +147,7 @@ pub(crate) fn is_same_as_host(path: &Utf8Path) -> Result<bool> {
155147/// for a mount from that namespace.
156148#[ allow( unsafe_code) ]
157149#[ context( "Opening mount tree from pid" ) ]
158- pub ( crate ) fn open_tree_from_pidns (
150+ pub fn open_tree_from_pidns (
159151 pid : rustix:: process:: Pid ,
160152 path : & Utf8Path ,
161153 recursive : bool ,
@@ -259,7 +251,7 @@ pub(crate) fn open_tree_from_pidns(
259251
260252/// Create a bind mount from the mount namespace of the target pid
261253/// into our mount namespace.
262- pub ( crate ) fn bind_mount_from_pidns (
254+ pub fn bind_mount_from_pidns (
263255 pid : Pid ,
264256 src : & Utf8Path ,
265257 target : & Utf8Path ,
@@ -279,7 +271,7 @@ pub(crate) fn bind_mount_from_pidns(
279271
280272// If the target path is not already mirrored from the host (e.g. via -v /dev:/dev)
281273// then recursively mount it.
282- pub ( crate ) fn ensure_mirrored_host_mount ( path : impl AsRef < Utf8Path > ) -> Result < ( ) > {
274+ pub fn ensure_mirrored_host_mount ( path : impl AsRef < Utf8Path > ) -> Result < ( ) > {
283275 let path = path. as_ref ( ) ;
284276 // If we didn't have this in our filesystem already (e.g. for /var/lib/containers)
285277 // then create it now.
0 commit comments