wasi_p2_filesystem (wasm v0.16.0)

View Source

The wasi:filesystem slice of the WASI 0.2 host: filesystem/1 builds the wasi:filesystem/types and wasi:filesystem/preopens imports over preopened directories, read-only or writable per mount.

Read it when you change what a descriptor can do. Paths go through wasi_fs, the same calls Preview 1 makes, so the sandbox is not reimplemented here. The streams a descriptor opens are the output-stream and input-stream resources wasi_preview2 serves; this module only mints them, and never calls back into wasi_preview2.

Summary

Functions

The entries of directory descriptor Dir, each #{type, name}.

wasi:filesystem over preopened directories. get-directories hands the guest a descriptor for preopen (named name, default /), or one per entry of mounts as {Name, Dir, Writable}. A mount is read-only unless its flag (or writable, for the single preopen) says otherwise, and write intent on a read-only one is refused with read-only. Path resolution and the sandbox are not reimplemented here: open-at passes the guest path straight to wasi_fs:open/3, the same call Preview 1 makes, so the same escapes are refused.

Functions

create_directory_at(Dir, Path)

dir_entries(Dir)

-spec dir_entries(non_neg_integer()) -> {ok, [map()]} | {error, binary()}.

The entries of directory descriptor Dir, each #{type, name}.

errno_name/1

filesystem(Opts)

-spec filesystem(#{preopen => file:filename_all(),
                   name => binary(),
                   writable => boolean(),
                   mounts => [{binary(), file:filename_all(), boolean()}]}) ->
                    #{{binary(), binary()} => fun()}.

wasi:filesystem over preopened directories. get-directories hands the guest a descriptor for preopen (named name, default /), or one per entry of mounts as {Name, Dir, Writable}. A mount is read-only unless its flag (or writable, for the single preopen) says otherwise, and write intent on a read-only one is refused with read-only. Path resolution and the sandbox are not reimplemented here: open-at passes the guest path straight to wasi_fs:open/3, the same call Preview 1 makes, so the same escapes are refused.

fs_drop(H)

get_directories(Mounts)

get_flags(H)

is_same_object(A, B)

metadata_hash(H)

metadata_hash_at(Dir, PathFlags, Path)

mounts_of(Opts)

open_at(Dir, PathFlags, Path, OpenFlags, DescFlags)

read_all(Handle, Off, Acc)

readable_file(File)

remove_directory_at(Dir, Path)

rename_at(Dir, Path, NewDir, NewPath)

set_size(File, Size)

set_times(H, Atime, Mtime)

set_times_at(Dir, PathFlags, Path, Atime, Mtime)

stat(H)

stat_at(Dir, PathFlags, Path)

sync_fd(H, Kind)

type_of(H)

write_all_at(File, Data, Off)

write_at(File, Data, Off)