Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions library/std/src/sys/fs/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ impl File {
}

pub fn fsync(&self) -> io::Result<()> {
unsupported()
self.datasync()
}

pub fn datasync(&self) -> io::Result<()> {
unsupported()
self.0.flush()
}

pub fn lock(&self) -> io::Result<()> {
Expand Down Expand Up @@ -348,8 +348,9 @@ impl File {
false
}

// Write::flush is only meant for buffered writers. So should be noop for unbuffered files.
pub fn flush(&self) -> io::Result<()> {
unsupported()
Ok(())
}
Comment on lines 352 to 354
Copy link
Member

Choose a reason for hiding this comment

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

The Write::flush method should be a noop for Files. It's only meant to flush buffered writers to the OS, since files are unbuffered there's nothing to do.

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 have made it a noop and added a comment for the same. However, while it is a noop on unix and windows, other platforms like motor, solid, etc seem to call normal file flush on it.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know whether those platforms do anything special or it just wasn't caught during review.

CC @lasiotus @kawadakk in case the platforms need fixing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the ping!

Re: flushing a file on Motor OS: the story is a bit complicated: while at the moment the call is a noop, it won't be in the future, as Motor OS is moving towards a fully asynchronous I/O (at the moment file I/O is synchronous) with in-process async runtime, so flushing a file will not stay a noop. The good news is that the call is already plumbed through to Motor OS runtime, so no changes to Rust std are expected.


pub fn seek(&self, _pos: SeekFrom) -> io::Result<u64> {
Expand Down Expand Up @@ -744,6 +745,12 @@ mod uefi_fs {
if r.is_error() { Err(io::Error::from_raw_os_error(r.as_usize())) } else { Ok(()) }
}

pub(crate) fn flush(&self) -> io::Result<()> {
let file_ptr = self.protocol.as_ptr();
let r = unsafe { ((*file_ptr).flush)(file_ptr) };
if r.is_error() { Err(io::Error::from_raw_os_error(r.as_usize())) } else { Ok(()) }
}

pub(crate) fn path(&self) -> &Path {
&self.path
}
Expand Down
Loading