From e7992231a34963a57d2297fe1ea7cdaf090efa8b Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Sat, 8 Oct 2022 12:53:37 +0800 Subject: [PATCH] add syncfs on linux --- CHANGELOG.md | 2 ++ src/unistd.rs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 080ea0e7f2..8678e3ed86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ This project adheres to [Semantic Versioning](https://semver.org/). ([#1817](https://github.com/nix-rust/nix/pull/1817)) - Re-export `RLIM_INFINITY` from `libc` ([#1831](https://github.com/nix-rust/nix/pull/1831)) +- Added `syncfs(2)` on Linux + ([#1833](https://github.com/nix-rust/nix/pull/1833)) ### Changed diff --git a/src/unistd.rs b/src/unistd.rs index e7a64dabb4..daa76b74d0 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1354,6 +1354,17 @@ pub fn sync() { unsafe { libc::sync() }; } +/// Commit filesystem caches containing file referred to by the open file +/// descriptor `fd` to disk +/// +/// See also [syncfs(2)](https://man7.org/linux/man-pages/man2/sync.2.html) +#[cfg(target_os = "linux")] +pub fn syncfs(fd: RawFd) -> Result<()> { + let res = unsafe { libc::syncfs(fd) }; + + Errno::result(res).map(drop) +} + /// Synchronize changes to a file /// /// See also [fsync(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html)