Stream: wasmtime

Topic: Virtual filesystem in WASI Preview 2


view this post on Zulip CryZe (Feb 29 2024 at 09:49):

I've been looking into WASI Preview 2 and it seems like some important functionality has been lost: The ability to define my own virtual file system by implementing the Dir and File traits. The types are now fully concrete: https://docs.rs/wasmtime-wasi/18.0.2/wasmtime_wasi/preview2/struct.WasiCtxBuilder.html#method.preopened_dir

Is there a plan to fix this or is there maybe some other way that I haven't discovered yet?

view this post on Zulip CryZe (Feb 29 2024 at 09:52):

In particular I'm mostly interested in implementing the Dir trait to prevent write access to the files. This was my workaround until now to the permissions systrem also having disappeared in recent wasmtime versions.

view this post on Zulip Lann Martin (Feb 29 2024 at 13:58):

prevent write access to the files

This particular feature is still available via the file_perms argument of preopened_dir (see also perms if you need the directory to be read-only as well)

view this post on Zulip CryZe (Feb 29 2024 at 15:16):

Oh wow, I must be blind. I didn't even look at the parameters properly, assuming the permissions would be gone there as well like in preview 1.

view this post on Zulip CryZe (Feb 29 2024 at 15:25):

mmh, I do however indeed have one folder that's entirely implemented via a trait. Is there no way to do this now?

view this post on Zulip Lann Martin (Feb 29 2024 at 15:38):

I believe there is no direct equivalent to the old WasiFile/WasiDir traits for WASI 0.2. It should still be possible to implement a virtual filesystem but I don't know of any friendly wrappers so it would require digging pretty deeply into the wasi filesystem details.

view this post on Zulip Lann Martin (Feb 29 2024 at 15:47):

Depending on your exact requirements wasi-virt might be of interest too: https://github.com/bytecodealliance/WASI-Virt/?tab=readme-ov-file#filesystem

Virtual implementations of WASI APIs. Contribute to bytecodealliance/WASI-Virt development by creating an account on GitHub.

view this post on Zulip Ralph (Feb 29 2024 at 15:48):

that's what I was thinking....

view this post on Zulip Alex Crichton (Feb 29 2024 at 16:15):

Yes it's intentional that the Wasi{File,Dir} traits did not survive the transition to preview2. No fundamental issues with p2 vs p1, just a decision we made when writing the wasmtime-wasi crate's support. It was concluded that supporting the traits-of-old was too much of a maintenance burden on us for not enough benefit.

It's always possible to implement the bindgen-generated traits in a custom fashion and add those to a linker instead of adding the wasmtime-wasi implementations to the linker. That's of course much of a larger lift than just implementing the file/dir traits, however. Some of the tricky parts around polling and streams, however, are still taken care of automatically with the I/O interface.


Last updated: Dec 23 2024 at 13:07 UTC