Closed yagehu closed 3 years ago
Absolute paths are not support at the WASI level, but wasi-libc supports them by transforming them into paths that are relative to one of the preopens (mapped directories).
If you want to use --dir
command line you would need to pass --dir /
to open/file
. To open /dir/file
you could alternatively just pass just --dir /tmp
.
If you want more control then you can use the --mapdir
instead. This gives you more control. e.g. --mapdir=/foobar::/
will map /foobar
in the host to the root directory in the application allowing the application to open /foobar/file
as just /file
.
See: https://github.com/bytecodealliance/wasmtime/blob/main/docs/WASI-tutorial.md
(at least I think this is how wasmtime works.. I don't use it myself so I'm just going on what I think the docs say)
Absolute paths are not support at the WASI level, but wasi-libc supports them by transforming them into paths that are relative to one of the preopens (mapped directories).
Answered my question. Thanks! Is there a WASI doc that explicitly says absolute paths are not supported?
I think its covered in https://github.com/WebAssembly/WASI/blob/master/docs/DesignPrinciples.md:
""" For example, a typical POSIX-style API might include a function that accepts a file name to open. That requires the implementation to have a filesystem view, and to have appropriate permissions within that filesystem view. WASI APIs typically prefer to instead have a function which accepts a handle for an already-open file. That way, the implementation doesn't need a filesystem view, or permissions within the filesystem. It doesn't even need to care whether there even is a filesystem. When needed, compatibility with POSIX-style APIs is then provided as a thin layer on top implementing a simple name-to-handle mapping. """
Basically, you can only open a file based on a directory handle that the embedder passes to you. In a way, absolute paths are supported but only if you pass a handle to the filesystem root (e.g. with "--dir /").. but that isn't really in the spirit of WASI's design.
Answered.
Does the WASI spec intend to disallow absolute path in
path_open
calls? If not, what should the path look like?Take wasmtime for example, I've tried to open
/file
and/dir/file
and both returns error code 76. This assumes I've passed indir
as a preopened directory withwasmtime --dir dir path_open.wat
.