Skip to content

Commit 7a7d4ab

Browse files
authored
Merge pull request #1828 from seijikun/mr-atapassthru-lbamap
uefi: Make AtaDevice::execute_command() return AtaResponse on error
2 parents 43222e3 + 3e8685f commit 7a7d4ab

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

uefi/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
## Changed
1010
- Changed ordering of `proto::pci::PciIoAddress` to (bus -> dev -> fun -> reg -> ext_reg).
11+
- Return request with status as error data object for `proto::ata::pass_thru::AtaDevice`.
1112

1213
# uefi - v0.36.1 (2025-11-05)
1314

uefi/src/proto/ata/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,24 @@ impl<'a> AtaRequestBuilder<'a> {
161161
}
162162

163163
/// Configure the `features` field.
164+
/// FEATURES (7:0)
164165
#[must_use]
165166
pub const fn with_features(mut self, features: u8) -> Self {
166167
self.req.acb.features = features;
167168
self
168169
}
169170

170171
/// Configure the `sector_number` field.
172+
/// LBA (7:0)
171173
#[must_use]
172174
pub const fn with_sector_number(mut self, sector_number: u8) -> Self {
173175
self.req.acb.sector_number = sector_number;
174176
self
175177
}
176178

177179
/// Configure the `cylinder` fields (low and high combined).
180+
/// low: LBA (15:8)
181+
/// high: LBA (23:16)
178182
#[must_use]
179183
pub const fn with_cylinder(mut self, low: u8, high: u8) -> Self {
180184
self.req.acb.cylinder_low = low;
@@ -183,20 +187,24 @@ impl<'a> AtaRequestBuilder<'a> {
183187
}
184188

185189
/// Configure the `device_head` field.
190+
/// DEVICE
186191
#[must_use]
187192
pub const fn with_device_head(mut self, device_head: u8) -> Self {
188193
self.req.acb.device_head = device_head;
189194
self
190195
}
191196

192197
/// Configure the `sector_number_exp` field.
198+
/// LBA (31:24)
193199
#[must_use]
194200
pub const fn with_sector_number_exp(mut self, sector_number_exp: u8) -> Self {
195201
self.req.acb.sector_number_exp = sector_number_exp;
196202
self
197203
}
198204

199205
/// Configure the `cylinder_exp` fields (low and high combined).
206+
/// low_exp: LBA (39:32)
207+
/// high_exp: LBA (47:40)
200208
#[must_use]
201209
pub const fn with_cylinder_exp(mut self, low_exp: u8, high_exp: u8) -> Self {
202210
self.req.acb.cylinder_low_exp = low_exp;
@@ -205,20 +213,23 @@ impl<'a> AtaRequestBuilder<'a> {
205213
}
206214

207215
/// Configure the `features_exp` field.
216+
/// FEATURES (15:8)
208217
#[must_use]
209218
pub const fn with_features_exp(mut self, features_exp: u8) -> Self {
210219
self.req.acb.features_exp = features_exp;
211220
self
212221
}
213222

214223
/// Configure the `sector_count` field.
224+
/// COUNT (7:0)
215225
#[must_use]
216226
pub const fn with_sector_count(mut self, sector_count: u8) -> Self {
217227
self.req.acb.sector_count = sector_count;
218228
self
219229
}
220230

221231
/// Configure the `sector_count_exp` field.
232+
/// COUNT (15:8)
222233
#[must_use]
223234
pub const fn with_sector_count_exp(mut self, sector_count_exp: u8) -> Self {
224235
self.req.acb.sector_count_exp = sector_count_exp;

uefi/src/proto/ata/pass_thru.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,25 @@ impl AtaDevice<'_> {
182182
/// - [`Status::UNSUPPORTED`] The host adapter does not support the command described by the ATA command.
183183
/// The command was not sent, and no additional status information is available.
184184
/// - [`Status::TIMEOUT`] A timeout occurred while waiting for the ATA command to execute. Refer to `Asb` for additional status details.
185+
#[allow(clippy::result_large_err)]
185186
pub fn execute_command<'req>(
186187
&mut self,
187188
mut req: AtaRequest<'req>,
188-
) -> crate::Result<AtaResponse<'req>> {
189+
) -> crate::Result<AtaResponse<'req>, AtaResponse<'req>> {
189190
req.packet.acb = &req.acb;
190-
unsafe {
191+
let result = unsafe {
191192
((*self.proto.get()).pass_thru)(
192193
self.proto.get(),
193194
self.port,
194195
self.pmp,
195196
&mut req.packet,
196197
ptr::null_mut(),
197198
)
198-
.to_result_with_val(|| AtaResponse { req })
199+
.to_result()
200+
};
201+
match result {
202+
Ok(_) => Ok(AtaResponse { req }),
203+
Err(s) => Err(crate::Error::new(s.status(), AtaResponse { req })),
199204
}
200205
}
201206
}

0 commit comments

Comments
 (0)