From ad63c14489372506b67e976ae2cb28164d75a8b0 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Sat, 10 Oct 2015 11:53:59 -0700 Subject: Add support for fsync, fdatasync --- src/unistd.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src') diff --git a/src/unistd.rs b/src/unistd.rs index d93355d6..65a9f9c9 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -60,6 +60,11 @@ mod ffi { // change root directory // doc: http://man7.org/linux/man-pages/man2/chroot.2.html pub fn chroot(path: *const c_char) -> c_int; + + // synchronize a file's in-core state with storage device + // doc: http://man7.org/linux/man-pages/man2/fsync.2.html + pub fn fsync(fd: c_int) -> c_int; + pub fn fdatasync(fd: c_int) -> c_int; } } @@ -356,6 +361,28 @@ pub fn chroot(path: &P) -> Result<()> { Ok(()) } +#[inline] +pub fn fsync(fd: RawFd) -> Result<()> { + let res = unsafe { ffi::fsync(fd) }; + + if res < 0 { + return Err(Error::Sys(Errno::last())); + } + + Ok(()) +} + +#[inline] +pub fn fdatasync(fd: RawFd) -> Result<()> { + let res = unsafe { ffi::fdatasync(fd) }; + + if res < 0 { + return Err(Error::Sys(Errno::last())); + } + + Ok(()) +} + #[cfg(any(target_os = "linux", target_os = "android"))] mod linux { use sys::syscall::{syscall, SYSPIVOTROOT}; -- cgit v1.2.3