This is conceptually represents a stream<_, _>, or in other words,
-a stream that one can wait on, repeatedly, but which does not itself
-produce any data. It's temporary scaffolding until component-model's
-async features are ready.
-
And at present, it is a u32 instead of being an actual handle, until
-the wit-bindgen implementation of handles and resources is ready.
-
pollable lifetimes are not automatically managed. Users must ensure
-that they do not outlive the resource they reference.
The "oneoff" in the name refers to the fact that this function must do a
@@ -107,18 +91,16 @@ inefficient if the number is large and the same subscriptions are used
many times. In the future, this is expected to be obsoleted by the
component model async proposal, which will include a scalable waiting
facility.
The result list is the same length as the argument
+list, and indicates the readiness of each corresponding
+element in that / list, with true indicating ready.
The number of seconds difference between UTC time and the local
time of the timezone.
The returned value will always be less than 86400 which is the
@@ -202,48 +187,34 @@ representation of the UTC offset may be returned, such as -04:00.
should return false.
In timezones that recognize daylight saving time, also known as daylight
-time and summer time, the information returned from the functions varies
-over time to reflect these adjustments.
Return information needed to display the given datetime. This includes
the UTC offset, the time zone name, and a flag indicating whether
daylight saving time is active.
If the timezone cannot be determined for the given datetime, return a
-timezone-display for UTC with a utc-offset of 0 and no daylight
+timezone-display for UTC with a utc-offset of 0 and no daylight
saving time.
An output bytestream. In the future, this will be replaced by handle
-types.
-
This conceptually represents a stream<u8, _>. It's temporary
-scaffolding until component-model's async features are ready.
-
output-streams are non-blocking to the extent practical on
-underlying platforms. Except where specified otherwise, I/O operations also
-always return promptly, after the number of bytes that can be written
-promptly, which could even be zero. To wait for the stream to be ready to
-accept data, the subscribe-to-output-stream function to obtain a
-pollable which can be polled for using wasi_poll.
-
And at present, it is a u32 instead of being an actual handle, until
-the wit-bindgen implementation of handles and resources is ready.
An input bytestream. In the future, this will be replaced by handle
-types.
-
This conceptually represents a stream<u8, _>. It's temporary
-scaffolding until component-model's async features are ready.
-
input-streams are non-blocking to the extent practical on underlying
-platforms. I/O operations always return promptly; if fewer bytes are
-promptly available than requested, they return the number of bytes promptly
-available, which could even be zero. To wait for data to be available,
-use the subscribe-to-input-stream function to obtain a pollable which
-can be polled for using wasi_poll.
-
And at present, it is a u32 instead of being an actual handle, until
-the wit-bindgen implementation of handles and resources is ready.
Streams provide a sequence of data and then end; once they end, they
+no longer provide any further data.
+
For example, a stream reading from a file ends when the stream reaches
+the end of the file. For another example, a stream reading from a
+socket ends when the socket is closed.
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
-stream was reached. The returned list will contain up to len bytes; it
-may return fewer than requested, but not more.
+read, along with a stream-status which indicates whether the end of
+the stream was reached. The returned list will contain up to len
+bytes; it may return fewer than requested, but not more.
Once a stream has reached the end, subsequent calls to read or
-skip will always report end-of-stream rather than producing more
+skip will always report end-of-stream rather than producing more
data.
If len is 0, it represents a request to read 0 bytes, which should
always succeed, assuming the stream hasn't reached its end yet, and
@@ -308,130 +272,123 @@ a buffer as large as that would imply.
FIXME: describe what happens if allocation fails.
This is similar to the read function, but avoids copying the
+
This is similar to the read function, but avoids copying the
bytes into the instance.
Once a stream has reached the end, subsequent calls to read or
-skip will always report end-of-stream rather than producing more
+skip will always report end-of-stream rather than producing more
data.
-
This function returns the number of bytes skipped, along with a bool
-indicating whether the end of the stream was reached. The returned
-value will be at most len; it may be less.
+
This function returns the number of bytes skipped, along with a
+stream-status indicating whether the end of the stream was
+reached. The returned value will be at most len; it may be less.
Forward the entire contents of an input stream to an output stream.
This function repeatedly reads from the input stream and writes
the data to the output stream, until the end of the input stream
@@ -472,30 +429,23 @@ the output stream.
This function returns the number of bytes transferred.
WASI filesystem is a filesystem API primarily intended to let users run WASI
@@ -524,7 +474,108 @@ underlying filesystem, the function fails with `type datetime`
[`datetime`](#datetime)
When this flag is enabled, functions may return immediately with an
+error-code::would-block error code in situations where they would
+otherwise block. However, this non-blocking behavior is not
+required. Implementations are permitted to ignore this flag and
+block. This is similar to O_NONBLOCK in POSIX.
Request that writes be performed according to synchronized I/O file
+integrity completion. The data stored in the file and the file's
+metadata are synchronized. This is similar to `O_SYNC` in POSIX.
+
The precise semantics of this operation have not yet been defined for
+WASI. At this time, it should be interpreted as a request, and not a
+requirement.
Request that writes be performed according to synchronized I/O data
+integrity completion. Only the data stored in the file is
+synchronized. This is similar to `O_DSYNC` in POSIX.
+
The precise semantics of this operation have not yet been defined for
+WASI. At this time, it should be interpreted as a request, and not a
+requirement.
Requests that reads be performed at the same level of integrety
+requested for writes. This is similar to `O_RSYNC` in POSIX.
+
The precise semantics of this operation have not yet been defined for
+WASI. At this time, it should be interpreted as a request, and not a
+requirement.
Mutating directories mode: Directory contents may be mutated.
+
When this flag is unset on a descriptor, operations using the
+descriptor which would create, rename, delete, modify the data or
+metadata of filesystem objects, or obtain another handle which
+would permit any of those, shall fail with error-code::read-only if
+they would otherwise succeed.
Identifier for a device containing a file system. Can be used in
+combination with `inode` to uniquely identify a file or directory in
+the filesystem.
The serial number of the object referred to by this directory entry.
+May be none if the inode value is not known.
+
When this is none, libc implementations might do an extra stat-at
+call to retrieve the inode number to fill their d_ino fields, so
+implementations which can set this to a non-none value should do so.
Error codes returned by functions, similar to errno in POSIX.
Not all of these error codes are returned by the functions provided by this
@@ -675,259 +819,68 @@ merely for alignment with POSIX.
No such file or directory, similar to `ENOENT` in POSIX.
Identifier for a device containing a file system. Can be used in
-combination with `inode` to uniquely identify a file or directory in
-the filesystem.
-
The serial number of the object referred to by this directory entry.
-May be none if the inode value is not known.
-
When this is none, libc implementations might do an extra stat-at
-call to retrieve the inode number to fill their d_ino fields, so
-implementations which can set this to a non-none value should do so.
When this flag is enabled, functions may return immediately with an
-error-code::would-block error code in situations where they would
-otherwise block. However, this non-blocking behavior is not
-required. Implementations are permitted to ignore this flag and
-block. This is similar to O_NONBLOCK in POSIX.
Request that writes be performed according to synchronized I/O file
-integrity completion. The data stored in the file and the file's
-metadata are synchronized. This is similar to `O_SYNC` in POSIX.
-
The precise semantics of this operation have not yet been defined for
-WASI. At this time, it should be interpreted as a request, and not a
-requirement.
Request that writes be performed according to synchronized I/O data
-integrity completion. Only the data stored in the file is
-synchronized. This is similar to `O_DSYNC` in POSIX.
-
The precise semantics of this operation have not yet been defined for
-WASI. At this time, it should be interpreted as a request, and not a
-requirement.
Requests that reads be performed at the same level of integrety
-requested for writes. This is similar to `O_RSYNC` in POSIX.
-
The precise semantics of this operation have not yet been defined for
-WASI. At this time, it should be interpreted as a request, and not a
-requirement.
Mutating directories mode: Directory contents may be mutated.
-
When this flag is unset on a descriptor, operations using the
-descriptor which would create, rename, delete, modify the data or
-metadata of filesystem objects, or obtain another handle which
-would permit any of those, shall fail with error-code::read-only if
-they would otherwise succeed.
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 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
@@ -1127,15 +1076,15 @@ if the I/O operation is interrupted.
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
@@ -1144,15 +1093,15 @@ the write set to zero.
On filesystems where directories contain entries referring to themselves
and their parents, often named . and .. respectively, these entries
@@ -1162,96 +1111,96 @@ directory. Multiple streams may be active on the same directory, and they
do not interfere with each other.
The returned descriptor is not guaranteed to be the lowest-numbered
descriptor not currently open/ it is randomized to prevent applications
@@ -1260,82 +1209,82 @@ error-prone in multi-threaded contexts. The returned descriptor is
guaranteed to be less than 2**31.
Note that the ultimate meanings of these permissions is
filesystem-specific.
Unlike in POSIX, the executable flag is not reinterpreted as a "search"
-flag. read on a directory implies readability and searchability, and
+flag. read on a directory implies readability and searchability, and
execute is not valid for directories.
An opaque resource that represents access to (a subset of) the network.
-This enables context-based security for networking.
-There is no need for this to map 1:1 to a physical network interface.
-
FYI, In the future this will be replaced by handle types.
@@ -1789,10 +1712,10 @@ combined with a couple of errors that are always possible:
#### `type ip-address-family`
[`ip-address-family`](#ip_address_family)
Resolve an internet host name to a list of IP addresses.
@@ -1801,7 +1724,7 @@ combined with a couple of errors that are always possible:
name: The name to look up. IP addresses are not allowed. Unicode domain names are automatically converted
to ASCII using IDNA encoding.
-
address-family: If provided, limit the results to addresses of this specific address family.
+
address-family: If provided, limit the results to addresses of this specific address family.
include-unavailable: When set to true, this function will also return addresses of which the runtime
thinks (or knows) can't be connected to at the moment. For example, this will return IPv6 addresses on
systems without an active IPv6 interface. Notes:
@@ -1811,12 +1734,12 @@ systems without an active IPv6 interface. Notes:
This function never blocks. It either immediately fails or immediately returns successfully with a resolve-address-stream
that can be used to (asynchronously) fetch the results.
At the moment, the stream never completes successfully with 0 items. Ie. the first call
-to resolve-next-address never returns ok(none). This may change in the future.
+to resolve-next-address never returns ok(none). This may change in the future.
Typical errors
invalid-name: name is a syntactically invalid domain name.
invalid-name: name is an IP address.
-
address-family-not-supported: The specified address-family is not supported. (EAI_FAMILY)
+
address-family-not-supported: The specified address-family is not supported. (EAI_FAMILY)
This function should be called multiple times. On each call, it will
return the next address in connection order preference. If all
addresses have been exhausted, this function returns none.
-After which, you should release the stream with drop-resolve-address-stream.
+After which, you should release the stream with drop-resolve-address-stream.
This function never returns IPv4-mapped IPv6 addresses.
@@ -1901,18 +1817,15 @@ It's planned to be removed when future is natively supported in Pre
#### `type ip-address-family`
[`ip-address-family`](#ip_address_family)
Bind the socket to a specific network on the provided IP address and port.
If the IP address is zero (0.0.0.0 in IPv4, :: in IPv6), it is left to the implementation to decide which
network interface(s) to bind to.
@@ -1932,7 +1848,7 @@ implicitly bind the socket.
Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
Typical start errors
-
address-family-mismatch: The local-address has the wrong address family. (EINVAL)
+
address-family-mismatch: The local-address has the wrong address family. (EINVAL)
already-bound: The socket is already bound. (EINVAL)
concurrency-conflict: Another bind, connect or listen operation is already in progress. (EALREADY)
@@ -1940,7 +1856,7 @@ implicitly bind the socket.
ephemeral-ports-exhausted: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)
address-in-use: Address is already in use. (EADDRINUSE)
-
address-not-bindable: local-address is not an address that the network can bind to. (EADDRNOTAVAIL)
+
address-not-bindable: local-address is not an address that the network can bind to. (EADDRNOTAVAIL)
not-in-progress: A bind operation is not in progress.
would-block: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
@@ -1953,24 +1869,24 @@ implicitly bind the socket.
The returned socket is bound and in the Connection state.
On success, this function returns the newly accepted client socket along with
@@ -2088,13 +2004,13 @@ a pair of streams that can be used to read & write to the connection.
The kernel buffer space reserved for sends/receives on this socket.
Note #1: an implementation may choose to cap or round the buffer size when setting the value.
In other words, after setting a value, reading the same setting back may return a different value.
@@ -2281,59 +2197,59 @@ for internal metadata structures.
receive: the socket is not expecting to receive any more data from the peer. All subsequent read
operations on the input-stream associated with this socket will return an End Of Stream indication.
-Any data still in the receive queue at time of calling shutdown will be discarded.
+Any data still in the receive queue at time of calling shutdown will be discarded.
send: the socket is not expecting to send any more data to the peer. All subsequent write
operations on the output-stream associated with this socket will return an error.
both: same effect as receive & send combined.
@@ -2352,20 +2268,12 @@ operations on the output-stream associ
@@ -2430,18 +2338,18 @@ is called, the socket is effectively an in-memory configuration object, unable t
#### `type ip-address-family`
[`ip-address-family`](#ip_address_family)
Bind the socket to a specific network on the provided IP address and port.
If the IP address is zero (0.0.0.0 in IPv4, :: in IPv6), it is left to the implementation to decide which
network interface(s) to bind to.
@@ -2450,7 +2358,7 @@ If the TCP/UDP port is zero, the socket will be bound to a random free port.
Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
Typical start errors
-
address-family-mismatch: The local-address has the wrong address family. (EINVAL)
+
address-family-mismatch: The local-address has the wrong address family. (EINVAL)
already-bound: The socket is already bound. (EINVAL)
concurrency-conflict: Another bind or connect operation is already in progress. (EALREADY)
@@ -2458,7 +2366,7 @@ If the TCP/UDP port is zero, the socket will be bound to a random free port.
ephemeral-ports-exhausted: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)
address-in-use: Address is already in use. (EADDRINUSE)
-
address-not-bindable: local-address is not an address that the network can bind to. (EADDRNOTAVAIL)
+
address-not-bindable: local-address is not an address that the network can bind to. (EADDRNOTAVAIL)
not-in-progress: A bind operation is not in progress.
would-block: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
@@ -2471,38 +2379,38 @@ If the TCP/UDP port is zero, the socket will be bound to a random free port.
The remote address option is required. To send a message to the "connected" peer,
-call remote-address to get their address.
+call remote-address to get their address.
Typical errors
-
address-family-mismatch: The remote-address has the wrong address family. (EAFNOSUPPORT)
-
invalid-remote-address: The IP address in remote-address is set to INADDR_ANY (0.0.0.0 / ::). (EDESTADDRREQ, EADDRNOTAVAIL)
-
invalid-remote-address: The port in remote-address is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
+
address-family-mismatch: The remote-address has the wrong address family. (EAFNOSUPPORT)
+
invalid-remote-address: The IP address in remote-address is set to INADDR_ANY (0.0.0.0 / ::). (EDESTADDRREQ, EADDRNOTAVAIL)
+
invalid-remote-address: The port in remote-address is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
already-connected: The socket is in "connected" mode and the datagram.remote-address does not match the address passed to connect. (EISCONN)
not-bound: The socket is not bound to any local address. Unlike POSIX, this function does not perform an implicit bind.
remote-unreachable: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN)
@@ -2596,14 +2504,14 @@ call remote-address to get their addr
The kernel buffer space reserved for sends/receives on this socket.
Note #1: an implementation may choose to cap or round the buffer size when setting the value.
In other words, after setting a value, reading the same setting back may return a different value.
@@ -2723,59 +2631,52 @@ for internal metadata structures.
diff --git a/wit/deps/clocks/timezone.wit b/wit/deps/clocks/timezone.wit
index 6628308..adb4037 100644
--- a/wit/deps/clocks/timezone.wit
+++ b/wit/deps/clocks/timezone.wit
@@ -6,25 +6,19 @@ interface timezone {
/// In timezones that recognize daylight saving time, also known as daylight
/// time and summer time, the information returned from the functions varies
/// over time to reflect these adjustments.
- ///
- /// This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
- type timezone = u32
-
- /// Return information needed to display the given `datetime`. This includes
- /// the UTC offset, the time zone name, and a flag indicating whether
- /// daylight saving time is active.
- ///
- /// If the timezone cannot be determined for the given `datetime`, return a
- /// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
- /// saving time.
- display: func(this: timezone, when: datetime) -> timezone-display
-
- /// The same as `display`, but only return the UTC offset.
- utc-offset: func(this: timezone, when: datetime) -> s32
+ resource timezone {
+ /// Return information needed to display the given `datetime`. This includes
+ /// the UTC offset, the time zone name, and a flag indicating whether
+ /// daylight saving time is active.
+ ///
+ /// If the timezone cannot be determined for the given `datetime`, return a
+ /// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
+ /// saving time.
+ display: func(when: datetime) -> timezone-display
- /// Dispose of the specified input-stream, after which it may no longer
- /// be used.
- drop-timezone: func(this: timezone)
+ /// The same as `display`, but only return the UTC offset.
+ utc-offset: func(when: datetime) -> s32
+ }
/// Information useful for displaying the timezone of a specific `datetime`.
///
diff --git a/wit/deps/filesystem/preopens.wit b/wit/deps/filesystem/preopens.wit
new file mode 100644
index 0000000..f45661b
--- /dev/null
+++ b/wit/deps/filesystem/preopens.wit
@@ -0,0 +1,6 @@
+interface preopens {
+ use types.{descriptor}
+
+ /// Return the set of preopened directories, and their path.
+ get-directories: func() -> list>
+}
diff --git a/wit/deps/filesystem/types.wit b/wit/deps/filesystem/types.wit
index 627b638..a582dfa 100644
--- a/wit/deps/filesystem/types.wit
+++ b/wit/deps/filesystem/types.wit
@@ -102,10 +102,6 @@ interface types {
///
/// Note: This was called `filestat` in earlier versions of WASI.
record descriptor-stat {
- /// Device ID of device containing the file.
- device: device,
- /// File serial number.
- inode: inode,
/// File type.
%type: descriptor-type,
/// Number of hard links to the file.
@@ -166,14 +162,6 @@ interface types {
/// Number of hard links to an inode.
type link-count = u64
- /// Identifier for a device containing a file system. Can be used in
- /// combination with `inode` to uniquely identify a file or directory in
- /// the filesystem.
- type device = u64
-
- /// Filesystem object serial number that is unique within its file system.
- type inode = u64
-
/// When setting a timestamp, this gives the value to set it to.
variant new-timestamp {
/// Leave the timestamp set to its previous value.
@@ -187,14 +175,6 @@ interface types {
/// A directory entry.
record directory-entry {
- /// The serial number of the object referred to by this directory entry.
- /// May be none if the inode value is not known.
- ///
- /// When this is none, libc implementations might do an extra `stat-at`
- /// call to retrieve the inode number to fill their `d_ino` fields, so
- /// implementations which can set this to a non-none value should do so.
- inode: option,
-
/// The type of the file referred to by this directory entry.
%type: descriptor-type,
@@ -305,493 +285,519 @@ interface types {
no-reuse,
}
+ /// A 128-bit hash value, split into parts because wasm doesn't have a
+ /// 128-bit integer type.
+ record metadata-hash-value {
+ /// 64 bits of a 128-bit hash value.
+ lower: u64,
+ /// Another 64 bits of a 128-bit hash value.
+ upper: u64,
+ }
+
/// 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.
- ///
- /// This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
- type descriptor = u32
-
- /// 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.
- ///
- /// Note: This allows using `read-stream`, which is similar to `read` in POSIX.
- read-via-stream: func(
- this: descriptor,
- /// The offset within the file at which to start reading.
- offset: filesize,
- ) -> input-stream
-
- /// Return a stream for writing to a file.
- ///
- /// Note: This allows using `write-stream`, which is similar to `write` in
- /// POSIX.
- write-via-stream: func(
- this: descriptor,
- /// The offset within the file at which to start writing.
- offset: filesize,
- ) -> output-stream
-
- /// Return a stream for appending to a file.
- ///
- /// Note: This allows using `write-stream`, which is similar to `write` with
- /// `O_APPEND` in in POSIX.
- append-via-stream: func(
- this: descriptor,
- ) -> output-stream
-
- /// Provide file advisory information on a descriptor.
- ///
- /// This is similar to `posix_fadvise` in POSIX.
- advise: func(
- this: descriptor,
- /// The offset within the file to which the advisory applies.
- offset: filesize,
- /// The length of the region to which the advisory applies.
- length: filesize,
- /// The advice.
- advice: advice
- ) -> 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.
- sync-data: func(this: descriptor) -> result<_, 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.
- get-flags: func(this: descriptor) -> result
+ resource descriptor {
+ /// 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.
+ read-via-stream: func(
+ /// The offset within the file at which to start reading.
+ offset: filesize,
+ ) -> result
- /// 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.
- get-type: func(this: descriptor) -> result
+ /// 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.
+ write-via-stream: func(
+ /// The offset within the file at which to start writing.
+ offset: filesize,
+ ) -> result
+
+ /// 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 in POSIX.
+ append-via-stream: func() -> result
- /// Set status flags associated with a descriptor.
- ///
- /// This function may only change the `non-blocking` flag.
- ///
- /// Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
- ///
- /// Note: This was called `fd_fdstat_set_flags` in earlier versions of WASI.
- set-flags: func(this: descriptor, %flags: descriptor-flags) -> result<_, error-code>
+ /// Provide file advisory information on a descriptor.
+ ///
+ /// This is similar to `posix_fadvise` in POSIX.
+ advise: func(
+ /// The offset within the file to which the advisory applies.
+ offset: filesize,
+ /// The length of the region to which the advisory applies.
+ length: filesize,
+ /// The advice.
+ advice: advice
+ ) -> 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.
+ sync-data: func() -> 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.
- set-size: func(this: descriptor, size: filesize) -> result<_, 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.
+ get-flags: func() -> result
- /// 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.
- set-times: func(
- this: descriptor,
- /// The desired values of the data access timestamp.
- data-access-timestamp: new-timestamp,
- /// The desired values of the data modification timestamp.
- data-modification-timestamp: new-timestamp,
- ) -> result<_, 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`.
- ///
- /// Note: This is similar to `pread` in POSIX.
- read: func(
- this: descriptor,
- /// The maximum number of bytes to read.
- length: filesize,
- /// The offset within the file at which to read.
- offset: filesize,
- ) -> result, bool>, 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`.
- ///
- /// Note: This is similar to `pwrite` in POSIX.
- write: func(
- this: descriptor,
- /// Data to write
- buffer: list,
- /// The offset within the file at which to write.
- offset: filesize,
- ) -> result
-
- /// 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.
- read-directory: func(
- this: descriptor
- ) -> result
-
- /// 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.
- sync: func(this: descriptor) -> result<_, 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.
+ get-type: func() -> result
- /// Create a directory.
- ///
- /// Note: This is similar to `mkdirat` in POSIX.
- create-directory-at: func(
- this: descriptor,
- /// The relative path at which to create the directory.
- path: string,
- ) -> result<_, error-code>
-
- /// Return the attributes of an open file or directory.
- ///
- /// Note: This is similar to `fstat` in POSIX.
- ///
- /// Note: This was called `fd_filestat_get` in earlier versions of WASI.
- stat: func(this: descriptor) -> result
+ /// Set status flags associated with a descriptor.
+ ///
+ /// This function may only change the `non-blocking` flag.
+ ///
+ /// Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
+ ///
+ /// Note: This was called `fd_fdstat_set_flags` in earlier versions of WASI.
+ set-flags: func(%flags: descriptor-flags) -> result<_, error-code>
- /// Return the attributes of a file or directory.
- ///
- /// Note: This is similar to `fstatat` in POSIX.
- ///
- /// Note: This was called `path_filestat_get` in earlier versions of WASI.
- stat-at: func(
- this: descriptor,
- /// Flags determining the method of how the path is resolved.
- path-flags: path-flags,
- /// The relative path of the file or directory to inspect.
- path: string,
- ) -> result
-
- /// 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.
- set-times-at: func(
- this: descriptor,
- /// Flags determining the method of how the path is resolved.
- path-flags: path-flags,
- /// The relative path of the file or directory to operate on.
- path: string,
- /// The desired values of the data access timestamp.
- data-access-timestamp: new-timestamp,
- /// The desired values of the data modification timestamp.
- data-modification-timestamp: new-timestamp,
- ) -> result<_, error-code>
-
- /// Create a hard link.
- ///
- /// Note: This is similar to `linkat` in POSIX.
- link-at: func(
- this: descriptor,
- /// Flags determining the method of how the path is resolved.
- old-path-flags: path-flags,
- /// The relative source path from which to link.
- old-path: string,
- /// The base directory for `new-path`.
- new-descriptor: descriptor,
- /// The relative destination path at which to create the hard link.
- new-path: string,
- ) -> result<_, error-code>
-
- /// Open a file or directory.
- ///
- /// The returned descriptor is not guaranteed to be the lowest-numbered
- /// descriptor not currently open/ it is randomized to prevent applications
- /// from depending on making assumptions about indexes, since this is
- /// error-prone in multi-threaded contexts. The returned descriptor is
- /// guaranteed to be less than 2**31.
- ///
- /// 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.
- open-at: func(
- this: descriptor,
- /// Flags determining the method of how the path is resolved.
- path-flags: path-flags,
- /// The relative path of the object to open.
- path: string,
- /// The method by which to open the file.
- open-flags: open-flags,
- /// Flags to use for the resulting descriptor.
- %flags: descriptor-flags,
- /// Permissions to use when creating a new file.
- modes: modes
- ) -> result
-
- /// 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.
- readlink-at: func(
- this: descriptor,
- /// The relative path of the symbolic link from which to read.
- path: string,
- ) -> result
-
- /// 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.
- remove-directory-at: func(
- this: descriptor,
- /// The relative path to a directory to remove.
- path: string,
- ) -> result<_, error-code>
-
- /// Rename a filesystem object.
- ///
- /// Note: This is similar to `renameat` in POSIX.
- rename-at: func(
- this: descriptor,
- /// The relative source path of the file or directory to rename.
- old-path: string,
- /// The base directory for `new-path`.
- new-descriptor: descriptor,
- /// The relative destination path to which to rename the file or directory.
- 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.
- symlink-at: func(
- this: descriptor,
- /// The contents of the symbolic link.
- old-path: string,
- /// The relative destination path at which to create the symbolic link.
- new-path: string,
- ) -> result<_, error-code>
-
- /// Check accessibility of a filesystem path.
- ///
- /// Check whether the given filesystem path names an object which is
- /// readable, writable, or executable, or whether it exists.
- ///
- /// This does not a guarantee that subsequent accesses will succeed, as
- /// filesystem permissions may be modified asynchronously by external
- /// entities.
- ///
- /// Note: This is similar to `faccessat` with the `AT_EACCESS` flag in POSIX.
- access-at: func(
- this: descriptor,
- /// Flags determining the method of how the path is resolved.
- path-flags: path-flags,
- /// The relative path to check.
- path: string,
- /// The type of check to perform.
- %type: access-type
- ) -> 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.
- unlink-file-at: func(
- this: descriptor,
- /// The relative path to a file to unlink.
- path: string,
- ) -> result<_, error-code>
-
- /// Change the permissions of a filesystem object that is not a directory.
- ///
- /// Note that the ultimate meanings of these permissions is
- /// filesystem-specific.
- ///
- /// Note: This is similar to `fchmodat` in POSIX.
- change-file-permissions-at: func(
- this: descriptor,
- /// Flags determining the method of how the path is resolved.
- path-flags: path-flags,
- /// The relative path to operate on.
- path: string,
- /// The new permissions for the filesystem object.
- modes: modes,
- ) -> result<_, error-code>
-
- /// Change the permissions of a directory.
- ///
- /// Note that the ultimate meanings of these permissions is
- /// filesystem-specific.
- ///
- /// Unlike in POSIX, the `executable` flag is not reinterpreted as a "search"
- /// flag. `read` on a directory implies readability and searchability, and
- /// `execute` is not valid for directories.
- ///
- /// Note: This is similar to `fchmodat` in POSIX.
- change-directory-permissions-at: func(
- this: descriptor,
- /// Flags determining the method of how the path is resolved.
- path-flags: path-flags,
- /// The relative path to operate on.
- path: string,
- /// The new permissions for the directory.
- modes: modes,
- ) -> result<_, error-code>
-
- /// Request a shared advisory lock for an open file.
- ///
- /// This requests a *shared* lock; more than one shared lock can be held for
- /// a file at the same time.
- ///
- /// If the open file has an exclusive lock, this function downgrades the lock
- /// to a shared lock. If it has a shared lock, this function has no effect.
- ///
- /// This requests an *advisory* lock, meaning that the file could be accessed
- /// by other programs that don't hold the lock.
- ///
- /// It is unspecified how shared locks interact with locks acquired by
- /// non-WASI programs.
- ///
- /// This function blocks until the lock can be acquired.
- ///
- /// Not all filesystems support locking; on filesystems which don't support
- /// locking, this function returns `error-code::unsupported`.
- ///
- /// Note: This is similar to `flock(fd, LOCK_SH)` in Unix.
- lock-shared: func(this: descriptor) -> 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.
+ set-size: func(size: filesize) -> result<_, error-code>
- /// Request an exclusive advisory lock for an open file.
- ///
- /// This requests an *exclusive* lock; no other locks may be held for the
- /// file while an exclusive lock is held.
- ///
- /// If the open file has a shared lock and there are no exclusive locks held
- /// for the file, this function upgrades the lock to an exclusive lock. If the
- /// open file already has an exclusive lock, this function has no effect.
- ///
- /// This requests an *advisory* lock, meaning that the file could be accessed
- /// by other programs that don't hold the lock.
- ///
- /// It is unspecified whether this function succeeds if the file descriptor
- /// is not opened for writing. It is unspecified how exclusive locks interact
- /// with locks acquired by non-WASI programs.
- ///
- /// This function blocks until the lock can be acquired.
- ///
- /// Not all filesystems support locking; on filesystems which don't support
- /// locking, this function returns `error-code::unsupported`.
- ///
- /// Note: This is similar to `flock(fd, LOCK_EX)` in Unix.
- lock-exclusive: func(this: descriptor) -> 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.
+ set-times: func(
+ /// The desired values of the data access timestamp.
+ data-access-timestamp: new-timestamp,
+ /// The desired values of the data modification timestamp.
+ data-modification-timestamp: new-timestamp,
+ ) -> result<_, 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`.
+ ///
+ /// Note: This is similar to `pread` in POSIX.
+ read: func(
+ /// The maximum number of bytes to read.
+ length: filesize,
+ /// The offset within the file at which to read.
+ offset: filesize,
+ ) -> result, bool>, 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`.
+ ///
+ /// Note: This is similar to `pwrite` in POSIX.
+ write: func(
+ /// Data to write
+ buffer: list,
+ /// The offset within the file at which to write.
+ offset: filesize,
+ ) -> result
+
+ /// 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.
+ read-directory: func() -> result
- /// Request a shared advisory lock for an open file.
- ///
- /// This requests a *shared* lock; more than one shared lock can be held for
- /// a file at the same time.
- ///
- /// If the open file has an exclusive lock, this function downgrades the lock
- /// to a shared lock. If it has a shared lock, this function has no effect.
- ///
- /// This requests an *advisory* lock, meaning that the file could be accessed
- /// by other programs that don't hold the lock.
- ///
- /// It is unspecified how shared locks interact with locks acquired by
- /// non-WASI programs.
- ///
- /// This function returns `error-code::would-block` if the lock cannot be
- /// acquired.
- ///
- /// Not all filesystems support locking; on filesystems which don't support
- /// locking, this function returns `error-code::unsupported`.
- ///
- /// Note: This is similar to `flock(fd, LOCK_SH | LOCK_NB)` in Unix.
- try-lock-shared: func(this: descriptor) -> 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.
+ sync: func() -> result<_, error-code>
- /// Request an exclusive advisory lock for an open file.
- ///
- /// This requests an *exclusive* lock; no other locks may be held for the
- /// file while an exclusive lock is held.
- ///
- /// If the open file has a shared lock and there are no exclusive locks held
- /// for the file, this function upgrades the lock to an exclusive lock. If the
- /// open file already has an exclusive lock, this function has no effect.
- ///
- /// This requests an *advisory* lock, meaning that the file could be accessed
- /// by other programs that don't hold the lock.
- ///
- /// It is unspecified whether this function succeeds if the file descriptor
- /// is not opened for writing. It is unspecified how exclusive locks interact
- /// with locks acquired by non-WASI programs.
- ///
- /// This function returns `error-code::would-block` if the lock cannot be
- /// acquired.
- ///
- /// Not all filesystems support locking; on filesystems which don't support
- /// locking, this function returns `error-code::unsupported`.
- ///
- /// Note: This is similar to `flock(fd, LOCK_EX | LOCK_NB)` in Unix.
- try-lock-exclusive: func(this: descriptor) -> result<_, error-code>
+ /// Create a directory.
+ ///
+ /// Note: This is similar to `mkdirat` in POSIX.
+ create-directory-at: func(
+ /// The relative path at which to create the directory.
+ path: string,
+ ) -> result<_, error-code>
- /// Release a shared or exclusive lock on an open file.
- ///
- /// Note: This is similar to `flock(fd, LOCK_UN)` in Unix.
- unlock: func(this: descriptor) -> result<_, 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.
+ stat: func() -> result
- /// Dispose of the specified `descriptor`, after which it may no longer
- /// be used.
- drop-descriptor: func(this: descriptor)
+ /// 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.
+ stat-at: func(
+ /// Flags determining the method of how the path is resolved.
+ path-flags: path-flags,
+ /// The relative path of the file or directory to inspect.
+ path: string,
+ ) -> result
+
+ /// 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.
+ set-times-at: func(
+ /// Flags determining the method of how the path is resolved.
+ path-flags: path-flags,
+ /// The relative path of the file or directory to operate on.
+ path: string,
+ /// The desired values of the data access timestamp.
+ data-access-timestamp: new-timestamp,
+ /// The desired values of the data modification timestamp.
+ data-modification-timestamp: new-timestamp,
+ ) -> result<_, error-code>
+
+ /// Create a hard link.
+ ///
+ /// Note: This is similar to `linkat` in POSIX.
+ link-at: func(
+ /// Flags determining the method of how the path is resolved.
+ old-path-flags: path-flags,
+ /// The relative source path from which to link.
+ old-path: string,
+ /// The base directory for `new-path`.
+ new-descriptor: descriptor,
+ /// The relative destination path at which to create the hard link.
+ new-path: string,
+ ) -> result<_, error-code>
+
+ /// Open a file or directory.
+ ///
+ /// The returned descriptor is not guaranteed to be the lowest-numbered
+ /// descriptor not currently open/ it is randomized to prevent applications
+ /// from depending on making assumptions about indexes, since this is
+ /// error-prone in multi-threaded contexts. The returned descriptor is
+ /// guaranteed to be less than 2**31.
+ ///
+ /// 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.
+ open-at: func(
+ /// Flags determining the method of how the path is resolved.
+ path-flags: path-flags,
+ /// The relative path of the object to open.
+ path: string,
+ /// The method by which to open the file.
+ open-flags: open-flags,
+ /// Flags to use for the resulting descriptor.
+ %flags: descriptor-flags,
+ /// Permissions to use when creating a new file.
+ modes: modes
+ ) -> result
+
+ /// 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.
+ readlink-at: func(
+ /// The relative path of the symbolic link from which to read.
+ path: string,
+ ) -> result
+
+ /// 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.
+ remove-directory-at: func(
+ /// The relative path to a directory to remove.
+ path: string,
+ ) -> result<_, error-code>
+
+ /// Rename a filesystem object.
+ ///
+ /// Note: This is similar to `renameat` in POSIX.
+ rename-at: func(
+ /// The relative source path of the file or directory to rename.
+ old-path: string,
+ /// The base directory for `new-path`.
+ new-descriptor: descriptor,
+ /// The relative destination path to which to rename the file or directory.
+ 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.
+ symlink-at: func(
+ /// The contents of the symbolic link.
+ old-path: string,
+ /// The relative destination path at which to create the symbolic link.
+ new-path: string,
+ ) -> result<_, error-code>
+
+ /// Check accessibility of a filesystem path.
+ ///
+ /// Check whether the given filesystem path names an object which is
+ /// readable, writable, or executable, or whether it exists.
+ ///
+ /// This does not a guarantee that subsequent accesses will succeed, as
+ /// filesystem permissions may be modified asynchronously by external
+ /// entities.
+ ///
+ /// Note: This is similar to `faccessat` with the `AT_EACCESS` flag in POSIX.
+ access-at: func(
+ /// Flags determining the method of how the path is resolved.
+ path-flags: path-flags,
+ /// The relative path to check.
+ path: string,
+ /// The type of check to perform.
+ %type: access-type
+ ) -> 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.
+ unlink-file-at: func(
+ /// The relative path to a file to unlink.
+ path: string,
+ ) -> result<_, error-code>
+
+ /// Change the permissions of a filesystem object that is not a directory.
+ ///
+ /// Note that the ultimate meanings of these permissions is
+ /// filesystem-specific.
+ ///
+ /// Note: This is similar to `fchmodat` in POSIX.
+ change-file-permissions-at: func(
+ /// Flags determining the method of how the path is resolved.
+ path-flags: path-flags,
+ /// The relative path to operate on.
+ path: string,
+ /// The new permissions for the filesystem object.
+ modes: modes,
+ ) -> result<_, error-code>
+
+ /// Change the permissions of a directory.
+ ///
+ /// Note that the ultimate meanings of these permissions is
+ /// filesystem-specific.
+ ///
+ /// Unlike in POSIX, the `executable` flag is not reinterpreted as a "search"
+ /// flag. `read` on a directory implies readability and searchability, and
+ /// `execute` is not valid for directories.
+ ///
+ /// Note: This is similar to `fchmodat` in POSIX.
+ change-directory-permissions-at: func(
+ /// Flags determining the method of how the path is resolved.
+ path-flags: path-flags,
+ /// The relative path to operate on.
+ path: string,
+ /// The new permissions for the directory.
+ modes: modes,
+ ) -> result<_, error-code>
+
+ /// Request a shared advisory lock for an open file.
+ ///
+ /// This requests a *shared* lock; more than one shared lock can be held for
+ /// a file at the same time.
+ ///
+ /// If the open file has an exclusive lock, this function downgrades the lock
+ /// to a shared lock. If it has a shared lock, this function has no effect.
+ ///
+ /// This requests an *advisory* lock, meaning that the file could be accessed
+ /// by other programs that don't hold the lock.
+ ///
+ /// It is unspecified how shared locks interact with locks acquired by
+ /// non-WASI programs.
+ ///
+ /// This function blocks until the lock can be acquired.
+ ///
+ /// Not all filesystems support locking; on filesystems which don't support
+ /// locking, this function returns `error-code::unsupported`.
+ ///
+ /// Note: This is similar to `flock(fd, LOCK_SH)` in Unix.
+ lock-shared: func() -> result<_, error-code>
+
+ /// Request an exclusive advisory lock for an open file.
+ ///
+ /// This requests an *exclusive* lock; no other locks may be held for the
+ /// file while an exclusive lock is held.
+ ///
+ /// If the open file has a shared lock and there are no exclusive locks held
+ /// for the file, this function upgrades the lock to an exclusive lock. If the
+ /// open file already has an exclusive lock, this function has no effect.
+ ///
+ /// This requests an *advisory* lock, meaning that the file could be accessed
+ /// by other programs that don't hold the lock.
+ ///
+ /// It is unspecified whether this function succeeds if the file descriptor
+ /// is not opened for writing. It is unspecified how exclusive locks interact
+ /// with locks acquired by non-WASI programs.
+ ///
+ /// This function blocks until the lock can be acquired.
+ ///
+ /// Not all filesystems support locking; on filesystems which don't support
+ /// locking, this function returns `error-code::unsupported`.
+ ///
+ /// Note: This is similar to `flock(fd, LOCK_EX)` in Unix.
+ lock-exclusive: func() -> result<_, error-code>
+
+ /// Request a shared advisory lock for an open file.
+ ///
+ /// This requests a *shared* lock; more than one shared lock can be held for
+ /// a file at the same time.
+ ///
+ /// If the open file has an exclusive lock, this function downgrades the lock
+ /// to a shared lock. If it has a shared lock, this function has no effect.
+ ///
+ /// This requests an *advisory* lock, meaning that the file could be accessed
+ /// by other programs that don't hold the lock.
+ ///
+ /// It is unspecified how shared locks interact with locks acquired by
+ /// non-WASI programs.
+ ///
+ /// This function returns `error-code::would-block` if the lock cannot be
+ /// acquired.
+ ///
+ /// Not all filesystems support locking; on filesystems which don't support
+ /// locking, this function returns `error-code::unsupported`.
+ ///
+ /// Note: This is similar to `flock(fd, LOCK_SH | LOCK_NB)` in Unix.
+ try-lock-shared: func() -> result<_, error-code>
+
+ /// Request an exclusive advisory lock for an open file.
+ ///
+ /// This requests an *exclusive* lock; no other locks may be held for the
+ /// file while an exclusive lock is held.
+ ///
+ /// If the open file has a shared lock and there are no exclusive locks held
+ /// for the file, this function upgrades the lock to an exclusive lock. If the
+ /// open file already has an exclusive lock, this function has no effect.
+ ///
+ /// This requests an *advisory* lock, meaning that the file could be accessed
+ /// by other programs that don't hold the lock.
+ ///
+ /// It is unspecified whether this function succeeds if the file descriptor
+ /// is not opened for writing. It is unspecified how exclusive locks interact
+ /// with locks acquired by non-WASI programs.
+ ///
+ /// This function returns `error-code::would-block` if the lock cannot be
+ /// acquired.
+ ///
+ /// Not all filesystems support locking; on filesystems which don't support
+ /// locking, this function returns `error-code::unsupported`.
+ ///
+ /// Note: This is similar to `flock(fd, LOCK_EX | LOCK_NB)` in Unix.
+ try-lock-exclusive: func() -> result<_, error-code>
+
+ /// Release a shared or exclusive lock on an open file.
+ ///
+ /// Note: This is similar to `flock(fd, LOCK_UN)` in Unix.
+ unlock: func() -> result<_, error-code>
+
+ /// 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.
+ is-same-object: func(other: descriptor) -> bool
+
+ /// 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 encourated 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: func() -> result
+
+ /// 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`.
+ metadata-hash-at: func(
+ /// Flags determining the method of how the path is resolved.
+ path-flags: path-flags,
+ /// The relative path of the file or directory to inspect.
+ path: string,
+ ) -> result
+ }
/// A stream of directory entries.
///
/// This [represents a stream of `dir-entry`](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Streams).
- type directory-entry-stream = u32
-
- /// Read a single directory entry from a `directory-entry-stream`.
- read-directory-entry: func(
- this: directory-entry-stream
- ) -> result