Types
use resource descriptorsince 0.2.0
from wasi:filesystem/types@0.2.3
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.
read-via-stream: func( offset: filesize, ) -> result<input-stream, error-code>since 0.2.0Return 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 toreadin POSIX.write-via-stream: func( offset: filesize, ) -> result<output-stream, error-code>since 0.2.0Return 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 towritein POSIX.append-via-stream: func() -> result<output-stream, error-code>since 0.2.0Return 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 towritewithO_APPENDin POSIX.advise: func( offset: filesize, length: filesize, advice: advice, ) -> result<_, error-code>since 0.2.0Provide file advisory information on a descriptor.
This is similar to
posix_fadvisein POSIX.sync-data: func() -> result<_, error-code>since 0.2.0Synchronize 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
fdatasyncin POSIX.get-flags: func() -> result<descriptor-flags, error-code>since 0.2.0Get 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_flagsvalue returned fromfdstat_getin earlier versions of WASI.get-type: func() -> result<descriptor-type, error-code>since 0.2.0Get the dynamic type of a descriptor.
Note: This returns the same value as the
typefield of thefd-statreturned bystat,stat-atand similar.Note: This returns similar flags to the
st_mode & S_IFMTvalue provided byfstatin POSIX.Note: This returns the value that was the
fs_filetypevalue returned fromfdstat_getin earlier versions of WASI.set-size: func(size: filesize) -> result<_, error-code>since 0.2.0Adjust 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_sizein earlier versions of WASI.set-times: func( data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp, ) -> result<_, error-code>since 0.2.0Adjust the timestamps of an open file or directory.
Note: This is similar to
futimensin POSIX.Note: This was called
fd_filestat_set_timesin earlier versions of WASI.read: func( length: filesize, offset: filesize, ) -> result<tuple<list<u8>, bool>, error-code>since 0.2.0Read 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
lengthbytes; 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
preadin POSIX.write: func( buffer: list<u8>, offset: filesize, ) -> result<filesize, error-code>since 0.2.0Write 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
pwritein POSIX.read-directory: func() -> result<directory-entry-stream, error-code>since 0.2.0Read 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.
sync: func() -> result<_, error-code>since 0.2.0Synchronize 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
fsyncin POSIX.create-directory-at: func(path: string) -> result<_, error-code>since 0.2.0Create a directory.
Note: This is similar to
mkdiratin POSIX.stat: func() -> result<descriptor-stat, error-code>since 0.2.0Return the attributes of an open file or directory.
Note: This is similar to
fstatin POSIX, except that it does not return device and inode information. For testing whether two descriptors refer to the same underlying filesystem object, useis-same-object. To obtain additional data that can be used do determine whether a file has been modified, usemetadata-hash.Note: This was called
fd_filestat_getin earlier versions of WASI.stat-at: func( path-flags: path-flags, path: string, ) -> result<descriptor-stat, error-code>since 0.2.0Return the attributes of a file or directory.
Note: This is similar to
fstatatin POSIX, except that it does not return device and inode information. See thestatdescription for a discussion of alternatives.Note: This was called
path_filestat_getin earlier versions of WASI.set-times-at: func( path-flags: path-flags, path: string, data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp, ) -> result<_, error-code>since 0.2.0Adjust the timestamps of a file or directory.
Note: This is similar to
utimensatin POSIX.Note: This was called
path_filestat_set_timesin earlier versions of WASI.link-at: func( old-path-flags: path-flags, old-path: string, new-descriptor: borrow<descriptor>, new-path: string, ) -> result<_, error-code>since 0.2.0Create a hard link.
Note: This is similar to
linkatin POSIX.open-at: func( path-flags: path-flags, path: string, open-flags: open-flags, flags: descriptor-flags, ) -> result<descriptor, error-code>since 0.2.0Open a file or directory.
If
flagscontainsdescriptor-flags::mutate-directory, and the base descriptor doesn't havedescriptor-flags::mutate-directoryset,open-atfails witherror-code::read-only.If
flagscontainswriteormutate-directory, oropen-flagscontainstruncateorcreate, and the base descriptor doesn't havedescriptor-flags::mutate-directoryset,open-atfails witherror-code::read-only.Note: This is similar to
openatin POSIX.readlink-at: func(path: string) -> result<string, error-code>since 0.2.0Read 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
readlinkatin POSIX.remove-directory-at: func(path: string) -> result<_, error-code>since 0.2.0Remove a directory.
Return
error-code::not-emptyif the directory is not empty.Note: This is similar to
unlinkat(fd, path, AT_REMOVEDIR)in POSIX.rename-at: func( old-path: string, new-descriptor: borrow<descriptor>, new-path: string, ) -> result<_, error-code>since 0.2.0Rename a filesystem object.
Note: This is similar to
renameatin POSIX.symlink-at: func( old-path: string, new-path: string, ) -> result<_, error-code>since 0.2.0Create a symbolic link (also known as a "symlink").
If
old-pathstarts with/, the function fails witherror-code::not-permitted.Note: This is similar to
symlinkatin POSIX.unlink-file-at: func(path: string) -> result<_, error-code>since 0.2.0Unlink a filesystem object that is not a directory.
Return
error-code::is-directoryif the path refers to a directory. Note: This is similar tounlinkat(fd, path, 0)in POSIX.is-same-object: func(other: borrow<descriptor>) -> boolsince 0.2.0Test 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_inoord_ino) numbers. wasi-filesystem does not expose device and inode numbers, so this function may be used instead.metadata-hash: func() -> result<metadata-hash-value, error-code>since 0.2.0Return 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.
metadata-hash-at: func( path-flags: path-flags, path: string, ) -> result<metadata-hash-value, error-code>since 0.2.0Return 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.
Functions
get-directories: func() -> list<tuple<descriptor, string>>since 0.2.0
Return the set of preopened directories, and their paths.
WIT
@since(version = 0.2.0)
interface preopens {
@since(version = 0.2.0)
use types.{descriptor};
/// Return the set of preopened directories, and their paths.
@since(version = 0.2.0)
get-directories: func() -> list<tuple<descriptor, string>>;
}