@@ -14,6 +14,7 @@ use r_efi::protocols::{device_path, device_path_to_text, shell};
1414
1515use crate :: ffi:: { OsStr , OsString } ;
1616use crate :: io:: { self , const_error} ;
17+ use crate :: iter:: Iterator ;
1718use crate :: mem:: { MaybeUninit , size_of} ;
1819use crate :: os:: uefi:: env:: boot_services;
1920use crate :: os:: uefi:: ffi:: { OsStrExt , OsStringExt } ;
@@ -222,14 +223,14 @@ pub(crate) fn runtime_services() -> Option<NonNull<r_efi::efi::RuntimeServices>>
222223 NonNull :: new ( runtime_services)
223224}
224225
225- pub ( crate ) struct DevicePath ( NonNull < r_efi:: protocols:: device_path:: Protocol > ) ;
226+ pub ( crate ) struct OwnedDevicePath ( pub ( crate ) NonNull < r_efi:: protocols:: device_path:: Protocol > ) ;
226227
227- impl DevicePath {
228+ impl OwnedDevicePath {
228229 pub ( crate ) fn from_text ( p : & OsStr ) -> io:: Result < Self > {
229230 fn inner (
230231 p : & OsStr ,
231232 protocol : NonNull < r_efi:: protocols:: device_path_from_text:: Protocol > ,
232- ) -> io:: Result < DevicePath > {
233+ ) -> io:: Result < OwnedDevicePath > {
233234 let path_vec = p. encode_wide ( ) . chain ( Some ( 0 ) ) . collect :: < Vec < u16 > > ( ) ;
234235 if path_vec[ ..path_vec. len ( ) - 1 ] . contains ( & 0 ) {
235236 return Err ( const_error ! (
@@ -242,7 +243,7 @@ impl DevicePath {
242243 unsafe { ( ( * protocol. as_ptr ( ) ) . convert_text_to_device_path ) ( path_vec. as_ptr ( ) ) } ;
243244
244245 NonNull :: new ( path)
245- . map ( DevicePath )
246+ . map ( OwnedDevicePath )
246247 . ok_or_else ( || const_error ! ( io:: ErrorKind :: InvalidFilename , "Invalid Device Path" ) )
247248 }
248249
@@ -275,12 +276,12 @@ impl DevicePath {
275276 ) )
276277 }
277278
278- pub ( crate ) fn as_ptr ( & self ) -> * mut r_efi:: protocols:: device_path:: Protocol {
279+ pub ( crate ) const fn as_ptr ( & self ) -> * mut r_efi:: protocols:: device_path:: Protocol {
279280 self . 0 . as_ptr ( )
280281 }
281282}
282283
283- impl Drop for DevicePath {
284+ impl Drop for OwnedDevicePath {
284285 fn drop ( & mut self ) {
285286 if let Some ( bt) = boot_services ( ) {
286287 let bt: NonNull < r_efi:: efi:: BootServices > = bt. cast ( ) ;
@@ -291,6 +292,13 @@ impl Drop for DevicePath {
291292 }
292293}
293294
295+ impl crate :: fmt:: Debug for OwnedDevicePath {
296+ fn fmt ( & self , f : & mut crate :: fmt:: Formatter < ' _ > ) -> crate :: fmt:: Result {
297+ let p = device_path_to_text ( self . 0 ) . unwrap ( ) ;
298+ p. fmt ( f)
299+ }
300+ }
301+
294302pub ( crate ) struct OwnedProtocol < T > {
295303 guid : r_efi:: efi:: Guid ,
296304 handle : NonNull < crate :: ffi:: c_void > ,
0 commit comments