Skip to content

Add DiskIo and DiskIo2 protocols #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 1, 2022

Conversation

e820
Copy link
Contributor

@e820 e820 commented Jul 14, 2022

Adds the EFI_DISK_IO_PROTOCOL and EFI_DISK_IO2_PROTOCOL protocols from the UEFI specification that build on top of the block I/O protocol to provide byte-oriented disk I/O.

Copy link
Member

@nicholasbishop nicholasbishop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

I think the DiskIo part looks good, but we should consider the safety of the DiskIo2 interface. Since the operations are asynchronous if an Event is passed in via DiskIo2Token, the buffer and token parameters needs to remain valid for the whole lifetime of the request, but this isn't currently enforced. I'm not quite sure what a good safe interface would look like yet. As an intermediate step, we could change the current functions to be unsafe, maybe also rename them to something like read_disk_raw/write_disk_raw, and change the buffer and token parameters to be raw pointers. Alternatively we could try to jump right into figuring out what a safe interface looks like, I'm interested to hear ideas.

Also, it would be good to add some tests for the new protocols. I think these could go in uefi-test-runner/src/proto/media/known_disk.rs.

@e820 e820 force-pushed the protocol-disk-io branch from 505ca9b to 7a75ce2 Compare July 30, 2022 19:54
@e820
Copy link
Contributor Author

e820 commented Jul 30, 2022

DiskIo2's read_disk & write_disk were made unsafe and renamed. I also added a small test for both DiskIo & DiskIo2.

@e820 e820 requested a review from nicholasbishop July 31, 2022 00:29
Copy link
Member

@nicholasbishop nicholasbishop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates and added tests! I added some comments on the tests.

#[repr(C)]
pub struct DiskIo2Token {
/// Event to be signalled when an asynchronous disk I/O operation completes.
pub event: Option<Event>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In trying to track down why the Event never gets signaled, I realized that this struct does not currently have the correct layout. We aren't using NonNull in Event like we do with Handle, so Option<Event> doesn't get the same layout as a raw pointer.

I filed #477 to fix this, but for now this line should be changed to pub event: Event.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case this actually isn't necessary because I interpreted the specification wrong. The spec talks about the token "field" to be nullable, but it seems what it means is that the token argument to ReadDiskEx/WriteDiskEx can be NULL - meaning I could simply change the parameter type.

@e820 e820 requested a review from nicholasbishop July 31, 2022 20:14
@nicholasbishop
Copy link
Member

Looks good, thanks!

@nicholasbishop nicholasbishop merged commit 8833ff9 into rust-osdev:main Aug 1, 2022
@e820 e820 deleted the protocol-disk-io branch August 2, 2022 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants