Skip to content

Commit

Permalink
add syncfs on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC committed Oct 8, 2022
1 parent e5913c6 commit e799223
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions src/unistd.rs
Expand Up @@ -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)
Expand Down

0 comments on commit e799223

Please sign in to comment.