Skip to content

Commit 9e88900

Browse files
Add BlockIoMedia to uefi-raw
1 parent e960121 commit 9e88900

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

uefi-raw/src/protocol/block.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
11
/// Logical block address.
22
pub type Lba = u64;
3+
4+
/// Media information structure
5+
#[repr(C)]
6+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
7+
pub struct BlockIoMedia {
8+
pub media_id: u32,
9+
pub removable_media: bool,
10+
pub media_present: bool,
11+
pub logical_partition: bool,
12+
pub read_only: bool,
13+
pub write_caching: bool,
14+
pub block_size: u32,
15+
pub io_align: u32,
16+
pub last_block: Lba,
17+
18+
// Added in revision 2.
19+
pub lowest_aligned_lba: Lba,
20+
pub logical_blocks_per_physical_block: u32,
21+
22+
// Added in revision 3.
23+
pub optimal_transfer_length_granularity: u32,
24+
}

uefi/src/proto/media/block.rs

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -103,100 +103,82 @@ impl BlockIO {
103103
}
104104

105105
/// Media information structure
106-
#[repr(C)]
106+
#[repr(transparent)]
107107
#[derive(Debug)]
108-
pub struct BlockIOMedia {
109-
media_id: u32,
110-
removable_media: bool,
111-
media_present: bool,
112-
logical_partition: bool,
113-
read_only: bool,
114-
write_caching: bool,
115-
116-
block_size: u32,
117-
io_align: u32,
118-
last_block: Lba,
119-
120-
// Revision 2
121-
lowest_aligned_lba: Lba,
122-
logical_blocks_per_physical_block: u32,
123-
124-
// Revision 3
125-
optimal_transfer_length_granularity: u32,
126-
}
108+
pub struct BlockIOMedia(uefi_raw::protocol::block::BlockIoMedia);
127109

128110
impl BlockIOMedia {
129111
/// The current media ID.
130112
#[must_use]
131113
pub const fn media_id(&self) -> u32 {
132-
self.media_id
114+
self.0.media_id
133115
}
134116

135117
/// True if the media is removable.
136118
#[must_use]
137119
pub const fn is_removable_media(&self) -> bool {
138-
self.removable_media
120+
self.0.removable_media
139121
}
140122

141123
/// True if there is a media currently present in the device.
142124
#[must_use]
143125
pub const fn is_media_present(&self) -> bool {
144-
self.media_present
126+
self.0.media_present
145127
}
146128

147129
/// True if block IO was produced to abstract partition structure.
148130
#[must_use]
149131
pub const fn is_logical_partition(&self) -> bool {
150-
self.logical_partition
132+
self.0.logical_partition
151133
}
152134

153135
/// True if the media is marked read-only.
154136
#[must_use]
155137
pub const fn is_read_only(&self) -> bool {
156-
self.read_only
138+
self.0.read_only
157139
}
158140

159141
/// True if `writeBlocks` function writes data.
160142
#[must_use]
161143
pub const fn is_write_caching(&self) -> bool {
162-
self.write_caching
144+
self.0.write_caching
163145
}
164146

165147
/// The intrinsic block size of the device.
166148
///
167149
/// If the media changes, then this field is updated. Returns the number of bytes per logical block.
168150
#[must_use]
169151
pub const fn block_size(&self) -> u32 {
170-
self.block_size
152+
self.0.block_size
171153
}
172154

173155
/// Supplies the alignment requirement for any buffer used in a data transfer.
174156
#[must_use]
175157
pub const fn io_align(&self) -> u32 {
176-
self.io_align
158+
self.0.io_align
177159
}
178160

179161
/// The last LBA on the device. If the media changes, then this field is updated.
180162
#[must_use]
181163
pub const fn last_block(&self) -> Lba {
182-
self.last_block
164+
self.0.last_block
183165
}
184166

185167
/// Returns the first LBA that is aligned to a physical block boundary.
186168
#[must_use]
187169
pub const fn lowest_aligned_lba(&self) -> Lba {
188-
self.lowest_aligned_lba
170+
self.0.lowest_aligned_lba
189171
}
190172

191173
/// Returns the number of logical blocks per physical block.
192174
#[must_use]
193175
pub const fn logical_blocks_per_physical_block(&self) -> u32 {
194-
self.logical_blocks_per_physical_block
176+
self.0.logical_blocks_per_physical_block
195177
}
196178

197179
/// Returns the optimal transfer length granularity as a number of logical blocks.
198180
#[must_use]
199181
pub const fn optimal_transfer_length_granularity(&self) -> u32 {
200-
self.optimal_transfer_length_granularity
182+
self.0.optimal_transfer_length_granularity
201183
}
202184
}

0 commit comments

Comments
 (0)