@@ -14,6 +14,7 @@ use r_efi::protocols::{device_path, device_path_to_text, shell};
14
14
15
15
use crate :: ffi:: { OsStr , OsString } ;
16
16
use crate :: io:: { self , const_error} ;
17
+ use crate :: iter:: Iterator ;
17
18
use crate :: mem:: { MaybeUninit , size_of} ;
18
19
use crate :: os:: uefi:: env:: boot_services;
19
20
use crate :: os:: uefi:: ffi:: { OsStrExt , OsStringExt } ;
@@ -222,14 +223,14 @@ pub(crate) fn runtime_services() -> Option<NonNull<r_efi::efi::RuntimeServices>>
222
223
NonNull :: new ( runtime_services)
223
224
}
224
225
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 > ) ;
226
227
227
- impl DevicePath {
228
+ impl OwnedDevicePath {
228
229
pub ( crate ) fn from_text ( p : & OsStr ) -> io:: Result < Self > {
229
230
fn inner (
230
231
p : & OsStr ,
231
232
protocol : NonNull < r_efi:: protocols:: device_path_from_text:: Protocol > ,
232
- ) -> io:: Result < DevicePath > {
233
+ ) -> io:: Result < OwnedDevicePath > {
233
234
let path_vec = p. encode_wide ( ) . chain ( Some ( 0 ) ) . collect :: < Vec < u16 > > ( ) ;
234
235
if path_vec[ ..path_vec. len ( ) - 1 ] . contains ( & 0 ) {
235
236
return Err ( const_error ! (
@@ -242,7 +243,7 @@ impl DevicePath {
242
243
unsafe { ( ( * protocol. as_ptr ( ) ) . convert_text_to_device_path ) ( path_vec. as_ptr ( ) ) } ;
243
244
244
245
NonNull :: new ( path)
245
- . map ( DevicePath )
246
+ . map ( OwnedDevicePath )
246
247
. ok_or_else ( || const_error ! ( io:: ErrorKind :: InvalidFilename , "Invalid Device Path" ) )
247
248
}
248
249
@@ -275,12 +276,12 @@ impl DevicePath {
275
276
) )
276
277
}
277
278
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 {
279
280
self . 0 . as_ptr ( )
280
281
}
281
282
}
282
283
283
- impl Drop for DevicePath {
284
+ impl Drop for OwnedDevicePath {
284
285
fn drop ( & mut self ) {
285
286
if let Some ( bt) = boot_services ( ) {
286
287
let bt: NonNull < r_efi:: efi:: BootServices > = bt. cast ( ) ;
@@ -291,6 +292,13 @@ impl Drop for DevicePath {
291
292
}
292
293
}
293
294
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
+
294
302
pub ( crate ) struct OwnedProtocol < T > {
295
303
guid : r_efi:: efi:: Guid ,
296
304
handle : NonNull < crate :: ffi:: c_void > ,
0 commit comments