1
1
//! Block I/O protocols.
2
2
3
3
use crate :: proto:: unsafe_protocol;
4
- use crate :: { Result , Status , StatusExt } ;
4
+ use crate :: { Result , StatusExt } ;
5
5
6
6
pub use uefi_raw:: protocol:: block:: Lba ;
7
7
8
8
/// The Block I/O protocol.
9
- #[ repr( C ) ]
10
- #[ unsafe_protocol( "964e5b21-6459-11d2-8e39-00a0c969723b" ) ]
11
- pub struct BlockIO {
12
- revision : u64 ,
13
- media : * const BlockIOMedia ,
14
-
15
- reset : extern "efiapi" fn ( this : & BlockIO , extended_verification : bool ) -> Status ,
16
- read_blocks : extern "efiapi" fn (
17
- this : & BlockIO ,
18
- media_id : u32 ,
19
- lba : Lba ,
20
- buffer_size : usize ,
21
- buffer : * mut u8 ,
22
- ) -> Status ,
23
- write_blocks : extern "efiapi" fn (
24
- this : & BlockIO ,
25
- media_id : u32 ,
26
- lba : Lba ,
27
- buffer_size : usize ,
28
- buffer : * const u8 ,
29
- ) -> Status ,
30
- flush_blocks : extern "efiapi" fn ( this : & BlockIO ) -> Status ,
31
- }
9
+ #[ repr( transparent) ]
10
+ #[ unsafe_protocol( uefi_raw:: protocol:: block:: BlockIo :: GUID ) ]
11
+ pub struct BlockIO ( uefi_raw:: protocol:: block:: BlockIo ) ;
32
12
33
13
impl BlockIO {
34
14
/// Pointer for block IO media.
35
15
#[ must_use]
36
16
pub const fn media ( & self ) -> & BlockIOMedia {
37
- unsafe { & * self . media }
17
+ unsafe { & * self . 0 . media . cast :: < BlockIOMedia > ( ) }
38
18
}
39
19
40
20
/// Resets the block device hardware.
@@ -46,7 +26,7 @@ impl BlockIO {
46
26
/// # Errors
47
27
/// * `uefi::Status::DEVICE_ERROR` The block device is not functioning correctly and could not be reset.
48
28
pub fn reset ( & mut self , extended_verification : bool ) -> Result {
49
- ( self . reset ) ( self , extended_verification) . to_result ( )
29
+ unsafe { ( self . 0 . reset ) ( & mut self . 0 , extended_verification) } . to_result ( )
50
30
}
51
31
52
32
/// Read the requested number of blocks from the device.
@@ -67,7 +47,16 @@ impl BlockIO {
67
47
/// proper alignment.
68
48
pub fn read_blocks ( & self , media_id : u32 , lba : Lba , buffer : & mut [ u8 ] ) -> Result {
69
49
let buffer_size = buffer. len ( ) ;
70
- ( self . read_blocks ) ( self , media_id, lba, buffer_size, buffer. as_mut_ptr ( ) ) . to_result ( )
50
+ unsafe {
51
+ ( self . 0 . read_blocks ) (
52
+ & self . 0 ,
53
+ media_id,
54
+ lba,
55
+ buffer_size,
56
+ buffer. as_mut_ptr ( ) . cast ( ) ,
57
+ )
58
+ }
59
+ . to_result ( )
71
60
}
72
61
73
62
/// Writes the requested number of blocks to the device.
@@ -89,7 +78,16 @@ impl BlockIO {
89
78
/// on proper alignment.
90
79
pub fn write_blocks ( & mut self , media_id : u32 , lba : Lba , buffer : & [ u8 ] ) -> Result {
91
80
let buffer_size = buffer. len ( ) ;
92
- ( self . write_blocks ) ( self , media_id, lba, buffer_size, buffer. as_ptr ( ) ) . to_result ( )
81
+ unsafe {
82
+ ( self . 0 . write_blocks ) (
83
+ & mut self . 0 ,
84
+ media_id,
85
+ lba,
86
+ buffer_size,
87
+ buffer. as_ptr ( ) . cast ( ) ,
88
+ )
89
+ }
90
+ . to_result ( )
93
91
}
94
92
95
93
/// Flushes all modified data to a physical block device.
@@ -98,7 +96,7 @@ impl BlockIO {
98
96
/// * `uefi::Status::DEVICE_ERROR` The device reported an error while attempting to write data.
99
97
/// * `uefi::Status::NO_MEDIA` There is no media in the device.
100
98
pub fn flush_blocks ( & mut self ) -> Result {
101
- ( self . flush_blocks ) ( self ) . to_result ( )
99
+ unsafe { ( self . 0 . flush_blocks ) ( & mut self . 0 ) } . to_result ( )
102
100
}
103
101
}
104
102
0 commit comments