Resource

descriptor

A descriptor is a reference to a filesystem object, which may be a file, directory, named pipe, special file, or other object on which filesystem calls may be made.

resource descriptor;

F read-via-stream

read-via-stream: func(offset: filesize) -> tuple​<stream​<u8>, future​<result​<_, error-code>>>;

Return a stream for reading from a file.

Multiple read, write, and append streams may be active on the same open file and they do not interfere with each other.

This function returns a stream which provides the data received from the file, and a future providing additional error information in case an error is encountered.

If no error is encountered, stream.read on the stream will return read-status::closed with no error-context and the future resolves to the value ok. If an error is encountered, stream.read on the stream returns read-status::closed with an error-context and the future resolves to err with an error-code.

Note: This is similar to pread in POSIX.

F write-via-stream

write-via-stream: func(data: stream​<u8>, offset: filesize) -> future​<result​<_, error-code>>;

Return a stream for writing to a file, if available.

May fail with an error-code describing why the file cannot be written.

It is valid to write past the end of a file; the file is extended to the extent of the write, with bytes between the previous end and the start of the write set to zero.

This function returns once either full contents of the stream are written or an error is encountered.

Note: This is similar to pwrite in POSIX.

F append-via-stream

append-via-stream: func(data: stream​<u8>) -> future​<result​<_, error-code>>;

Return a stream for appending to a file, if available.

May fail with an error-code describing why the file cannot be appended.

This function returns once either full contents of the stream are written or an error is encountered.

Note: This is similar to write with O_APPEND in POSIX.

F advise

advise: async func(offset: filesize, length: filesize, advice: advice) -> result​<_, error-code>;

Provide file advisory information on a descriptor.

This is similar to posix_fadvise in POSIX.

F sync-data

sync-data: async func() -> result​<_, error-code>;

Synchronize the data of a file to disk.

This function succeeds with no effect if the file descriptor is not opened for writing.

Note: This is similar to fdatasync in POSIX.

F get-flags

get-flags: async func() -> result​<descriptor-flags, error-code>;

Get flags associated with a descriptor.

Note: This returns similar flags to fcntl(fd, F_GETFL) in POSIX.

Note: This returns the value that was the fs_flags value returned from fdstat_get in earlier versions of WASI.

F get-type

get-type: async func() -> result​<descriptor-type, error-code>;

Get the dynamic type of a descriptor.

Note: This returns the same value as the type field of the fd-stat returned by stat, stat-at and similar.

Note: This returns similar flags to the st_mode & S_IFMT value provided by fstat in POSIX.

Note: This returns the value that was the fs_filetype value returned from fdstat_get in earlier versions of WASI.

F set-size

set-size: async func(size: filesize) -> result​<_, error-code>;

Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.

Note: This was called fd_filestat_set_size in earlier versions of WASI.

F set-times

