wasmer_wasix/syscalls/wasi/
fd_datasync.rs

1use super::*;
2use crate::syscalls::*;
3
4/// ### `fd_datasync()`
5/// Synchronize the file data to disk
6/// Inputs:
7/// - `Fd fd`
8///     The file descriptor to sync
9#[instrument(level = "trace", skip_all, fields(%fd), ret)]
10pub fn fd_datasync(mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Result<Errno, WasiError> {
11    WasiEnv::do_pending_operations(&mut ctx)?;
12
13    let env = ctx.data();
14    let state = env.state.clone();
15    let fd_entry = wasi_try_ok!(state.fs.get_fd(fd));
16    if !fd_entry.inner.rights.contains(Rights::FD_DATASYNC) {
17        return Ok(Errno::Access);
18    }
19
20    #[allow(clippy::await_holding_lock)]
21    Ok(wasi_try_ok!(__asyncify(&mut ctx, None, async move {
22        state.fs.flush(fd).await.map(|_| Errno::Success)
23    })?))
24}