Skip to content

Commit 0eebf19

Browse files
bors[bot]SteveLauC
andauthored
Merge #1833
1833: add syncfs on linux r=rtzoeller a=SteveLauC Fixes #1818 Change has not been added to `CHANGELOG.md`, will add it when #1831 is merged, or there will be a merge conflict Co-authored-by: Steve Lau <stevelauc@outlook.com>
2 parents 8341e4f + e799223 commit 0eebf19

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
2020
([#1817](https://github.com/nix-rust/nix/pull/1817))
2121
- Re-export `RLIM_INFINITY` from `libc`
2222
([#1831](https://github.com/nix-rust/nix/pull/1831))
23+
- Added `syncfs(2)` on Linux
24+
([#1833](https://github.com/nix-rust/nix/pull/1833))
2325

2426
### Changed
2527

src/unistd.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,17 @@ pub fn sync() {
13541354
unsafe { libc::sync() };
13551355
}
13561356

1357+
/// Commit filesystem caches containing file referred to by the open file
1358+
/// descriptor `fd` to disk
1359+
///
1360+
/// See also [syncfs(2)](https://man7.org/linux/man-pages/man2/sync.2.html)
1361+
#[cfg(target_os = "linux")]
1362+
pub fn syncfs(fd: RawFd) -> Result<()> {
1363+
let res = unsafe { libc::syncfs(fd) };
1364+
1365+
Errno::result(res).map(drop)
1366+
}
1367+
13571368
/// Synchronize changes to a file
13581369
///
13591370
/// See also [fsync(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html)

0 commit comments

Comments
 (0)