1+ use alloc:: borrow:: ToOwned ;
12use alloc:: boxed:: Box ;
23use alloc:: ffi:: CString ;
34use alloc:: string:: { String , ToString } ;
@@ -14,10 +15,11 @@ use uhyve_interface::parameters::{
1415use uhyve_interface:: { GuestPhysAddr , GuestVirtAddr , Hypercall } ;
1516
1617use crate :: arch:: mm:: paging;
17- use crate :: env:: is_uhyve;
18+ use crate :: env:: { self , is_uhyve} ;
1819use crate :: errno:: Errno ;
1920use crate :: fs:: {
2021 self , AccessPermission , FileAttr , NodeKind , ObjectInterface , OpenOption , SeekWhence , VfsNode ,
22+ create_dir_recursive,
2123} ;
2224use crate :: io;
2325use crate :: syscalls:: interfaces:: uhyve:: uhyve_hypercall;
@@ -231,15 +233,48 @@ impl VfsNode for UhyveDirectory {
231233pub ( crate ) fn init ( ) {
232234 info ! ( "Try to initialize uhyve filesystem" ) ;
233235 if is_uhyve ( ) {
234- let mount_point = hermit_var_or ! ( "UHYVE_MOUNT" , "/root" ) . to_string ( ) ;
235- info ! ( "Mounting uhyve filesystem at {mount_point}" ) ;
236- fs:: FILESYSTEM
237- . get ( )
238- . unwrap ( )
239- . mount (
240- & mount_point,
241- Box :: new ( UhyveDirectory :: new ( Some ( mount_point. clone ( ) ) ) ) ,
242- )
243- . expect ( "Mount failed. Duplicate mount_point?" ) ;
236+ let mount_str = env:: fdt ( ) . and_then ( |fdt| {
237+ fdt. find_node ( "/uhyve,mounts" ) . and_then ( |node| {
238+ node. property ( "mounts" )
239+ . and_then ( |property| str:: from_utf8 ( property. value ) . ok ( ) )
240+ } )
241+ } ) ;
242+ if let Some ( mount_str) = mount_str {
243+ for mount_point in mount_str. trim_end_matches ( '\0' ) . split ( '\0' ) {
244+ info ! ( "Mounting uhyve filesystem at {mount_point}" ) ;
245+
246+ if let Err ( errno) = fs:: FILESYSTEM . get ( ) . unwrap ( ) . mount (
247+ mount_point,
248+ Box :: new ( UhyveDirectory :: new ( Some ( mount_point. to_owned ( ) ) ) ) ,
249+ ) {
250+ debug ! (
251+ "Mounting of {mount_point} failed with {errno:?}. Creating missing parent folders"
252+ ) ;
253+ let parent_path = & mount_point[ 0 ..mount_point. rfind ( '/' ) . unwrap ( ) ] ;
254+ create_dir_recursive ( parent_path, AccessPermission :: S_IRWXU ) . unwrap ( ) ;
255+
256+ fs:: FILESYSTEM
257+ . get ( )
258+ . unwrap ( )
259+ . mount (
260+ mount_point,
261+ Box :: new ( UhyveDirectory :: new ( Some ( mount_point. to_owned ( ) ) ) ) ,
262+ )
263+ . unwrap ( ) ;
264+ }
265+ }
266+ } else {
267+ // No FDT -> Uhyve legacy mounting (to /root)
268+ let mount_point = hermit_var_or ! ( "UHYVE_MOUNT" , "/root" ) . to_string ( ) ;
269+ info ! ( "Mounting uhyve filesystem at {mount_point}" ) ;
270+ fs:: FILESYSTEM
271+ . get ( )
272+ . unwrap ( )
273+ . mount (
274+ & mount_point,
275+ Box :: new ( UhyveDirectory :: new ( Some ( mount_point. clone ( ) ) ) ) ,
276+ )
277+ . expect ( "Mount failed. Duplicate mount_point?" ) ;
278+ }
244279 }
245280}
0 commit comments