btrfs_uapi/sync.rs
1//! # Filesystem sync: flushing all pending writes to disk
2//!
3//! Forces the kernel to commit all dirty btrfs metadata and data to stable
4//! storage. Equivalent to calling `sync(2)` scoped to a single btrfs
5//! filesystem rather than all mounted filesystems.
6
7use crate::raw::btrfs_ioc_sync;
8use std::os::{fd::AsRawFd, unix::io::BorrowedFd};
9
10/// Force a sync on the btrfs filesystem referred to by `fd`.
11///
12/// Equivalent to `ioctl(fd, BTRFS_IOC_SYNC)`.
13pub fn sync(fd: BorrowedFd) -> nix::Result<()> {
14 unsafe { btrfs_ioc_sync(fd.as_raw_fd()) }?;
15 Ok(())
16}