@@ -10,10 +10,11 @@ mod dir;
10
10
mod info;
11
11
mod regular;
12
12
13
- use crate :: { CStr16 , Char16 , Guid , Result , Status , StatusExt } ;
13
+ use crate :: { CStr16 , Result , Status , StatusExt } ;
14
14
use core:: ffi:: c_void;
15
15
use core:: fmt:: Debug ;
16
16
use core:: { mem, ptr} ;
17
+ use uefi_raw:: protocol:: file_system:: FileProtocolV1 ;
17
18
#[ cfg( all( feature = "unstable" , feature = "alloc" ) ) ]
18
19
use { alloc:: alloc:: Global , core:: alloc:: Allocator } ;
19
20
#[ cfg( feature = "alloc" ) ]
@@ -74,8 +75,8 @@ pub trait File: Sized {
74
75
( self . imp ( ) . open ) (
75
76
self . imp ( ) ,
76
77
& mut ptr,
77
- filename. as_ptr ( ) ,
78
- open_mode,
78
+ filename. as_ptr ( ) . cast ( ) ,
79
+ uefi_raw :: protocol :: file_system :: FileMode :: from_bits_truncate ( open_mode as u64 ) ,
79
80
attributes,
80
81
)
81
82
}
@@ -93,7 +94,7 @@ pub trait File: Sized {
93
94
///
94
95
/// * [`uefi::Status::WARN_DELETE_FAILURE`]
95
96
fn delete ( mut self ) -> Result {
96
- let result = ( self . imp ( ) . delete ) ( self . imp ( ) ) . to_result ( ) ;
97
+ let result = unsafe { ( self . imp ( ) . delete ) ( self . imp ( ) ) } . to_result ( ) ;
97
98
mem:: forget ( self ) ;
98
99
result
99
100
}
@@ -128,7 +129,7 @@ pub trait File: Sized {
128
129
self . imp ( ) ,
129
130
& Info :: GUID ,
130
131
& mut buffer_size,
131
- buffer. as_mut_ptr ( ) ,
132
+ buffer. as_mut_ptr ( ) . cast ( ) ,
132
133
)
133
134
}
134
135
. to_result_with (
@@ -184,7 +185,7 @@ pub trait File: Sized {
184
185
/// * [`uefi::Status::ACCESS_DENIED`]
185
186
/// * [`uefi::Status::VOLUME_FULL`]
186
187
fn flush ( & mut self ) -> Result {
187
- ( self . imp ( ) . flush ) ( self . imp ( ) ) . to_result ( )
188
+ unsafe { ( self . imp ( ) . flush ) ( self . imp ( ) ) } . to_result ( )
188
189
}
189
190
190
191
/// Read the dynamically allocated info for a file.
@@ -224,7 +225,7 @@ pub trait File: Sized {
224
225
225
226
// Internal File helper methods to access the function pointer table.
226
227
trait FileInternal : File {
227
- fn imp ( & mut self ) -> & mut FileImpl {
228
+ fn imp ( & mut self ) -> & mut FileProtocolV1 {
228
229
unsafe { & mut * self . handle ( ) . 0 }
229
230
}
230
231
}
@@ -240,10 +241,10 @@ impl<T: File> FileInternal for T {}
240
241
/// Dropping this structure will result in the file handle being closed.
241
242
#[ repr( transparent) ]
242
243
#[ derive( Debug ) ]
243
- pub struct FileHandle ( * mut FileImpl ) ;
244
+ pub struct FileHandle ( * mut FileProtocolV1 ) ;
244
245
245
246
impl FileHandle {
246
- pub ( super ) const unsafe fn new ( ptr : * mut FileImpl ) -> Self {
247
+ pub ( super ) const unsafe fn new ( ptr : * mut FileProtocolV1 ) -> Self {
247
248
Self ( ptr)
248
249
}
249
250
@@ -296,7 +297,7 @@ impl File for FileHandle {
296
297
// - get_position fails with EFI_UNSUPPORTED on directories
297
298
// - result is an error if the underlying file was already closed or deleted.
298
299
let mut pos = 0 ;
299
- match ( this. get_position ) ( this, & mut pos) {
300
+ match unsafe { ( this. get_position ) ( this, & mut pos) } {
300
301
Status :: SUCCESS => Ok ( true ) ,
301
302
Status :: UNSUPPORTED => Ok ( false ) ,
302
303
s => Err ( s. into ( ) ) ,
@@ -310,65 +311,12 @@ impl File for FileHandle {
310
311
311
312
impl Drop for FileHandle {
312
313
fn drop ( & mut self ) {
313
- let result: Result = ( self . imp ( ) . close ) ( self . imp ( ) ) . to_result ( ) ;
314
+ let result: Result = unsafe { ( self . imp ( ) . close ) ( self . imp ( ) ) } . to_result ( ) ;
314
315
// The spec says this always succeeds.
315
316
result. expect ( "Failed to close file" ) ;
316
317
}
317
318
}
318
319
319
- /// The function pointer table for the File protocol.
320
- #[ repr( C ) ]
321
- pub ( super ) struct FileImpl {
322
- revision : u64 ,
323
- open : unsafe extern "efiapi" fn (
324
- this : & mut FileImpl ,
325
- new_handle : & mut * mut FileImpl ,
326
- filename : * const Char16 ,
327
- open_mode : FileMode ,
328
- attributes : FileAttribute ,
329
- ) -> Status ,
330
- close : extern "efiapi" fn ( this : & mut FileImpl ) -> Status ,
331
- delete : extern "efiapi" fn ( this : & mut FileImpl ) -> Status ,
332
- /// # Read from Regular Files
333
- /// If `self` is not a directory, the function reads the requested number of bytes from the file
334
- /// at the file’s current position and returns them in `buffer`. If the read goes beyond the end
335
- /// of the file, the read length is truncated to the end of the file. The file’s current
336
- /// position is increased by the number of bytes returned.
337
- ///
338
- /// # Read from Directory
339
- /// If `self` is a directory, the function reads the directory entry at the file’s current
340
- /// position and returns the entry in `buffer`. If the `buffer` is not large enough to hold the
341
- /// current directory entry, then `EFI_BUFFER_TOO_SMALL` is returned and the current file
342
- /// position is not updated. `buffer_size` is set to be the size of the buffer needed to read
343
- /// the entry. On success, the current position is updated to the next directory entry. If there
344
- /// are no more directory entries, the read returns a zero-length buffer.
345
- read : unsafe extern "efiapi" fn (
346
- this : & mut FileImpl ,
347
- buffer_size : & mut usize ,
348
- buffer : * mut u8 ,
349
- ) -> Status ,
350
- write : unsafe extern "efiapi" fn (
351
- this : & mut FileImpl ,
352
- buffer_size : & mut usize ,
353
- buffer : * const u8 ,
354
- ) -> Status ,
355
- get_position : extern "efiapi" fn ( this : & mut FileImpl , position : & mut u64 ) -> Status ,
356
- set_position : extern "efiapi" fn ( this : & mut FileImpl , position : u64 ) -> Status ,
357
- get_info : unsafe extern "efiapi" fn (
358
- this : & mut FileImpl ,
359
- information_type : & Guid ,
360
- buffer_size : & mut usize ,
361
- buffer : * mut u8 ,
362
- ) -> Status ,
363
- set_info : unsafe extern "efiapi" fn (
364
- this : & mut FileImpl ,
365
- information_type : & Guid ,
366
- buffer_size : usize ,
367
- buffer : * const c_void ,
368
- ) -> Status ,
369
- flush : extern "efiapi" fn ( this : & mut FileImpl ) -> Status ,
370
- }
371
-
372
320
/// Disambiguate the file type. Returned by `File::into_type()`.
373
321
#[ derive( Debug ) ]
374
322
pub enum FileType {
@@ -399,16 +347,17 @@ pub enum FileMode {
399
347
mod tests {
400
348
use super :: * ;
401
349
use crate :: table:: runtime:: Time ;
402
- use crate :: { CString16 , Identify } ;
350
+ use crate :: { CString16 , Guid , Identify } ;
403
351
use :: alloc:: vec;
352
+ use uefi_raw:: protocol:: file_system:: FileProtocolRevision ;
404
353
405
354
// Test `get_boxed_info` by setting up a fake file, which is mostly
406
355
// just function pointers. Most of the functions can be empty, only
407
356
// get_info is actually implemented to return useful data.
408
357
#[ test]
409
358
fn test_get_boxed_info ( ) {
410
- let mut file_impl = FileImpl {
411
- revision : 0 ,
359
+ let mut file_impl = FileProtocolV1 {
360
+ revision : FileProtocolRevision :: REVISION_1 ,
412
361
open : stub_open,
413
362
close : stub_close,
414
363
delete : stub_delete,
@@ -428,13 +377,13 @@ mod tests {
428
377
assert_eq ! ( info. file_name( ) , CString16 :: try_from( "test_file" ) . unwrap( ) ) ;
429
378
}
430
379
431
- extern "efiapi" fn stub_get_info (
432
- _this : & mut FileImpl ,
433
- information_type : & Guid ,
434
- buffer_size : & mut usize ,
435
- buffer : * mut u8 ,
380
+ unsafe extern "efiapi" fn stub_get_info (
381
+ _this : * mut FileProtocolV1 ,
382
+ information_type : * const Guid ,
383
+ buffer_size : * mut usize ,
384
+ buffer : * mut c_void ,
436
385
) -> Status {
437
- assert_eq ! ( * information_type, FileInfo :: GUID ) ;
386
+ assert_eq ! ( unsafe { * information_type } , FileInfo :: GUID ) ;
438
387
439
388
// Use a temporary buffer to get some file info, then copy that
440
389
// data to the output buffer.
@@ -467,57 +416,60 @@ mod tests {
467
416
}
468
417
469
418
extern "efiapi" fn stub_open (
470
- _this : & mut FileImpl ,
471
- _new_handle : & mut * mut FileImpl ,
472
- _filename : * const Char16 ,
473
- _open_mode : FileMode ,
419
+ _this : * mut FileProtocolV1 ,
420
+ _new_handle : * mut * mut FileProtocolV1 ,
421
+ _filename : * const uefi_raw :: Char16 ,
422
+ _open_mode : uefi_raw :: protocol :: file_system :: FileMode ,
474
423
_attributes : FileAttribute ,
475
424
) -> Status {
476
425
Status :: UNSUPPORTED
477
426
}
478
427
479
- extern "efiapi" fn stub_close ( _this : & mut FileImpl ) -> Status {
428
+ extern "efiapi" fn stub_close ( _this : * mut FileProtocolV1 ) -> Status {
480
429
Status :: SUCCESS
481
430
}
482
431
483
- extern "efiapi" fn stub_delete ( _this : & mut FileImpl ) -> Status {
432
+ extern "efiapi" fn stub_delete ( _this : * mut FileProtocolV1 ) -> Status {
484
433
Status :: UNSUPPORTED
485
434
}
486
435
487
436
extern "efiapi" fn stub_read (
488
- _this : & mut FileImpl ,
489
- _buffer_size : & mut usize ,
490
- _buffer : * mut u8 ,
437
+ _this : * mut FileProtocolV1 ,
438
+ _buffer_size : * mut usize ,
439
+ _buffer : * mut c_void ,
491
440
) -> Status {
492
441
Status :: UNSUPPORTED
493
442
}
494
443
495
444
extern "efiapi" fn stub_write (
496
- _this : & mut FileImpl ,
497
- _buffer_size : & mut usize ,
498
- _buffer : * const u8 ,
445
+ _this : * mut FileProtocolV1 ,
446
+ _buffer_size : * mut usize ,
447
+ _buffer : * const c_void ,
499
448
) -> Status {
500
449
Status :: UNSUPPORTED
501
450
}
502
451
503
- extern "efiapi" fn stub_get_position ( _this : & mut FileImpl , _position : & mut u64 ) -> Status {
452
+ extern "efiapi" fn stub_get_position (
453
+ _this : * const FileProtocolV1 ,
454
+ _position : * mut u64 ,
455
+ ) -> Status {
504
456
Status :: UNSUPPORTED
505
457
}
506
458
507
- extern "efiapi" fn stub_set_position ( _this : & mut FileImpl , _position : u64 ) -> Status {
459
+ extern "efiapi" fn stub_set_position ( _this : * mut FileProtocolV1 , _position : u64 ) -> Status {
508
460
Status :: UNSUPPORTED
509
461
}
510
462
511
463
extern "efiapi" fn stub_set_info (
512
- _this : & mut FileImpl ,
513
- _information_type : & Guid ,
464
+ _this : * mut FileProtocolV1 ,
465
+ _information_type : * const Guid ,
514
466
_buffer_size : usize ,
515
467
_buffer : * const c_void ,
516
468
) -> Status {
517
469
Status :: UNSUPPORTED
518
470
}
519
471
520
- extern "efiapi" fn stub_flush ( _this : & mut FileImpl ) -> Status {
472
+ extern "efiapi" fn stub_flush ( _this : * mut FileProtocolV1 ) -> Status {
521
473
Status :: UNSUPPORTED
522
474
}
523
475
}
0 commit comments