1- use std:: {
2- ffi:: { CStr , CString , OsString } ,
3- os:: unix:: ffi:: OsStrExt ,
4- path:: PathBuf ,
5- sync:: Arc ,
6- } ;
1+ use std:: { ffi:: CString , os:: unix:: ffi:: OsStrExt , path:: PathBuf , sync:: Arc } ;
72
83#[ cfg( target_os = "linux" ) ]
94use libc:: { O_DIRECT , O_SYNC } ;
@@ -124,10 +119,7 @@ impl UhyveFileMap {
124119 let data: Arc < [ u8 ] > = i. data ( ) . to_vec ( ) . into ( ) ;
125120
126121 // UNWRAP: `tar_no_std::ArchiveEntry::filename` already truncates at the first null byte.
127- if !self . create_file (
128- & CString :: new ( filename) . unwrap ( ) ,
129- UhyveTreeFile :: Virtual ( data) ,
130- ) {
122+ if !self . create_file ( filename, UhyveTreeFile :: Virtual ( data) ) {
131123 return Err ( HermitImageError :: CreateFile ( filename. to_string ( ) ) ) ;
132124 }
133125 }
@@ -138,17 +130,17 @@ impl UhyveFileMap {
138130 /// Returns the host_path on the host filesystem given a requested guest_path, if it exists.
139131 ///
140132 /// * `guest_path` - The guest path that is to be looked up in the map.
141- pub fn get_host_path ( & self , guest_path : & CStr ) -> Option < UhyveTreeFile > {
142- tree:: resolve_guest_path ( & self . root , guest_path. to_bytes ( ) )
133+ pub fn get_host_path ( & self , guest_path : & str ) -> Option < UhyveTreeFile > {
134+ tree:: resolve_guest_path ( & self . root , guest_path. as_bytes ( ) )
143135 }
144136
145137 /// Returns an array of all host paths (for Landlock).
146138 #[ cfg( target_os = "linux" ) ]
147- pub ( crate ) fn get_all_host_paths ( & self ) -> impl Iterator < Item = & std:: ffi :: OsStr > {
148- tree:: get_all_host_paths ( & self . root ) . map ( |i| i . as_os_str ( ) )
139+ pub ( crate ) fn get_all_host_paths ( & self ) -> impl Iterator < Item = & std:: path :: Path > {
140+ tree:: get_all_host_paths ( & self . root )
149141 }
150142
151- /// Returns an iterator (non-unique) over all mountable guest directories.
143+ /// Returns an iterator over all mountable guest directories.
152144 pub ( crate ) fn get_all_guest_dirs ( & self ) -> impl Iterator < Item = String > {
153145 tree:: get_all_guest_dirs ( & self . root )
154146 }
@@ -178,15 +170,15 @@ impl UhyveFileMap {
178170 ///
179171 /// Note that this is also used for the entire setup of the uhyve file tree,
180172 /// and this also called for the entire initial mapping.
181- pub fn create_file ( & mut self , guest_path : & CStr , file : UhyveTreeFile ) -> bool {
182- tree:: create_file ( & mut self . root , guest_path. to_bytes ( ) , file)
173+ pub fn create_file ( & mut self , guest_path : & str , file : UhyveTreeFile ) -> bool {
174+ tree:: create_file ( & mut self . root , guest_path. as_bytes ( ) , file)
183175 }
184176
185177 /// Inserts an opened temporary file into the file map. Returns a CString so that
186178 /// the file can be directly used by [crate::hypercall::open].
187179 ///
188180 /// * `guest_path` - The requested guest path.
189- pub fn create_temporary_file ( & mut self , guest_path : & CStr ) -> Option < CString > {
181+ pub fn create_temporary_file ( & mut self , guest_path : & str ) -> Option < CString > {
190182 let host_path = self . tempdir . path ( ) . join ( Uuid :: new_v4 ( ) . to_string ( ) ) ;
191183 trace ! ( "create_temporary_file (host_path): {host_path:#?}" ) ;
192184 let ret = CString :: new ( host_path. as_os_str ( ) . as_bytes ( ) ) . unwrap ( ) ;
@@ -198,7 +190,7 @@ impl UhyveFileMap {
198190 }
199191
200192 /// Attempt to remove a file. Note that this will fail on non-empty directories.
201- pub fn unlink ( & mut self , guest_path : & CStr ) -> Result < Option < OsString > , ( ) > {
202- tree:: unlink ( & mut self . root , guest_path. to_bytes ( ) ) . map ( |i| i . map ( |j| j . into_os_string ( ) ) )
193+ pub fn unlink ( & mut self , guest_path : & str ) -> Result < Option < PathBuf > , ( ) > {
194+ tree:: unlink ( & mut self . root , guest_path. as_bytes ( ) )
203195 }
204196}
0 commit comments