summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Fitzhardinge <jeremy@goop.org>2015-10-10 11:53:59 -0700
committerJeremy Fitzhardinge <jeremy@goop.org>2015-10-27 00:05:44 -0700
commitad63c14489372506b67e976ae2cb28164d75a8b0 (patch)
tree257fcf3ad02a3e3443970c0d9c9aa49f447f3a1c /src
parent293b2a0e21032c8d9b997020c326ba2e7422672b (diff)
downloadnix-ad63c14489372506b67e976ae2cb28164d75a8b0.zip
Add support for fsync, fdatasync
Diffstat (limited to 'src')
-rw-r--r--src/unistd.rs27
1 files changed, 27 insertions, 0 deletions
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<P: ?Sized + NixPath>(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};