@@ -22,11 +22,8 @@ use rustix::{
22
22
} ;
23
23
use serde:: Deserialize ;
24
24
25
- #[ cfg( feature = "install-to-disk" ) ]
26
- use crate :: task:: Task ;
27
-
28
25
/// Well known identifier for pid 1
29
- pub ( crate ) const PID1 : Pid = const {
26
+ pub const PID1 : Pid = const {
30
27
match Pid :: from_raw ( 1 ) {
31
28
Some ( v) => v,
32
29
None => panic ! ( "Expected to parse pid1" ) ,
@@ -36,21 +33,21 @@ pub(crate) const PID1: Pid = const {
36
33
#[ derive( Deserialize , Debug ) ]
37
34
#[ serde( rename_all = "kebab-case" ) ]
38
35
#[ allow( dead_code) ]
39
- pub ( crate ) struct Filesystem {
36
+ pub struct Filesystem {
40
37
// 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 ,
43
40
#[ 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 > > ,
49
46
}
50
47
51
48
#[ derive( Deserialize , Debug ) ]
52
- pub ( crate ) struct Findmnt {
53
- pub ( crate ) filesystems : Vec < Filesystem > ,
49
+ pub struct Findmnt {
50
+ pub filesystems : Vec < Filesystem > ,
54
51
}
55
52
56
53
fn run_findmnt ( args : & [ & str ] , path : & str ) -> Result < Findmnt > {
@@ -80,20 +77,19 @@ fn findmnt_filesystem(args: &[&str], path: &str) -> Result<Filesystem> {
80
77
#[ context( "Inspecting filesystem {path}" ) ]
81
78
/// Inspect a target which must be a mountpoint root - it is an error
82
79
/// 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 > {
84
81
findmnt_filesystem ( & [ "--mountpoint" ] , path. as_str ( ) )
85
82
}
86
83
87
84
#[ context( "Inspecting filesystem by UUID {uuid}" ) ]
88
85
/// 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 > {
90
87
findmnt_filesystem ( & [ "--source" ] , & ( format ! ( "UUID={uuid}" ) ) )
91
88
}
92
89
93
90
// Check if a specified device contains an already mounted filesystem
94
91
// 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 > {
97
93
let o = run_findmnt ( & [ "-N" ] , "1" ) ?;
98
94
99
95
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> {
102
98
}
103
99
104
100
// 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 {
107
102
if mounted_fs. source . contains ( path) {
108
103
return true ;
109
104
}
@@ -120,21 +115,18 @@ pub(crate) fn is_source_mounted(path: &str, mounted_fs: &Filesystem) -> bool {
120
115
}
121
116
122
117
/// 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 ( )
130
122
}
131
123
132
124
/// If the fsid of the passed path matches the fsid of the same path rooted
133
125
/// at /proc/1/root, it is assumed that these are indeed the same mounted
134
126
/// filesystem between container and host.
135
127
/// Path should be absolute.
136
128
#[ 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 > {
138
130
// Add a leading '/' in case a relative path is passed
139
131
let path = Utf8Path :: new ( "/" ) . join ( path) ;
140
132
@@ -155,7 +147,7 @@ pub(crate) fn is_same_as_host(path: &Utf8Path) -> Result<bool> {
155
147
/// for a mount from that namespace.
156
148
#[ allow( unsafe_code) ]
157
149
#[ context( "Opening mount tree from pid" ) ]
158
- pub ( crate ) fn open_tree_from_pidns (
150
+ pub fn open_tree_from_pidns (
159
151
pid : rustix:: process:: Pid ,
160
152
path : & Utf8Path ,
161
153
recursive : bool ,
@@ -259,7 +251,7 @@ pub(crate) fn open_tree_from_pidns(
259
251
260
252
/// Create a bind mount from the mount namespace of the target pid
261
253
/// into our mount namespace.
262
- pub ( crate ) fn bind_mount_from_pidns (
254
+ pub fn bind_mount_from_pidns (
263
255
pid : Pid ,
264
256
src : & Utf8Path ,
265
257
target : & Utf8Path ,
@@ -279,7 +271,7 @@ pub(crate) fn bind_mount_from_pidns(
279
271
280
272
// If the target path is not already mirrored from the host (e.g. via -v /dev:/dev)
281
273
// 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 < ( ) > {
283
275
let path = path. as_ref ( ) ;
284
276
// If we didn't have this in our filesystem already (e.g. for /var/lib/containers)
285
277
// then create it now.
0 commit comments