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) -> result<input-stream, error-code>;Return a stream for reading from a file, if available.
May fail with an error-code describing why the file cannot be read.
Multiple read, write, and append streams may be active on the same open file and they do not interfere with each other.
Note: This allows using read-stream, which is similar to read in POSIX.
F write-via-stream
write-via-stream: func(offset: filesize) -> result<output-stream, 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.
Note: This allows using write-stream, which is similar to write in
POSIX.
F append-via-stream
append-via-stream: func() -> result<output-stream, 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.
Note: This allows using write-stream, which is similar to write with
O_APPEND in POSIX.
F advise
advise: 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: 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: 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: 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: 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: 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
read: func(length: filesize, offset: filesize) -> result<tuple<list<u8>, bool>, error-code>;Read from a descriptor, without using and updating the descriptor's offset.
This function returns a list of bytes containing the data that was
read, along with a bool which, when true, indicates that the end of the
file was reached. The returned list will contain up to length bytes; it
may return fewer than requested, if the end of the file is reached or
if the I/O operation is interrupted.
In the future, this may change to return a stream<u8, error-code>.
Note: This is similar to pread in POSIX.
F write
write: func(buffer: list<u8>, offset: filesize) -> result<filesize, error-code>;Write to a descriptor, without using and updating the descriptor's offset.
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.
In the future, this may change to take a stream<u8, error-code>.
Note: This is similar to pwrite in POSIX.
F read-directory
read-directory: func() -> result<directory-entry-stream, 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.
F sync
sync: 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: func(path: string) -> result<_, error-code>;Create a directory.
Note: This is similar to mkdirat in POSIX.
F stat
stat: 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: 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: 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: 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: 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: 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: 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: 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: 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: func(path: string) -> result<_, error-code>;Unlink a filesystem object that is not a directory.
Return error-code::is-directory if the path refers to a directory.
Note: This is similar to unlinkat(fd, path, 0) in POSIX.
F is-same-object
is-same-object: 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: 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: 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.