Skip to content

Commit 23e3528

Browse files
authored
Rollup merge of rust-lang#150862 - uefi-fs-flush, r=the8472
std: sys: fs: uefi: Implement File::flush - Also forward fsync and datasync to flush. UEFI does not have anything separate for metadata sync. @rustbot label +O-UEFI
2 parents 2ba1963 + f6f901f commit 23e3528

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

library/std/src/sys/fs/uefi.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,11 @@ impl File {
285285
}
286286

287287
pub fn fsync(&self) -> io::Result<()> {
288-
unsupported()
288+
self.datasync()
289289
}
290290

291291
pub fn datasync(&self) -> io::Result<()> {
292-
unsupported()
292+
self.0.flush()
293293
}
294294

295295
pub fn lock(&self) -> io::Result<()> {
@@ -348,8 +348,9 @@ impl File {
348348
false
349349
}
350350

351+
// Write::flush is only meant for buffered writers. So should be noop for unbuffered files.
351352
pub fn flush(&self) -> io::Result<()> {
352-
unsupported()
353+
Ok(())
353354
}
354355

355356
pub fn seek(&self, _pos: SeekFrom) -> io::Result<u64> {
@@ -784,6 +785,12 @@ mod uefi_fs {
784785
if r.is_error() { Err(io::Error::from_raw_os_error(r.as_usize())) } else { Ok(()) }
785786
}
786787

788+
pub(crate) fn flush(&self) -> io::Result<()> {
789+
let file_ptr = self.protocol.as_ptr();
790+
let r = unsafe { ((*file_ptr).flush)(file_ptr) };
791+
if r.is_error() { Err(io::Error::from_raw_os_error(r.as_usize())) } else { Ok(()) }
792+
}
793+
787794
pub(crate) fn path(&self) -> &Path {
788795
&self.path
789796
}

0 commit comments

Comments
 (0)