Sign in

    wasi

    Download zip
    Version
    0.21.0
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    768

    #WASI Preview 1 implementation for MoonBit

    ⚠️ It's a complete rewrite since 0.17.0

    Note: not all APIs are fully tested.

    #Implemented functions

    #Develop

    #Testing

    • Requirements: you need wasmtime & deno. You may use wasmedge or wamr if you replace the wasmtime in test.ts, but it may cause different testing result.
    • Comamnds: deno task test:build && deno task test

    Advice

    pub(all) enum Advice {
    Normal
    Sequential
    Random
    Willneed
    Dontneed
    Noreuse
    }
    File or memory access pattern advisory information.

    • Normal: The application has no advice to give on its behavior with respect to the specified data.
    • Sequential: The application expects to access the specified data sequentially from lower offsets to higher offsets.
    • Random: The application expects to access the specified data in a random order.
    • Willneed: The application expects to access the specified data in the near future.
    • Dontneed: The application expects that it will not access the specified data in the near future.
    • Noreuse: The application expects to access the specified data once and then not reuse it afterwards.
    impl Eq for Advice
    impl Show for Advice

    Advice::from_value

    fn Advice::from_value(value : UInt) -> Advice?

    Advice::value

    fn Advice::value(self : Advice) -> UInt

    CIOVec

    pub(all) struct CIOVec {
    buf : Int
    buf_len : Size
    }
    A region of memory for scatter/gather writes.

    • buf: The address of the buffer to be written.
    • buf_len: The length of the buffer to be written.
    impl Eq for CIOVec
    impl Show for CIOVec

    ClockId

    pub(all) enum ClockId {
    RealTime
    Monotonic
    ProcessCPUTimeId
    ThreadCPUTimeId
    }
    Identifiers for clocks.

    • Realtime: The clock measuring real time. Time value zero corresponds with 1970-01-01T00:00:00Z.
    • Monotonic: The store-wide monotonic clock, which is defined as a clock measuring real time, whose value cannot be adjusted and which cannot have negative clock jumps. The epoch of this clock is undefined. The absolute time value of this clock therefore has no meaning.
    • ProcessCPUTimeId: The CPU-time clock associated with the current process.
    • ThreadCPUTimeId: The CPU-time clock associated with the current thread.
    impl Eq for ClockId
    impl Show for ClockId

    ClockId::clock_res_get

    fn ClockId::clock_res_get(self : ClockId) -> TimeStamp raise Errno
    Return the resolution of a clock.

    Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, return errno::inval.

    Note: This is similar to clock_getres in POSIX.

    @param self The clock for which to return the resolution. @return The resolution of the clock, or an error if one happened.

    ClockId::clock_time_get

    fn ClockId::clock_time_get(self : ClockId, precision : TimeStamp) -> TimeStamp raise Errno
    Return the time value of a clock

    Note: This is similar to clock_gettime in POSIX.

    @param self The clodk for which to return the time. @param precision The maximum lag (exclusive) that the returned time value may have, compared to its actual value. @return The time value of the clock.

    ClockId::from_value

    fn ClockId::from_value(value : UInt) -> ClockId?

    ClockId::value

    fn ClockId::value(self : ClockId) -> UInt

    Device

    pub(all) type Device UInt64
    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.
    impl Eq for Device
    impl Show for Device

    Device::inner

    fn Device::inner(self : Device) -> UInt64
    Convert newtype to its underlying type, automatically derived.

    DirCookie

    pub(all) type DirCookie UInt64
    A reference to the offset of a directory entry.

    The value 0 signifies the start of the directory.
    impl Eq for DirCookie
    impl Show for DirCookie

    DirCookie::inner

    fn DirCookie::inner(self : DirCookie) -> UInt64
    Convert newtype to its underlying type, automatically derived.

    DirEnt

    pub(all) struct DirEnt {
    d_next : DirCookie
    d_ino : Inode
    d_namlen : DirNamlen
    d_type : FileType
    }
    A directory entry.

    • d_next: The offset of the next directory entry stored in the buffer.
    • d_ino: The serial number of the file referred to by this directory entry.
    • d_namlen: The length of the name of the directory entry.
    • d_type: The type of the file referred to by this directory entry.
    impl Eq for DirEnt
    impl Show for DirEnt

    DirNamlen

    pub(all) type DirNamlen UInt
    The type for the dirent::d_namlen field of dirent struct.
    impl Eq for DirNamlen
    impl Show for DirNamlen

    DirNamlen::inner

    fn DirNamlen::inner(self : DirNamlen) -> UInt
    Convert newtype to its underlying type, automatically derived.

    Errno

    pub(all) enum Errno {
    Success
    TooBig
    Acces
    Addrinuse
    Addrnotavail
    Afnosupport
    Again
    Already
    Badf
    Badmsg
    Busy
    Canceled
    Child
    Connaborted
    Connrefused
    Connreset
    Deadlock
    Destaddrreq
    Dom
    Dquot
    Exist
    Fault
    Fbig
    Hostunreach
    Idrm
    Ilseq
    Inprogress
    Intr
    Inval
    IO
    Isconn
    Isdir
    Loop
    Mfile
    Mlink
    Msgsize
    Multihop
    Nametoolong
    Netdown
    Netreset
    Netunreach
    Nfile
    Nobufs
    Nodev
    Noent
    Noexec
    Nolck
    Nolink
    Nomem
    Nomsg
    Noprotoopt
    Nospc
    Nosys
    Notconn
    Notdir
    Notempty
    Notrecoverable
    Notsock
    Notsup
    Notty
    Nxio
    Overflow
    Ownerdead
    Perm
    Pipe
    Proto
    Protonosupport
    Prototype
    Range
    Rofs
    Spipe
    Srch
    Stale
    Timedout
    Txtbsy
    Xdev
    Notcapable
    }
    Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

    See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant
    impl Eq for Errno
    impl Show for Errno

    Errno::from_value

    fn Errno::from_value(value : UInt) -> Errno?

    Errno::value

    fn Errno::value(self : Errno) -> UInt

    Event

    pub(all) struct Event {
    userdata : Userdata
    error : Errno
    type_ : EventType
    fd_readwrite : Event_fd_readwrite
    }
    An event that occurred.

    • userdata: User-provided value that got attched to subscription::userdata.
    • error: If non-zero, an error that occurred while processing the subscription request.
    • type_: The type of the event that occurred.
    • fd_readwrite: The contents of the event, if it is an eventtype::fd_read or eventtype::fd_write. eventtype::clock events ignore this field.
    impl Eq for Event
    impl Show for Event

    EventRWFlag

    pub(all) enum EventRWFlag {
    Fd_readwrite_hangup
    }
    The state of the file descriptor subscribed to with eventtype::fd_read or eventtype::fd_write.

    • Fd_readwrite_hangup: The peer of this socket has closed or disconnected.
    impl Eq for EventRWFlag
    impl Show for EventRWFlag

    EventRWFlag::value

    fn EventRWFlag::value(self : EventRWFlag) -> UInt

    EventRWFlags

    pub(all) type EventRWFlags UInt
    The state of the file descriptor subscribed to with eventtype::fd_read or eventtype::fd_write.
    impl Eq for EventRWFlags

    EventRWFlags::inner

    fn EventRWFlags::inner(self : EventRWFlags) -> UInt
    Convert newtype to its underlying type, automatically derived.

    EventRWFlags::is_set

    fn EventRWFlags::is_set(self : EventRWFlags, flag : EventRWFlag) -> Bool

    EventRWFlags::new

    EventRWFlags::set

    EventRWFlags::unset

    fn EventRWFlags::unset(self : EventRWFlags, flag : EventRWFlag) -> EventRWFlags

    EventType

    pub(all) enum EventType {
    Clock
    Fd_read
    Fd_write
    }
    Type of a subscription to an event or its occurrence.

    • Clock: The time value of clock subscription_clock::id has reached timestamp subscription_clock::timeout.
    • Fd_read: File descriptor subscription_fd_readwrite::file_descriptor has data available for reading. This event always triggers for regular files.
    • Fd_write: File descriptor subscription_fd_readwrite::file_descriptor has capacity available for writing. This event always triggers for regular files.
    impl Eq for EventType
    impl Show for EventType

    EventType::from_value

    fn EventType::from_value(value : UInt) -> EventType?

    EventType::value

    fn EventType::value(self : EventType) -> UInt

    Event_fd_readwrite

    pub(all) struct Event_fd_readwrite {
    nbytes : FileSize
    flags : EventRWFlags
    }
    The contents of an event when type is eventtype::fd_read or eventtype::fd_write.

    • nbytes: Number of bytes available for reading or writing.
    • flags: The state of the file descriptor.

    ExitCode

    pub(all) type ExitCode UInt
    Exit code generated by a process when exiting.
    impl Eq for ExitCode
    impl Show for ExitCode

    ExitCode::inner

    fn ExitCode::inner(self : ExitCode) -> UInt
    Convert newtype to its underlying type, automatically derived.
    pub(all) type Fd Int
    A file descriptor handle
    impl Eq for Fd
    impl Show for Fd

    Fd::fd_advise

    fn Fd::fd_advise(self : Fd, offset : FileSize, len : FileSize, advice : Advice) -> Unit raise Errno
    Provide file advisory information on a file ddescriptor

    Note: This is similar to posix_fadvise in POSIX.

    @param offset The offset within the file to which the advisory applies. @param len The length of the region to which the advisory applies. @param advice The advice.

    Fd::fd_allocate

    fn Fd::fd_allocate(self : Fd, offset : FileSize, len : FileSize) -> Unit raise Errno
    Force the allocaiton of space in a file.

    Note: This is similar to posix_fallocate in POSIX.

    @param offset The offset at which to start allocating. @param len The length of the area that is allocated. @return The error code.

    Fd::fd_close

    fn Fd::fd_close(self : Fd) -> Unit raise Errno
    Close a file descriptor.

    Note: This is similar to close in POSIX.

    Fd::fd_datasync

    fn Fd::fd_datasync(self : Fd) -> Unit raise Errno
    Synchronize the data of a file to disk.

    Note: This is similar to fdatasync in POSIX.

    Fd::fd_fdstat_get

    fn Fd::fd_fdstat_get(self : Fd) -> FdStat raise Errno
    Get the attributes of a file descriptor.

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

    Fd::fd_fdstat_set_flags

    fn Fd::fd_fdstat_set_flags(self : Fd, flags : FdFlags) -> Unit raise Errno
    Adjust the flags associated with a file descriptor.

    Note: This is similar to fcntl(fd, F_SETFL, flags) in POSIX.

    @param flags The desired values of the file descriptor flags.

    Fd::fd_fdstat_set_rights

    fn Fd::fd_fdstat_set_rights(self : Fd, fs_rights_base : Rights, fs_rights_inheriting : Rights) -> Unit raise Errno
    Adjust the rights associated with a file descriptor.

    This can only be used to remove rights, and returns errno::notcapable if called in a way that would attempt to add rights.

    @param fs_rights_base The desired rights of the file descriptor.

    Fd::fd_filestat_get

    fn Fd::fd_filestat_get(self : Fd) -> FileStat raise Errno
    Return the attributes of an open file

    Fd::fd_filestat_set_size

    fn Fd::fd_filestat_set_size(self : Fd, size : FileSize) -> Unit raise Errno
    Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.

    Note: This is similar to ftruncate in POSIX.

    @param size The desired file size.

    Fd::fd_filestat_set_times

    fn Fd::fd_filestat_set_times(self : Fd, atim : TimeStamp, mtim : TimeStamp, fst_flags : FstFlags) -> Unit raise Errno
    Adjust the timestamps of an open file or directory.

    Note: This is similar to futimens in POSIX.

    @param atim The desired value of the data access timestamp. @param mtim The desired value of the data modification timestamp. @param fst_flags A bitmask indicating which timestamps to adjust.

    Fd::fd_pread

    fn Fd::fd_pread(self : Fd, iovs : Array[FixedArray[Byte]], offset : FileSize) -> Size raise Errno
    Read from a file descriptor, without using and updating the file descriptor's offset.

    Note: This is similar to preadv in Linux (and other Unix-es).

    Fd::fd_prestat_dir_name

    fn Fd::fd_prestat_dir_name(self : Fd) -> String raise Errno
    Return a description of the given preopened file descriptor.

    Fd::fd_prestat_get

    fn Fd::fd_prestat_get(self : Fd) -> PreStat raise Errno
    Return a description of the given preopened file descriptor.

    Note: consider using fd_prestat_dir_name directly.

    Fd::fd_read

    fn Fd::fd_read(self : Fd, iovs : Array[FixedArray[Byte]]) -> Size raise Errno
    Read from a file descriptor.

    Note: This is similar to readv in POSIX.

    Fd::fd_readdir

    fn Fd::fd_readdir(self : Fd, cookie~ : DirCookie = .., buffer~ : Bytes = ..) -> (Array[(String, DirEnt)], Bool) raise Errno
    Read directory entries from a directory. When successful, the contents of the output buffer consist of a sequence of directory entries. Each directory entry consists of a dirent object, followed by dirent::d_namlen bytes holding the name of the directory entry.

    This function fills the output buffer as much as possible, potentially truncating the last directory entry. This allows the caller to grow its read buffer size in case it's too small to fit a single large directory entry, or skip the oversized directory entry.

    Entries for the special . and .. directory entries are included in the sequence.

    @param cookie: The location within the directory to start reading. @param size: The buffer used to read. @return The entries untruncated and whether there's still other entries.

    Fd::fd_renumber

    fn Fd::fd_renumber(self : Fd, to : Fd) -> Unit raise Errno
    Atomically replace a file descriptor by renumbering another file descriptor.

    Due to the strong focus on thread safety, this environment does not provide a mechanism to duplicate or renumber a file descriptor to an arbitrary number, like dup2(). This would be prone to race conditions, as an actual file descriptor with the same number could be allocated by a different thread at the same time.

    This function provides a way to atomically renumber file descriptors, which would disappear if dup2() were to be removed entirely.

    Fd::fd_seek

    fn Fd::fd_seek(self : Fd, offset : FileDelta, whence : Whence) -> FileSize raise Errno
    Move the offset of a file descriptor.

    Note: This is similar to lseek in POSIX.

    @param offset The number of bytes to move. @param whence The base from which the offset is calculated. @return The new offset of the file descriptor, relative to the start of the file.

    Fd::fd_sync

    fn Fd::fd_sync(self : Fd) -> Unit raise Errno
    Synchronize the data and metadata of a file to disk.

    Note: This is similar to fsync in POSIX.

    Fd::fd_tell

    fn Fd::fd_tell(self : Fd) -> FileSize raise Errno
    Return the current offset of a file descriptor.

    Note: This is similar to lseek(fd, 0, SEEK_CUR) in POSIX.

    @return The current offset of the file descriptor, relative to the start of the file.

    Fd::fd_write

    fn Fd::fd_write(self : Fd, contents : Array[
    View
    ]) -> Size raise Errno
    Write to a file descriptor.

    Note: This is similar to writev in POSIX.

    Like POSIX, any calls of write (and other functions to read or write) for a regular file by other threads in the WASI process should not be interleaved while write is executed.

    Note: it may write less than demanded.

    Fd::inner

    fn Fd::inner(self : Fd) -> Int
    Convert newtype to its underlying type, automatically derived.

    Fd::path_create_directory

    fn Fd::path_create_directory(self : Fd, path : String) -> Unit raise Errno
    Create a directory.

    Note: This is similar to mkdirat in POSIX.

    @param path The path at which to create the directory.

    Fd::path_filestat_get

    fn Fd::path_filestat_get(self : Fd, flags : LookupFlags, path : String) -> FileStat raise Errno
    Return the attributes of a file or directory.

    Note: This is similar to stat in POSIX.

    @param flags Flags determining the method of how the path is resolved. @param path The path of the file or directory to inspect.

    Fd::path_filestat_set_times

    fn Fd::path_filestat_set_times(self : Fd, flags : LookupFlags, path : String, atim : TimeStamp, mtim : TimeStamp, fst_flags : FstFlags) -> Unit raise Errno
    Adjust the timestamps of a file or directory.

    Note: This is similar to utimensat in POSIX.

    @param flag Flags determining the method of how the path is resolved. @param path The path of the file or directory to operate on. @param atim The desired values of the data access timestamp. @param mtim The desired values of the data modification timestamp. @param fst_flags A bitmask indicating which timestamps to adjust.
    fn Fd::path_link(self : Fd, old_flags : LookupFlags, old_path : String, new_fd : Fd, new_path : String) -> Unit raise Errno
    Create a hard link.

    Note: This is similar to linkat in POSIX.

    @param old_flags Flags determining the method of how the path is resolved. @param old_path The source path from which to link. @param new_fd The wroking directory at which the resolution of the new path starts. @param new_path The destination path at which to create the hard link.

    Fd::path_open

    fn Fd::path_open(self : Fd, dirflags : LookupFlags, path : String, oflags : OpenFlags, fs_rights_base : Rights, fs_rights_inheriting : Rights, fs_flags : FdFlags) -> Fd raise Errno
    Open a file or directory.

    The returned file descriptor is not guaranteed to be the lowest-numbered file 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 file descriptor is guaranteed to be less than 2^31.

    Note: This is similar to openat in POSIX.

    @param dirflags Flags determining the method of how the path is resolved. @param path The path of the file or directory to open. @param oflags The method by which to open the file. @param fs_rights_base The initial rights of the newly created file descriptor. The implementation is allowed to return a file descriptor with fewer rights than specified, if and only if those rights do not apply to the type of file being opened. The base rights are rights that will apply to operations using the file descriptor itself. @param fs_rights_inheriting The initial rights of the newly created file descriptor. The implementation is allowed to return a file descriptor with fewer rights than specified, if and only if those rights do not apply to the type of file being opened. The inheriting rights are rights that apply to file descriptors derived from it. @return The file descriptor of the file that has been opened.
    fn Fd::path_readlink(self : Fd, path : String, buffer~ : FixedArray[Byte] = ..) -> Size raise Errno
    Read the contents of a symbolic link.

    Note: This is similar to readlinkat in POSIX. If buf is not large enough to store the contents of the link, the first buf_len bytes will be written buf.

    Fd::path_remove_directory

    fn Fd::path_remove_directory(self : Fd, path : String) -> Unit raise Errno
    Remove a directory.

    Return errno::notempty if the directory is not empty.

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

    Fd::path_rename

    fn Fd::path_rename(self : Fd, old_path : String, new_fd : Fd, new_path : String) -> Unit raise Errno
    Rename a file or directory.

    Note: This is similar to renameat in POSIX.

    @param old_path The source path of the file or directory to rename. @param new_fd The working directory at which the resolution of the new path starts. @param new_path The destination path of the file or directory to rename.
    fn Fd::path_unlink_file(self : Fd, path : String) -> Unit raise Errno
    Unlink a file.

    Return errno::isdir if the path refers to a directory.

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

    Fd::sock_accept

    fn Fd::sock_accept(self : Fd, flags : FdFlags) -> Fd raise Errno
    Accept a new incoming connection on a socket.

    Note: This is similar to accept in POSIX.

    @param self The listening socket. @param flags The desired values of the file descriptor flags. @return New socket connection.

    Fd::sock_recv

    fn Fd::sock_recv(self : Fd, contents : Array[FixedArray[Byte]], flags : RiFlags) -> (Size, RoFlags) raise Errno
    Receive a message from a socket.

    Note: This is similar to recv in POSIX, though it also supports reading the data into multiple buffers in the manner of readv.

    @param contents List of scatter/gather vectors to which to store data. @param flags Message flags. @return Number of bytes stored in the buffers and message flags.

    Fd::sock_send

    fn Fd::sock_send(self : Fd, contents : Array[
    View
    ], flags : SiFlags) -> Size raise Errno
    Send a message on a socket.

    Note: This is similar to send in POSIX, though it also supports writing the data from multiple buffers in the manner of writev.

    @param contents List of scatter/gather vectors to which to retrieve the data. @param flags Message flags. @return The number of bytes transmitted.

    Fd::sock_shutdown

    fn Fd::sock_shutdown(self : Fd, how : SdFlags) -> Unit raise Errno
    Shut down socket send and receive channels.

    Note: This is similar to shutdown in POSIX.

    @param how Which channels on the socket to shut down.

    FdFlag

    pub(all) enum FdFlag {
    Append
    Dsync
    Nonblock
    Rsync
    Sync
    }
    File descriptor flags.

    • Append: Append mode: Data written to the file is always appended to the file's end.
    • Dsync: Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized.
    • Nonblock: Non-blocking mode.
    • Rsync: Synchronized read I/O operations.
    • Sync: Write according to synchronized I/O file integrity completion. In addition to synchronizing the data stored in the file, the implementation may also synchronously update the file's metadata.
    impl Eq for FdFlag
    impl Show for FdFlag

    FdFlag::value

    fn FdFlag::value(self : FdFlag) -> UInt

    FdFlags

    pub(all) type FdFlags UInt
    File descriptor flag.
    impl Eq for FdFlags
    impl Show for FdFlags

    FdFlags::inner

    fn FdFlags::inner(self : FdFlags) -> UInt
    Convert newtype to its underlying type, automatically derived.

    FdFlags::is_set

    fn FdFlags::is_set(self : FdFlags, flag : FdFlag) -> Bool

    FdFlags::new

    fn FdFlags::new() -> FdFlags

    FdFlags::set

    fn FdFlags::set(self : FdFlags, flag : FdFlag) -> FdFlags

    FdFlags::unset

    fn FdFlags::unset(self : FdFlags, flag : FdFlag) -> FdFlags

    FdStat

    pub(all) struct FdStat {
    fs_filetype : FileType
    fs_flags : FdFlags
    fs_rights_base : Rights
    fs_rights_inheriting : Rights
    }
    File descriptor attributes.

    • fs_filetype: File type.
    • fs_flags: File descriptor flags.
    • fs_rights_base: Rights that apply to this file descriptor.
    • fs_rights_inheriting: Maximum set of rights that may be installed on new file descriptors that are created through this file descriptor, e.g., through path_open.
    impl Eq for FdStat
    impl Show for FdStat

    FileDelta

    pub(all) type FileDelta Int64
    Relative offset within a file.
    impl Eq for FileDelta
    impl Show for FileDelta

    FileDelta::inner

    fn FileDelta::inner(self : FileDelta) -> Int64
    Convert newtype to its underlying type, automatically derived.

    FileSize

    pub(all) type FileSize UInt64
    Non-negative file size or length of a region within a file.
    impl Eq for FileSize
    impl Show for FileSize

    FileSize::inner

    fn FileSize::inner(self : FileSize) -> UInt64
    Convert newtype to its underlying type, automatically derived.

    FileStat

    pub(all) struct FileStat {
    dev : Device
    ino : Inode
    filetype : FileType
    nlink : LinkCount
    size : FileSize
    atim : TimeStamp
    mtim : TimeStamp
    ctim : TimeStamp
    }
    File attributes.

    • dev: Device ID of device containing the file.
    • ino: File serial number.
    • filetype: File type.
    • nlink: Number of hard links to the file.
    • size: For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
    • atim: Last data access timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
    • mtim: Last data modification timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
    • ctim: Last file status change timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
    impl Eq for FileStat
    impl Show for FileStat

    FileType

    pub(all) enum FileType {
    Unknown
    Block_device
    Character_device
    Directory
    Regular_file
    Socket_dgram
    Socket_stream
    Symbolic_link
    }
    The type of a file descriptor or file.

    • Unknown: The type of the file descriptor or file is unknown or is different from any of the other types specified.
    • Block_device: The file descriptor or file refers to a block device inode.
    • Character_device: The file descriptor or file refers to a character device inode.
    • Directory: The file descriptor or file refers to a directory inode.
    • Regular_file: The file descriptor or file refers to a regular file inode.
    • Socket_dgram: The file descriptor or file refers to a datagram socket.
    • Socket_stream: The file descriptor or file refers to a byte-stream socket.
    • Symbolic_link: The file refers to a symbolic link inode.
    impl Eq for FileType
    impl Show for FileType

    FileType::from_value

    fn FileType::from_value(value : Int) -> FileType?

    FileType::value

    fn FileType::value(self : FileType) -> Int

    FstFlag

    pub(all) enum FstFlag {
    Atim
    Atim_now
    Mtim
    Mtim_now
    }
    Which file time attributes to adjust

    • Atim: Adjust the last access timestamp to the value stored in filestat::atim.
    • Atim_now: Adjust the last access timestamp to the time of clock clockid::realtime.
    • Mtim: Adjust the last modification timestamp to the value stored in filestat::mtim.
    • Mtim_now: Adjust the last modification timestamp to the time of clock clockid::realtime.
    impl Eq for FstFlag
    impl Show for FstFlag

    FstFlag::value

    fn FstFlag::value(self : FstFlag) -> UInt

    FstFlags

    pub(all) type FstFlags UInt
    Which file time attributes to adjust
    impl Eq for FstFlags
    impl Show for FstFlags

    FstFlags::inner

    fn FstFlags::inner(self : FstFlags) -> UInt
    Convert newtype to its underlying type, automatically derived.

    FstFlags::is_set

    fn FstFlags::is_set(self : FstFlags, flag : FstFlag) -> Bool

    FstFlags::new

    fn FstFlags::new() -> FstFlags

    FstFlags::set

    fn FstFlags::set(self : FstFlags, flag : FstFlag) -> FstFlags

    FstFlags::unset

    fn FstFlags::unset(self : FstFlags, flag : FstFlag) -> FstFlags

    IOVec

    pub(all) struct IOVec {
    buf : Int
    buf_len : Size
    }
    A region of memory for scatter/gather reads.

    • buf: The address of the buffer to be filled.
    • buf_len: The length of the buffer to be filled.
    impl Eq for IOVec
    impl Show for IOVec

    Inode

    pub(all) type Inode UInt64
    File serial number that is unique within its file system.
    impl Eq for Inode
    impl Show for Inode

    Inode::inner

    fn Inode::inner(self : Inode) -> UInt64
    Convert newtype to its underlying type, automatically derived.

    LinkCount

    pub(all) type LinkCount UInt64
    Number of hard links to an inode.
    impl Eq for LinkCount
    impl Show for LinkCount

    LinkCount::inner

    fn LinkCount::inner(self : LinkCount) -> UInt64
    Convert newtype to its underlying type, automatically derived.

    LookupFlag

    pub(all) enum LookupFlag {
    Symlink_follow
    }

    impl Eq for LookupFlag
    impl Show for LookupFlag

    LookupFlag::value

    fn LookupFlag::value(self : LookupFlag) -> UInt

    LookupFlags

    pub(all) type LookupFlags UInt
    Flags dermining the method of how paths are resolved.
    impl Eq for LookupFlags
    impl Show for LookupFlags

    LookupFlags::inner

    fn LookupFlags::inner(self : LookupFlags) -> UInt
    Convert newtype to its underlying type, automatically derived.

    LookupFlags::is_set

    fn LookupFlags::is_set(self : LookupFlags, flag : LookupFlag) -> Bool

    LookupFlags::new

    LookupFlags::set

    fn LookupFlags::set(self : LookupFlags, flag : LookupFlag) -> LookupFlags

    LookupFlags::unset

    fn LookupFlags::unset(self : LookupFlags, flag : LookupFlag) -> LookupFlags

    OpenFlag

    pub(all) enum OpenFlag {
    Create
    Directory
    Excl
    Trunc
    }
    Open flags used by path_open.

    • Create: Create the file if it does not exist.
    • Directory: Fail if not a directory.
    • Excl: Fail if the file already exists.
    • Trunc: Truncate the file to size 0.
    impl Eq for OpenFlag
    impl Show for OpenFlag

    OpenFlag::value

    fn OpenFlag::value(self : OpenFlag) -> UInt

    OpenFlags

    pub(all) type OpenFlags UInt
    Open flags used by path_open.
    impl Eq for OpenFlags
    impl Show for OpenFlags

    OpenFlags::inner

    fn OpenFlags::inner(self : OpenFlags) -> UInt
    Convert newtype to its underlying type, automatically derived.

    OpenFlags::is_set

    fn OpenFlags::is_set(self : OpenFlags, flag : OpenFlag) -> Bool

    OpenFlags::new

    fn OpenFlags::new() -> OpenFlags

    OpenFlags::set

    fn OpenFlags::set(self : OpenFlags, flag : OpenFlag) -> OpenFlags

    OpenFlags::unset

    fn OpenFlags::unset(self : OpenFlags, flag : OpenFlag) -> OpenFlags

    PreOpenType

    pub(all) enum PreOpenType {
    Dir
    }
    Identifiers for preopened capabilites.

    • Dir: A pre-opened directory.
    impl Eq for PreOpenType
    impl Show for PreOpenType

    PreOpenType::from_value

    fn PreOpenType::from_value(value : UInt) -> PreOpenType?

    PreOpenType::value

    fn PreOpenType::value(self : PreOpenType) -> UInt

    PreStat

    pub(all) enum PreStat {
    Dir(PreStat_dir)
    }
    Information about a pre-opened capability.
    impl Eq for PreStat
    impl Show for PreStat

    PreStat_dir

    pub(all) struct PreStat_dir {
    pr_name_len : Size
    }
    The content of a prestat when type is preopentype::dir.

    • pr_name_len: The length of the directory name for use with fd_prestat_dir_name.
    impl Eq for PreStat_dir
    impl Show for PreStat_dir

    RiFlag

    pub(all) enum RiFlag {
    Recv_peek
    Recv_waitall
    }
    Flags provided to sock_recv.

    • Recv_peek: Returns the message without removing it from the socket's receive queue.
    • Recv_waitall: On byte-stream sockets, block until the full amount of data can be returned.
    impl Eq for RiFlag
    impl Show for RiFlag

    RiFlag::value

    fn RiFlag::value(self : RiFlag) -> UInt

    RiFlags

    pub(all) type RiFlags UInt
    Flags provided to sock_recv.
    impl Eq for RiFlags
    impl Show for RiFlags

    RiFlags::inner

    fn RiFlags::inner(self : RiFlags) -> UInt
    Convert newtype to its underlying type, automatically derived.

    RiFlags::is_set

    fn RiFlags::is_set(self : RiFlags, flag : RiFlag) -> Bool

    RiFlags::new

    fn RiFlags::new() -> RiFlags

    RiFlags::set

    fn RiFlags::set(self : RiFlags, flag : RiFlag) -> RiFlags

    RiFlags::unset

    fn RiFlags::unset(self : RiFlags, flag : RiFlag) -> RiFlags

    pub(all) enum Right {
    Fd_datasync
    Fd_read
    Fd_seek
    Fd_fdstat_set_flags
    Fd_sync
    Fd_tell
    Fd_write
    Fd_advice
    Fd_allocate
    Path_create_directory
    Path_create_file
    Path_link_source
    Path_link_target
    Path_open
    Fd_readdir
    Path_readlink
    Path_rename_source
    Path_rename_target
    Path_filestat_get
    Path_filestat_set_size
    Path_filestat_set_times
    Fd_filestat_get
    Fd_filestat_set_size
    Fd_filestat_set_times
    Path_symlink
    Path_remove_directory
    Path_unlink_file
    Poll_fd_readwrite
    Sock_shutdown
    Sock_accept
    }
    File descriptor rights, determining which actions may be performed.
    impl Eq for Right
    impl Show for Right

    Right::value

    fn Right::value(self : Right) -> UInt64

    Rights

    pub(all) type Rights UInt64
    File descriptor rights, determining which actions may be performed.
    impl Eq for Rights
    impl Show for Rights

    Rights::inner

    fn Rights::inner(self : Rights) -> UInt64
    Convert newtype to its underlying type, automatically derived.

    Rights::is_set

    fn Rights::is_set(self : Rights, right : Right) -> Bool

    Rights::new

    fn Rights::new() -> Rights

    Rights::set

    fn Rights::set(self : Rights, right : Right) -> Rights

    Rights::unset

    fn Rights::unset(self : Rights, right : Right) -> Rights

    RoFlag

    pub(all) enum RoFlag {
    Recv_data_truncated
    }
    Flags returned by sock_recv.

    • Recv_data_truncated: Returned by sock_recv: Message data has been truncated.
    impl Eq for RoFlag
    impl Show for RoFlag

    RoFlag::value

    fn RoFlag::value(self : RoFlag) -> UInt

    RoFlags

    pub(all) type RoFlags UInt
    Flags returned by sock_recv.
    impl Eq for RoFlags
    impl Show for RoFlags

    RoFlags::inner

    fn RoFlags::inner(self : RoFlags) -> UInt
    Convert newtype to its underlying type, automatically derived.

    RoFlags::is_set

    fn RoFlags::is_set(self : RoFlags, flag : RoFlag) -> Bool

    RoFlags::new

    fn RoFlags::new() -> RoFlags

    RoFlags::set

    fn RoFlags::set(self : RoFlags, flag : RoFlag) -> RoFlags

    RoFlags::unset

    fn RoFlags::unset(self : RoFlags, flag : RoFlag) -> RoFlags

    SdFlag

    pub(all) enum SdFlag {
    Rd
    Wr
    }
    Which channels on a socket to shut down.

    • Rd: Disables further receive operations.
    • Wr: Disables further send operations.
    impl Eq for SdFlag
    impl Show for SdFlag

    SdFlag::value

    fn SdFlag::value(self : SdFlag) -> UInt

    SdFlags

    pub(all) type SdFlags UInt
    Which channels on a socket to shut down.
    impl Eq for SdFlags
    impl Show for SdFlags

    SdFlags::inner

    fn SdFlags::inner(self : SdFlags) -> UInt
    Convert newtype to its underlying type, automatically derived.

    SdFlags::is_set

    fn SdFlags::is_set(self : SdFlags, flag : SdFlag) -> Bool

    SdFlags::new

    fn SdFlags::new() -> SdFlags

    SdFlags::set

    fn SdFlags::set(self : SdFlags, flag : SdFlag) -> SdFlags

    SdFlags::unset

    fn SdFlags::unset(self : SdFlags, flag : SdFlag) -> SdFlags

    SiFlag

    pub(all) enum SiFlag {
    }
    Flags returned by sock_send. As there are currently no flags defined, it must be set to zero.
    impl Eq for SiFlag
    impl Show for SiFlag

    SiFlag::value

    fn SiFlag::value(self : SiFlag) -> UInt

    SiFlags

    pub(all) type SiFlags UInt
    Flags provided to sock_send. As there are currently no flags defined, it must be set to zero.
    impl Eq for SiFlags
    impl Show for SiFlags

    SiFlags::inner

    fn SiFlags::inner(self : SiFlags) -> UInt
    Convert newtype to its underlying type, automatically derived.

    SiFlags::is_set

    fn SiFlags::is_set(self : SiFlags, flag : SiFlag) -> Bool

    SiFlags::new

    fn SiFlags::new() -> SiFlags

    SiFlags::set

    fn SiFlags::set(self : SiFlags, flag : SiFlag) -> SiFlags

    SiFlags::unset

    fn SiFlags::unset(self : SiFlags, flag : SiFlag) -> SiFlags

    Signal

    pub(all) enum Signal {
    None
    Hup
    Inte
    Quit
    Ill
    Trap
    Abrt
    Bus
    Fpe
    Kill
    Usr1
    Segv
    Usr2
    Pipe
    Alrm
    Term
    Chld
    Cont
    Stop
    Tstp
    Ttin
    Ttou
    Urg
    Xcpu
    Xfsz
    Vtalrm
    Prof
    Winch
    Poll
    Pwr
    Sys
    }
    Signal condition.

    • None: No signal. Note that POSIX has special semantics for kill(pid, 0), so this value is reserved.
    • Hup: Hangup. Action: Terminates the process.
    • Inte: Terminate interrupt signal. Action: Terminates the process.
    • Quit: Terminal quit signal. Action: Terminates the process.
    • Ill: Illegal instruction. Action: Terminates the process.
    • Trap: Trace/breakpoint trap. Action: Terminates the process.
    • Abrt: Process abort signal. Action: Terminates the process.
    • Bus: Access to an undefined portion of a memory object. Action: Terminates the process.
    • Fpe: Erroneous arithmetic operation. Action: Terminates the process.
    • Kill: Kill. Action: Terminates the process.
    • Usr1: User-defined signal 1. Action: Terminates the process.
    • Segv: Invalid memory reference. Action: Terminates the process.
    • Usr2: User-defined signal 2. Action: Terminates the process.
    • Pipe: Write on a pipe with no one to read it. Action: Ignored.
    • Alrm: Alarm clock. Action: Terminates the process.
    • Chld: Child process terminated, stopped, or continued. Action: Ignored.
    • Cont: Continue executing, if stopped. Action: Continues the process.
    • Stop: Stop executing. Action: Stops the process.
    • Tstp: Terminal stop signal. Action: Stops the process.
    • Ttin: Background process attempting read. Action: Stops the process.
    • Ttou: Background process attempting write. Action: Stops the process.
    • Urg: High bandwidth data is available at a socket. Action: Ignored.
    • Xcpu: CPU time limit exceeded. Action: Terminates the process.
    • Xfsz: File size limit exceeded. Action: Terminates the process.
    • Vtalrm: Virtual timer expired. Action: Terminates the process.
    • Prof: Profiling timer expired. Action: Terminates the process.
    • Winch: Window changed. Action: Ignored.
    • Poll: I/O possible. Action: Terminates the process.
    • Pwr: Power failure. Action: Terminates the process.
    • Sys: Bad system call. Action: Terminates the process.
    impl Eq for Signal
    impl Show for Signal

    Signal::from_value

    fn Signal::from_value(value : UInt) -> Signal?

    Signal::value

    fn Signal::value(self : Signal) -> UInt

    Size

    pub(all) type Size UInt

    impl Eq for Size
    impl Show for Size

    Size::inner

    fn Size::inner(self : Size) -> UInt
    Convert newtype to its underlying type, automatically derived.

    SubclockFlag

    pub(all) enum SubclockFlag {
    Subscription_clock_abstime
    }
    Flags determining how to interpret the timestamp provided in subscription::timeout.

    • Subscription_clock_abstime: If set, treat the timestamp provided in subscription_clock::timeout as an absolute timestamp of clock subscription_clock::id. If clear, treat the timestamp provided in subscription_clock::timeout relative to the current time value of clock subscription_clock::id.
    impl Eq for SubclockFlag

    SubclockFlag::value

    fn SubclockFlag::value(self : SubclockFlag) -> UInt

    SubclockFlags

    pub(all) type SubclockFlags UInt
    Flags determining how to interpret the timestamp provided in subscription::timeout.
    impl Eq for SubclockFlags

    SubclockFlags::inner

    fn SubclockFlags::inner(self : SubclockFlags) -> UInt
    Convert newtype to its underlying type, automatically derived.

    SubclockFlags::is_set

    fn SubclockFlags::is_set(self : SubclockFlags, flag : SubclockFlag) -> Bool

    SubclockFlags::new

    SubclockFlags::set

    SubclockFlags::unset

    Subscription

    pub(all) struct Subscription {
    userdata : Userdata
    u : Subscription_u
    }
    Subscription to an event.

    • userdata: User-provided value that is attached to the subscription in the implementaiton and returned through event::userdata.
    • u: The type of the event to which to subscribe, and its contents.
    impl Eq for Subscription

    Subscription_clock

    pub(all) struct Subscription_clock {
    id : ClockId
    timeout : TimeStamp
    precision : TimeStamp
    flags : SubclockFlags
    }
    The contents of a subscription when type is eventtype::clock.

    • id: The clock against which to compare the timestamp.
    • timeout: The absolute or relative timestamp.
    • precision: The amount of time that the implementation may wait additionally to coalesce with other events.
    • flags: Flags specifying whether the timeout is absolute or relative.

    Subscription_fd_readwrite

    pub(all) struct Subscription_fd_readwrite {
    file_descriptor : Fd
    }
    The contents of a subscription when type is eventtype::fd_read or eventtype::fd_write.

    • file_descriptor: The file descriptor on which to wait for it to become ready for reading or writing.

    Subscription_u

    pub(all) enum Subscription_u {
    Clock(Subscription_clock)
    Fd_read(Subscription_fd_readwrite)
    Fd_write(Subscription_fd_readwrite)
    }
    The contents of a subscription.

    TimeStamp

    pub(all) type TimeStamp UInt64
    Timestamp in nanoseconds.
    impl Eq for TimeStamp
    impl Show for TimeStamp

    TimeStamp::inner

    fn TimeStamp::inner(self : TimeStamp) -> UInt64
    Convert newtype to its underlying type, automatically derived.

    Userdata

    pub(all) type Userdata UInt64
    User-provided value that may be attached to objects that is retained when extracted from the implementation.
    impl Eq for Userdata
    impl Show for Userdata

    Userdata::inner

    fn Userdata::inner(self : Userdata) -> UInt64
    Convert newtype to its underlying type, automatically derived.

    Whence

    pub(all) enum Whence {
    Set
    Cur
    End
    }
    The position relative to which to set the offset of the file descriptor
    impl Eq for Whence
    impl Show for Whence

    Whence::from_value

    fn Whence::from_value(value : UInt) -> Whence?

    Whence::value

    fn Whence::value(self : Whence) -> UInt

    args_get

    fn args_get() -> Array[String] raise Errno
    Read command-line argument data.

    The size of the array should match that returned by args_sizes_get.

    Each argument is not \0 terminated.

    The first argument should be a string containing the "name" of the program. This need not be a usable filesystem path or even file name, and may even be a fixed string. Subsequent arguments are the arguments passed to the program by the user.

    args_sizes_get

    fn args_sizes_get() -> (Int, Int) raise Errno
    Return command-line argument data sizes.

    @return Returns the number of arguments and the size of the argument string data, or an error.

    environ_get

    fn environ_get() -> Array[(String, String)] raise Errno
    Read environment variable data.

    The size of the array should match that returned by environ_sizes_get.

    environ_sizes_get

    fn environ_sizes_get() -> (Int, Int) raise Errno
    Return environment variable data sizes.

    @return Returns the number of environment variables arguments and the size of the environment variable data.
    fn path_symlink(old_path : String, fd : Fd, new_path : String) -> Unit raise Errno
    Create a symbolic link.

    Note: This is similar to symlinkat in POSIX.

    poll_oneoff

    fn poll_oneoff(in_ : Array[Subscription]) -> Array[Event] raise Errno
    Concurrently poll for the occurrence of a set of events.

    If nsubscriptions is 0, returns errno::inval.

    @param in_ The events to which to subscribe. @return The events that have occurred.

    proc_exit

    fn proc_exit(rval : UInt) -> Unit
    Terminate the process normally. An exit code of 0 indicates successful termination of the program. The meanings of other values is dependent on the environment.

    Note: the accepted range may depend on the runtime, meaning that it may become an error to return a value outside the accepted range of exit codes, making the actual error code environment-dependent.

    proc_raise

    fn proc_raise(sig : Signal) -> Unit raise Errno
    Send a signal to the process of the calling thread.

    Note: This is similar to raise in POSIX.

    @param sig The signal condition to trigger.

    random_get

    fn random_get(buf : FixedArray[Byte]) -> Unit raise Errno
    Write high-quality random data into a buffer.

    This function blocks when the implementaiton is unable to immediately provide sufficient high-quality random data.

    This function may execute slowly, so when larget mounts of random data are required, it's advisable to use this function to seed a pseudo-random number generator, rather than to provide the random data directly.

    sched_yield

    fn sched_yield() -> Unit raise Errno
    Temporarily yield execution of the calling thread.

    Note: This is similar to sched_yield in POSIX.

    stderr

    let stderr : Fd

    stdin

    let stdin : Fd

    stdout

    let stdout : Fd

    Source Files