wasmtime_wasi/
filesystem.rs

1use crate::p2::filesystem::Dir;
2use wasmtime::component::{HasData, ResourceTable};
3
4pub(crate) struct WasiFilesystem;
5
6impl HasData for WasiFilesystem {
7    type Data<'a> = WasiFilesystemCtxView<'a>;
8}
9
10#[derive(Clone, Default)]
11pub struct WasiFilesystemCtx {
12    pub allow_blocking_current_thread: bool,
13    pub preopens: Vec<(Dir, String)>,
14}
15
16pub struct WasiFilesystemCtxView<'a> {
17    pub ctx: &'a mut WasiFilesystemCtx,
18    pub table: &'a mut ResourceTable,
19}
20
21pub trait WasiFilesystemView: Send {
22    fn filesystem(&mut self) -> WasiFilesystemCtxView<'_>;
23}
24
25bitflags::bitflags! {
26    #[derive(Copy, Clone, Debug, PartialEq, Eq)]
27    pub struct FilePerms: usize {
28        const READ = 0b1;
29        const WRITE = 0b10;
30    }
31}
32
33bitflags::bitflags! {
34    #[derive(Copy, Clone, Debug, PartialEq, Eq)]
35    pub struct OpenMode: usize {
36        const READ = 0b1;
37        const WRITE = 0b10;
38    }
39}
40
41bitflags::bitflags! {
42    /// Permission bits for operating on a directory.
43    ///
44    /// Directories can be limited to being readonly. This will restrict what
45    /// can be done with them, for example preventing creation of new files.
46    #[derive(Copy, Clone, Debug, PartialEq, Eq)]
47    pub struct DirPerms: usize {
48        /// This directory can be read, for example its entries can be iterated
49        /// over and files can be opened.
50        const READ = 0b1;
51
52        /// This directory can be mutated, for example by creating new files
53        /// within it.
54        const MUTATE = 0b10;
55    }
56}