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
+
6
+ pub use uefi_raw:: protocol:: block:: Lba ;
5
7
6
8
/// The Block I/O protocol.
7
- #[ repr( C ) ]
8
- #[ unsafe_protocol( "964e5b21-6459-11d2-8e39-00a0c969723b" ) ]
9
- pub struct BlockIO {
10
- revision : u64 ,
11
- media : * const BlockIOMedia ,
12
-
13
- reset : extern "efiapi" fn ( this : & BlockIO , extended_verification : bool ) -> Status ,
14
- read_blocks : extern "efiapi" fn (
15
- this : & BlockIO ,
16
- media_id : u32 ,
17
- lba : Lba ,
18
- buffer_size : usize ,
19
- buffer : * mut u8 ,
20
- ) -> Status ,
21
- write_blocks : extern "efiapi" fn (
22
- this : & BlockIO ,
23
- media_id : u32 ,
24
- lba : Lba ,
25
- buffer_size : usize ,
26
- buffer : * const u8 ,
27
- ) -> Status ,
28
- flush_blocks : extern "efiapi" fn ( this : & BlockIO ) -> Status ,
29
- }
9
+ #[ repr( transparent) ]
10
+ #[ unsafe_protocol( uefi_raw:: protocol:: block:: BlockIo :: GUID ) ]
11
+ pub struct BlockIO ( uefi_raw:: protocol:: block:: BlockIo ) ;
30
12
31
13
impl BlockIO {
32
14
/// Pointer for block IO media.
33
15
#[ must_use]
34
16
pub const fn media ( & self ) -> & BlockIOMedia {
35
- unsafe { & * self . media }
17
+ unsafe { & * self . 0 . media . cast :: < BlockIOMedia > ( ) }
36
18
}
37
19
38
20
/// Resets the block device hardware.
@@ -44,7 +26,7 @@ impl BlockIO {
44
26
/// # Errors
45
27
/// * `uefi::Status::DEVICE_ERROR` The block device is not functioning correctly and could not be reset.
46
28
pub fn reset ( & mut self , extended_verification : bool ) -> Result {
47
- ( self . reset ) ( self , extended_verification) . to_result ( )
29
+ unsafe { ( self . 0 . reset ) ( & mut self . 0 , extended_verification) } . to_result ( )
48
30
}
49
31
50
32
/// Read the requested number of blocks from the device.
@@ -65,7 +47,16 @@ impl BlockIO {
65
47
/// proper alignment.
66
48
pub fn read_blocks ( & self , media_id : u32 , lba : Lba , buffer : & mut [ u8 ] ) -> Result {
67
49
let buffer_size = buffer. len ( ) ;
68
- ( 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 ( )
69
60
}
70
61
71
62
/// Writes the requested number of blocks to the device.
@@ -87,7 +78,16 @@ impl BlockIO {
87
78
/// on proper alignment.
88
79
pub fn write_blocks ( & mut self , media_id : u32 , lba : Lba , buffer : & [ u8 ] ) -> Result {
89
80
let buffer_size = buffer. len ( ) ;
90
- ( 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 ( )
91
91
}
92
92
93
93
/// Flushes all modified data to a physical block device.
@@ -96,108 +96,87 @@ impl BlockIO {
96
96
/// * `uefi::Status::DEVICE_ERROR` The device reported an error while attempting to write data.
97
97
/// * `uefi::Status::NO_MEDIA` There is no media in the device.
98
98
pub fn flush_blocks ( & mut self ) -> Result {
99
- ( self . flush_blocks ) ( self ) . to_result ( )
99
+ unsafe { ( self . 0 . flush_blocks ) ( & mut self . 0 ) } . to_result ( )
100
100
}
101
101
}
102
102
103
- /// EFI LBA type
104
- pub type Lba = u64 ;
105
-
106
103
/// Media information structure
107
- #[ repr( C ) ]
104
+ #[ repr( transparent ) ]
108
105
#[ derive( Debug ) ]
109
- pub struct BlockIOMedia {
110
- media_id : u32 ,
111
- removable_media : bool ,
112
- media_present : bool ,
113
- logical_partition : bool ,
114
- read_only : bool ,
115
- write_caching : bool ,
116
-
117
- block_size : u32 ,
118
- io_align : u32 ,
119
- last_block : Lba ,
120
-
121
- // Revision 2
122
- lowest_aligned_lba : Lba ,
123
- logical_blocks_per_physical_block : u32 ,
124
-
125
- // Revision 3
126
- optimal_transfer_length_granularity : u32 ,
127
- }
106
+ pub struct BlockIOMedia ( uefi_raw:: protocol:: block:: BlockIoMedia ) ;
128
107
129
108
impl BlockIOMedia {
130
109
/// The current media ID.
131
110
#[ must_use]
132
111
pub const fn media_id ( & self ) -> u32 {
133
- self . media_id
112
+ self . 0 . media_id
134
113
}
135
114
136
115
/// True if the media is removable.
137
116
#[ must_use]
138
117
pub const fn is_removable_media ( & self ) -> bool {
139
- self . removable_media
118
+ self . 0 . removable_media
140
119
}
141
120
142
121
/// True if there is a media currently present in the device.
143
122
#[ must_use]
144
123
pub const fn is_media_present ( & self ) -> bool {
145
- self . media_present
124
+ self . 0 . media_present
146
125
}
147
126
148
127
/// True if block IO was produced to abstract partition structure.
149
128
#[ must_use]
150
129
pub const fn is_logical_partition ( & self ) -> bool {
151
- self . logical_partition
130
+ self . 0 . logical_partition
152
131
}
153
132
154
133
/// True if the media is marked read-only.
155
134
#[ must_use]
156
135
pub const fn is_read_only ( & self ) -> bool {
157
- self . read_only
136
+ self . 0 . read_only
158
137
}
159
138
160
139
/// True if `writeBlocks` function writes data.
161
140
#[ must_use]
162
141
pub const fn is_write_caching ( & self ) -> bool {
163
- self . write_caching
142
+ self . 0 . write_caching
164
143
}
165
144
166
145
/// The intrinsic block size of the device.
167
146
///
168
147
/// If the media changes, then this field is updated. Returns the number of bytes per logical block.
169
148
#[ must_use]
170
149
pub const fn block_size ( & self ) -> u32 {
171
- self . block_size
150
+ self . 0 . block_size
172
151
}
173
152
174
153
/// Supplies the alignment requirement for any buffer used in a data transfer.
175
154
#[ must_use]
176
155
pub const fn io_align ( & self ) -> u32 {
177
- self . io_align
156
+ self . 0 . io_align
178
157
}
179
158
180
159
/// The last LBA on the device. If the media changes, then this field is updated.
181
160
#[ must_use]
182
161
pub const fn last_block ( & self ) -> Lba {
183
- self . last_block
162
+ self . 0 . last_block
184
163
}
185
164
186
165
/// Returns the first LBA that is aligned to a physical block boundary.
187
166
#[ must_use]
188
167
pub const fn lowest_aligned_lba ( & self ) -> Lba {
189
- self . lowest_aligned_lba
168
+ self . 0 . lowest_aligned_lba
190
169
}
191
170
192
171
/// Returns the number of logical blocks per physical block.
193
172
#[ must_use]
194
173
pub const fn logical_blocks_per_physical_block ( & self ) -> u32 {
195
- self . logical_blocks_per_physical_block
174
+ self . 0 . logical_blocks_per_physical_block
196
175
}
197
176
198
177
/// Returns the optimal transfer length granularity as a number of logical blocks.
199
178
#[ must_use]
200
179
pub const fn optimal_transfer_length_granularity ( & self ) -> u32 {
201
- self . optimal_transfer_length_granularity
180
+ self . 0 . optimal_transfer_length_granularity
202
181
}
203
182
}
0 commit comments