1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use super::*;

impl JournalEffector {
    pub fn save_fd_allocate(
        ctx: &mut FunctionEnvMut<'_, WasiEnv>,
        fd: Fd,
        offset: Filesize,
        len: Filesize,
    ) -> anyhow::Result<()> {
        Self::save_event(
            ctx,
            JournalEntry::FileDescriptorAllocateV1 { fd, offset, len },
        )
    }

    pub fn apply_fd_allocate(
        ctx: &mut FunctionEnvMut<'_, WasiEnv>,
        fd: Fd,
        offset: Filesize,
        len: Filesize,
    ) -> anyhow::Result<()> {
        crate::syscalls::fd_allocate_internal(ctx, fd, offset, len)
            .map_err(|err| {
                anyhow::format_err!(
                    "journal restore error: failed to allocate on file descriptor (fd={}, offset={}, len={}) - {}",
                    fd,
                    offset,
                    len,
                    err
                )
            })?;
        Ok(())
    }
}