set-times: async func(data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result​<_, error-code>;

Adjust the timestamps of an open file or directory.

Note: This is similar to futimens in POSIX.

Note: This was called fd_filestat_set_times in earlier versions of WASI.

F read-directory

read-directory: func() -> tuple​<stream​<directory-entry>, future​<result​<_, error-code>>>;

Read directory entries from a directory.

On filesystems where directories contain entries referring to themselves and their parents, often named . and .. respectively, these entries are omitted.

This always returns a new stream which starts at the beginning of the directory. Multiple streams may be active on the same directory, and they do not interfere with each other.

This function returns a future, which will resolve to an error code if reading full contents of the directory fails.

F sync

sync: async func() -> result​<_, error-code>;

Synchronize the data and metadata of a file to disk.

This function succeeds with no effect if the file descriptor is not opened for writing.

Note: This is similar to fsync in POSIX.

F create-directory-at

create-directory-at: async func(path: string) -> result​<_, error-code>;

Create a directory.

Note: This is similar to mkdirat in POSIX.

F stat

stat: async func() -> result​<descriptor-stat, error-code>;

Return the attributes of an open file or directory.

Note: This is similar to fstat in POSIX, except that it does not return device and inode information. For testing whether two descriptors refer to the same underlying filesystem object, use is-same-object. To obtain additional data that can be used do determine whether a file has been modified, use metadata-hash.

Note: This was called fd_filestat_get in earlier versions of WASI.

F stat-at

stat-at: async func(path-flags: path-flags, path: string) -> result​<descriptor-stat, error-code>;

Return the attributes of a file or directory.

Note: This is similar to fstatat in POSIX, except that it does not return device and inode information. See the stat description for a discussion of alternatives.

Note: This was called path_filestat_get in earlier versions of WASI.

F set-times-at

set-times-at: async func(path-flags: path-flags, path: string, data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result​<_, error-code>;

Adjust the timestamps of a file or directory.

Note: This is similar to utimensat in POSIX.

Note: This was called path_filestat_set_times in earlier versions of WASI.

F link-at

link-at: async func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow​<descriptor>, new-path: string) -> result​<_, error-code>;

Create a hard link.

Fails with error-code::no-entry if the old path does not exist, with error-code::exist if the new path already exists, and error-code::not-permitted if the old path is not a file.

Note: This is similar to linkat in POSIX.

F open-at

open-at: async func(path-flags: path-flags, path: string, open-flags: open-flags, flags: descriptor-flags) -> result​<descriptor, error-code>;

Open a file or directory.

If flags contains descriptor-flags::mutate-directory, and the base descriptor doesn't have descriptor-flags::mutate-directory set, open-at fails with error-code::read-only.

If flags contains write or mutate-directory, or open-flags contains truncate or create, and the base descriptor doesn't have descriptor-flags::mutate-directory set, open-at fails with error-code::read-only.

Note: This is similar to openat in POSIX.

F readlink-at

readlink-at: async func(path: string) -> result​<string, error-code>;

Read the contents of a symbolic link.

If the contents contain an absolute or rooted path in the underlying filesystem, this function fails with error-code::not-permitted.

Note: This is similar to readlinkat in POSIX.

F remove-directory-at

remove-directory-at: async func(path: string) -> result​<_, error-code>;

Remove a directory.

Return error-code::not-empty if the directory is not empty.

Note: This is similar to unlinkat(fd, path, AT_REMOVEDIR) in POSIX.

F rename-at

rename-at: async func(old-path: string, new-descriptor: borrow​<descriptor>, new-path: string) -> result​<_, error-code>;

Rename a filesystem object.

Note: This is similar to renameat in POSIX.

F symlink-at

symlink-at: async func(old-path: string, new-path: string) -> result​<_, error-code>;

Create a symbolic link (also known as a "symlink").

If old-path starts with /, the function fails with error-code::not-permitted.

Note: This is similar to symlinkat in POSIX.

F unlink-file-at

unlink-file-at: async func(path: string) -> result​<_, error-code>;

Unlink a filesystem object that is not a directory.

This is similar to unlinkat(fd, path, 0) in POSIX.

Error returns are as specified by POSIX.

If the filesystem object is a directory, error-code::access or error-code::is-directory may be returned instead of the POSIX-specified error-code::not-permitted.

F is-same-object

is-same-object: async func(other: borrow​<descriptor>) -> bool;

Test whether two descriptors refer to the same filesystem object.

In POSIX, this corresponds to testing whether the two descriptors have the same device (st_dev) and inode (st_ino or d_ino) numbers. wasi-filesystem does not expose device and inode numbers, so this function may be used instead.

F metadata-hash

metadata-hash: async func() -> result​<metadata-hash-value, error-code>;

Return a hash of the metadata associated with a filesystem object referred to by a descriptor.

This returns a hash of the last-modification timestamp and file size, and may also include the inode number, device number, birth timestamp, and other metadata fields that may change when the file is modified or replaced. It may also include a secret value chosen by the implementation and not otherwise exposed.

Implementations are encouraged to provide the following properties:

  • If the file is not modified or replaced, the computed hash value should usually not change.
  • If the object is modified or replaced, the computed hash value should usually change.
  • The inputs to the hash should not be easily computable from the computed hash.

However, none of these is required.

F metadata-hash-at

metadata-hash-at: async func(path-flags: path-flags, path: string) -> result​<metadata-hash-value, error-code>;

Return a hash of the metadata associated with a filesystem object referred to by a directory descriptor and a relative path.

This performs the same hash computation as metadata-hash.