@@ -63,21 +63,18 @@ pub fn mount_ext4(source: impl AsRef<Path>, target: impl AsRef<Path>) -> Result<
6363 . attach ( source)
6464 . with_context ( || "Failed to attach loop" ) ?;
6565 let lo = new_loopback. path ( ) . ok_or ( anyhow ! ( "no loop" ) ) ?;
66- if let Result :: Ok ( fs) = fsopen ( "ext4" , FsOpenFlags :: FSOPEN_CLOEXEC ) {
67- let fs = fs. as_fd ( ) ;
68- fsconfig_set_string ( fs, "source" , lo) ?;
69- fsconfig_create ( fs) ?;
70- let mount = fsmount ( fs, FsMountFlags :: FSMOUNT_CLOEXEC , MountAttrFlags :: empty ( ) ) ?;
71- move_mount (
72- mount. as_fd ( ) ,
73- "" ,
74- CWD ,
75- target. as_ref ( ) ,
76- MoveMountFlags :: MOVE_MOUNT_F_EMPTY_PATH ,
77- ) ?;
78- } else {
79- mount ( lo, target. as_ref ( ) , "ext4" , MountFlags :: empty ( ) , "" ) ?;
80- }
66+ let fs = fsopen ( "ext4" , FsOpenFlags :: FSOPEN_CLOEXEC ) ?;
67+ let fs = fs. as_fd ( ) ;
68+ fsconfig_set_string ( fs, "source" , lo) ?;
69+ fsconfig_create ( fs) ?;
70+ let mount = fsmount ( fs, FsMountFlags :: FSMOUNT_CLOEXEC , MountAttrFlags :: empty ( ) ) ?;
71+ move_mount (
72+ mount. as_fd ( ) ,
73+ "" ,
74+ CWD ,
75+ target. as_ref ( ) ,
76+ MoveMountFlags :: MOVE_MOUNT_F_EMPTY_PATH ,
77+ ) ?;
8178 Ok ( ( ) )
8279}
8380
@@ -157,27 +154,18 @@ pub fn mount_overlayfs(
157154#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
158155pub fn mount_tmpfs ( dest : impl AsRef < Path > ) -> Result < ( ) > {
159156 info ! ( "mount tmpfs on {}" , dest. as_ref( ) . display( ) ) ;
160- if let Result :: Ok ( fs) = fsopen ( "tmpfs" , FsOpenFlags :: FSOPEN_CLOEXEC ) {
161- let fs = fs. as_fd ( ) ;
162- fsconfig_set_string ( fs, "source" , KSU_OVERLAY_SOURCE ) ?;
163- fsconfig_create ( fs) ?;
164- let mount = fsmount ( fs, FsMountFlags :: FSMOUNT_CLOEXEC , MountAttrFlags :: empty ( ) ) ?;
165- move_mount (
166- mount. as_fd ( ) ,
167- "" ,
168- CWD ,
169- dest. as_ref ( ) ,
170- MoveMountFlags :: MOVE_MOUNT_F_EMPTY_PATH ,
171- ) ?;
172- } else {
173- mount (
174- KSU_OVERLAY_SOURCE ,
175- dest. as_ref ( ) ,
176- "tmpfs" ,
177- MountFlags :: empty ( ) ,
178- "" ,
179- ) ?;
180- }
157+ let fs = fsopen ( "tmpfs" , FsOpenFlags :: FSOPEN_CLOEXEC ) ?;
158+ let fs = fs. as_fd ( ) ;
159+ fsconfig_set_string ( fs, "source" , KSU_OVERLAY_SOURCE ) ?;
160+ fsconfig_create ( fs) ?;
161+ let mount = fsmount ( fs, FsMountFlags :: FSMOUNT_CLOEXEC , MountAttrFlags :: empty ( ) ) ?;
162+ move_mount (
163+ mount. as_fd ( ) ,
164+ "" ,
165+ CWD ,
166+ dest. as_ref ( ) ,
167+ MoveMountFlags :: MOVE_MOUNT_F_EMPTY_PATH ,
168+ ) ?;
181169 Ok ( ( ) )
182170}
183171
@@ -188,29 +176,20 @@ pub fn bind_mount(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
188176 from. as_ref( ) . display( ) ,
189177 to. as_ref( ) . display( )
190178 ) ;
191- if let Result :: Ok ( tree) = open_tree (
179+ let tree = open_tree (
192180 CWD ,
193181 from. as_ref ( ) ,
194182 OpenTreeFlags :: OPEN_TREE_CLOEXEC
195183 | OpenTreeFlags :: OPEN_TREE_CLONE
196184 | OpenTreeFlags :: AT_RECURSIVE ,
197- ) {
198- move_mount (
199- tree. as_fd ( ) ,
200- "" ,
201- CWD ,
202- to. as_ref ( ) ,
203- MoveMountFlags :: MOVE_MOUNT_F_EMPTY_PATH ,
204- ) ?;
205- } else {
206- mount (
207- from. as_ref ( ) ,
208- to. as_ref ( ) ,
209- "" ,
210- MountFlags :: BIND | MountFlags :: REC ,
211- "" ,
212- ) ?;
213- }
185+ ) ?;
186+ move_mount (
187+ tree. as_fd ( ) ,
188+ "" ,
189+ CWD ,
190+ to. as_ref ( ) ,
191+ MoveMountFlags :: MOVE_MOUNT_F_EMPTY_PATH ,
192+ ) ?;
214193 Ok ( ( ) )
215194}
216195
0 commit comments