1- use std:: {
2- ffi:: { CStr , CString , OsString } ,
3- os:: unix:: ffi:: OsStrExt ,
4- path:: PathBuf ,
5- } ;
1+ use std:: { ffi:: CString , os:: unix:: ffi:: OsStrExt , path:: PathBuf } ;
62
73#[ cfg( target_os = "linux" ) ]
84use libc:: { O_DIRECT , O_SYNC } ;
@@ -99,17 +95,17 @@ impl UhyveFileMap {
9995 /// Returns the host_path on the host filesystem given a requested guest_path, if it exists.
10096 ///
10197 /// * `guest_path` - The guest path that is to be looked up in the map.
102- pub fn get_host_path ( & self , guest_path : & CStr ) -> Option < UhyveMapLeaf > {
103- tree:: resolve_guest_path ( & self . root , guest_path. to_bytes ( ) )
98+ pub fn get_host_path ( & self , guest_path : & str ) -> Option < UhyveMapLeaf > {
99+ tree:: resolve_guest_path ( & self . root , guest_path. as_bytes ( ) )
104100 }
105101
106102 /// Returns an array of all host paths (for Landlock).
107103 #[ cfg( target_os = "linux" ) ]
108- pub ( crate ) fn get_all_host_paths ( & self ) -> impl Iterator < Item = & std:: ffi :: OsStr > {
109- tree:: get_all_host_paths ( & self . root ) . map ( |i| i . as_os_str ( ) )
104+ pub ( crate ) fn get_all_host_paths ( & self ) -> impl Iterator < Item = & std:: path :: Path > {
105+ tree:: get_all_host_paths ( & self . root )
110106 }
111107
112- /// Returns an iterator (non-unique) over all mountable guest directories.
108+ /// Returns an iterator over all mountable guest directories.
113109 pub ( crate ) fn get_all_guest_dirs ( & self ) -> impl Iterator < Item = String > {
114110 tree:: get_all_guest_dirs ( & self . root )
115111 }
@@ -139,15 +135,15 @@ impl UhyveFileMap {
139135 ///
140136 /// Note that this is also used for the entire setup of the uhyve file tree,
141137 /// and this also called for the entire initial mapping.
142- pub fn create_leaf ( & mut self , guest_path : & CStr , file : UhyveMapLeaf ) -> bool {
143- tree:: create_leaf ( & mut self . root , guest_path. to_bytes ( ) , file)
138+ pub fn create_leaf ( & mut self , guest_path : & str , file : UhyveMapLeaf ) -> bool {
139+ tree:: create_leaf ( & mut self . root , guest_path. as_bytes ( ) , file)
144140 }
145141
146142 /// Inserts an opened temporary file into the file map. Returns a CString so that
147143 /// the file can be directly used by [crate::hypercall::open].
148144 ///
149145 /// * `guest_path` - The requested guest path.
150- pub fn create_temporary_file ( & mut self , guest_path : & CStr ) -> Option < CString > {
146+ pub fn create_temporary_file ( & mut self , guest_path : & str ) -> Option < CString > {
151147 let host_path = self . tempdir . path ( ) . join ( Uuid :: new_v4 ( ) . to_string ( ) ) ;
152148 trace ! ( "create_temporary_file (host_path): {host_path:#?}" ) ;
153149 let ret = CString :: new ( host_path. as_os_str ( ) . as_bytes ( ) ) . unwrap ( ) ;
@@ -159,7 +155,7 @@ impl UhyveFileMap {
159155 }
160156
161157 /// Attempt to remove a file. Note that this will fail on non-empty directories.
162- pub fn unlink ( & mut self , guest_path : & CStr ) -> Result < Option < OsString > , ( ) > {
163- tree:: unlink ( & mut self . root , guest_path. to_bytes ( ) ) . map ( |i| i . map ( |j| j . into_os_string ( ) ) )
158+ pub fn unlink ( & mut self , guest_path : & str ) -> Result < Option < PathBuf > , ( ) > {
159+ tree:: unlink ( & mut self . root , guest_path. as_bytes ( ) )
164160 }
165161}
0 commit comments