gizlang:system
The program's authority: files, network, arguments and environment. A process receives it as main(sys: System); library code can use only what it is passed, and every value here has private fields, so none can be forged. Directories, streams, listeners and sockets belong to the task that opened them and close when it ends; using one after it closed is fault 14. Reads, writes, connects, accepts and receives suspend only the calling task. Failures a program should handle are IoError values.
import * as System from "gizlang:system";Types
System
type SystemThe handle of the running system: its files, clock, processes and network.
Opaque: create and use it through this module's functions.
DirectoryEntries
type DirectoryEntriesA directory that is being listed, entry by entry.
Opaque: create and use it through this module's functions.
Dir
type DirAn open directory: files and folders are opened below it.
Opaque: create and use it through this module's functions.
Stream
type StreamAn open byte stream, such as a file or a pipe.
Opaque: create and use it through this module's functions.
Listener
type ListenerA listening socket that accepts connections.
Opaque: create and use it through this module's functions.
Socket
type SocketA connected socket.
Opaque: create and use it through this module's functions.
Ready
type ReadyConnections waiting without a task, reported when bytes arrive (Ready.wait).
Opaque: create and use it through this module's functions.
Signals
type SignalsProcess signals a task reads one at a time (System.signals).
Opaque: create and use it through this module's functions.
Datagram
type Datagram = { data: bytes; host: string; port: i64; }One received UDP datagram and the address and port it came from.
data:byteshost:stringport:i64
IoError
type IoError = { code: i64; }A platform error code (negative, as libuv reports it) or a Gizlang one.
code:i64
ProcessUsage
type ProcessUsage = { residentBytes: i64; peakBytes: i64; userMicros: i64; systemMicros: i64; readBytes: i64; writtenBytes: i64; }The resources that the process used: resident and peak memory (the peak since this program started, not its parent before exec), CPU time and bytes read and written.
residentBytes:i64peakBytes:i64userMicros:i64systemMicros:i64readBytes:i64writtenBytes:i64
CgroupUsage
type CgroupUsage = { path: string; memoryBytes: Option<i64>; cpuMicros: i64; readBytes: Option<i64>; writtenBytes: Option<i64>; }The resources of the control group that the process runs in; a limit that the system does not report is none.
path:stringmemoryBytes:_gizlang_sdk_core.Option<i64>cpuMicros:i64readBytes:_gizlang_sdk_core.Option<i64>writtenBytes:_gizlang_sdk_core.Option<i64>
Usage
type Usage = { process: ProcessUsage; cgroup: Option<CgroupUsage>; }The resource use of the process, and of its control group when there is one.
process:gizlang_system.ProcessUsagecgroup:_gizlang_sdk_core.Option<gizlang_system.CgroupUsage>
FileInfo
type FileInfo = { size: i64; modified: i64; kind: string; mode: i64; }What a file is: its size, the time it was modified (ms), its kind and its mode bits.
size:i64modified:i64kind:stringmode:i64
FileClone
type FileClone = | { kind: "reflink"; } | { kind: "hardLink"; }How a file is cloned: a copy-on-write reflink, or a hard link.
reflinkhardLink
ProcessMemory
type ProcessMemory = { residentBytes: i64; peakBytes: i64; }The resident memory of process PID and its peak, on every OS.
residentBytes:i64peakBytes:i64
EnvironmentVariable
type EnvironmentVariable = { name: string; value: string; }One environment variable.
name:stringvalue:string
StreamPair
type StreamPair = { first: Stream; second: Stream; }Two connected streams inside this process: what one writes the other
reads, until either closes. A loop watching first in its Ready set is
woken by a write to second (from a task, a ticker, or itself).
first:gizlang_system.Streamsecond:gizlang_system.Stream
Watch
type Watch = { stream: Stream; rest: bytes; }The changes to the entries of folder path ("" is this one) as they happen, until it is closed: Linux inotify.
stream:gizlang_system.Streamrest:bytes
WatchEvent
type WatchEvent = { wd: i64; mask: i64; name: string; }One change: the watch number of the folder, what happened (the WATCH_ bits, Linux inotify's) and the entry's name ("" for the folder itself).
wd:i64mask:i64name:string
ProxyHeader
type ProxyHeader = { size: i64; address: string; }The PROXY protocol header (HAProxy, versions 1 and 2) that a load balancer writes first on a connection it forwards:
size bytes, and the client address (without port; IPv6 as eight groups of four hex digits), or "" for a LOCAL or UNKNOWN connection
(the balancer's own health check), whose peer stays the socket's.
size:i64address:string
Stdio
type Stdio = | { kind: "inherit" } | { kind: "pipe" } | { kind: "ignore" } | { kind: "stream"; stream: Stream; }Standard streams and child processes use the same task-owned Stream handles.
inheritpipeignorestream
Limits
type Limits = { memory: i64; cpu: i64; processes: i64; }At most MEMORY bytes (over it the whole process tree is killed), CPU in thousandths of a core (1000: one core), PROCESSES processes and threads; 0 leaves that one unlimited. A Gizlang program stops itself with R011 at four fifths of MEMORY, before the kernel kills it.
memory:i64cpu:i64processes:i64
ProcessGrant
type ProcessGrant = | { kind: "listener"; value: Listener; } | { kind: "stream"; value: Stream; }Explicit process resources. Both variants use the same inherited descriptor slots.
listenerstream
SpawnOptions
type SpawnOptions = { stdin: Stdio; stdout: Stdio; stderr: Stdio; cwd: Option<string>; environment: Vec<string>; inheritEnvironment: bool; isolated: bool; handed: Vec<ProcessGrant>; limits: Limits; }The options of a started process: its three streams, working folder, environment and isolation.
stdin:gizlang_system.Stdiostdout:gizlang_system.Stdiostderr:gizlang_system.Stdiocwd:_gizlang_sdk_core.Option<string>environment:Vec<string>inheritEnvironment:bool— False starts with only environment additions and runtime resource grants. Host secrets and unmentioned environment entries are absent.isolated:bool— Confined tocwdas its whole filesystem, with no network or other process in reach (Linux); a Gizlang program only.handed:Vec<gizlang_system.ProcessGrant>— Resources inherited as descriptors 3, 4, ... (at most 16): listeners, and streams with an OS descriptor (a file grant, an imported descriptor, a sys.streamPair end). Listener grants are received through sys.handed(index); a stream through sys.importDescriptor(3 + index, ...); native programs use the descriptor ABI.limits:gizlang_system.Limits— Resource limits (Linux cgroup v2, below a delegated cgroup of the spawner's); a Gizlang program only, which exits 71 rather than run without them.
Child
type ChildA started process.
Opaque: create and use it through this module's functions.
ExitStatus
type ExitStatus = | { kind: "code"; code: i64 } | { kind: "signal"; signal: i64 }How a process ended: with an exit code, or by a signal.
codesignal
Output
type Output = { status: ExitStatus; stdout: bytes; stderr: bytes; }What a process printed and how it ended.
status:gizlang_system.ExitStatusstdout:bytesstderr:bytes
Ran
type Ran = { code: i64; out: string; err: string; }A finished process as text: its exit code (ExitStatus.exitCode) and its two outputs. Tools that run programs and
read their output as text use it (the CLI, the test harness, the fleet tools).
code:i64out:stringerr:string
CaptureBudget
type CaptureBudget = { milliseconds: i64; outputBytes: i64; }Capture bounds are independent of SpawnOptions' OS resource limits.
milliseconds:i64outputBytes:i64
CapturedOutput
type CapturedOutput = { output: Output; outputLimit: bool; }The output of a process, and whether it was cut at the output limit.
output:gizlang_system.OutputoutputLimit:bool
Stat
type Stat = { dev: i64; mode: i64; nlink: i64; uid: i64; gid: i64; rdev: i64; blksize: i64; ino: i64; size: i64; blocks: i64; atimeSec: i64; atimeNsec: i64; mtimeSec: i64; mtimeNsec: i64; ctimeSec: i64; ctimeNsec: i64; birthSec: i64; birthNsec: i64; }Everything stat(2) reports (statx on Linux), times as seconds and nanoseconds. birth is ctime when the file system does not keep a birth time, as libuv reports it.
dev:i64mode:i64nlink:i64uid:i64gid:i64rdev:i64blksize:i64ino:i64size:i64blocks:i64atimeSec:i64atimeNsec:i64mtimeSec:i64mtimeNsec:i64ctimeSec:i64ctimeNsec:i64birthSec:i64birthNsec:i64
StatFs
type StatFs = { type: i64; bsize: i64; blocks: i64; bfree: i64; bavail: i64; files: i64; ffree: i64; }The numbers of a file system, as statfs reports them.
type:i64bsize:i64blocks:i64bfree:i64bavail:i64files:i64ffree:i64
DirEntry
type DirEntry = { name: string; kind: i64; }A directory entry and its kind: the UV_DIRENT values (0 unknown, 1 file, 2 dir, 3 link, 4 fifo, 5 socket, 6 char, 7 block).
name:stringkind:i64
Ring
type RingAn io_uring of 128-byte submissions for passthrough commands (IORING_OP_URING_CMD): the ublk control and queue commands, NVMe passthrough. Each command carries USER_DATA, and its completion comes back with it. Linux only: elsewhere System.ring fails. Close it with close.
Opaque: create and use it through this module's functions.
Completion
type Completion = { userData: i64; result: i64; }A completed command: the USER_DATA it was queued with and its result (negative: -errno).
userData:i64result:i64
TerminalSize
type TerminalSize = { columns: i64; rows: i64; }The size of a terminal in columns and rows.
columns:i64rows:i64
OsInfo
type OsInfo = { sysname: string; release: string; version: string; machine: string; }The operating system: its name, release, version and machine type.
sysname:stringrelease:stringversion:stringmachine:string
MemoryInfo
type MemoryInfo = { total: i64; available: i64; }Physical memory in bytes: all of it, and what the OS can give without swapping (Linux MemAvailable, macOS free and inactive pages, Windows available physical memory; Node's os.totalmem and os.freemem).
total:i64available:i64
CpuInfo
type CpuInfo = { model: string; speed: i64; user: i64; nice: i64; sys: i64; idle: i64; irq: i64; }The time of one CPU: its model, speed and the time it spent in each mode.
model:stringspeed:i64user:i64nice:i64sys:i64idle:i64irq:i64
Interface
type Interface = { name: string; address: string; netmask: string; family: string; mac: string; internal: bool; scopeId: i64; }A network interface: its name, address, netmask, family, MAC address, whether it is internal, and its scope id.
name:stringaddress:stringnetmask:stringfamily:stringmac:stringinternal:boolscopeId:i64
UserInfo
type UserInfo = { uid: i64; gid: i64; username: string; homedir: string; shell: string; }A user of the system: ids, name, home folder and shell.
uid:i64gid:i64username:stringhomedir:stringshell:string
Credentials
type Credentials = { uid: i64; euid: i64; gid: i64; egid: i64; groups: Vec<i64>; }The user and group ids that the process runs with; -1 and no groups on Windows.
uid:i64euid:i64gid:i64egid:i64groups:Vec<i64>
Functions
osError
function osError(code: i64): IoErrorThe IoError of CODE, a code the runtime or the OS gave: the Linux number of its name on every OS, so that it compares with NOT_FOUND and the other names.
ioMessage
function ioMessage<T>(result: Result<T, IoError>, what: string): T throws stringRESULT with its error as WHAT, a colon and the error's message, for a caller that reports plain text.
publicAddress
function publicAddress(address: string): boolWhether address (as System.addresses returns it) is on the public
internet: false for loopback, private, carrier-grade NAT, link-local,
documentation, benchmarking, multicast and reserved IPv4 ranges, and for
their IPv6 counterparts (::1, unique local, link- and site-local,
multicast, documentation) and IPv6 forms that carry an IPv4 address
(mapped, compatible, NAT64, 6to4, Teredo) unless that address is public.
Not an address at all is false.
Effects: fail.
serveThreads
function serveThreads<F>(self: System, count: i64, work: F): i64 throws IoError effects { work, io, fail }work(own, i) for every i in 0..count: i = 0 on the calling thread with this System, each other i on an OS thread of its own (Task.thread)
with its own System. The requests they served, or the first error (a thread that faults is IO_FAILURE). A server that listens in each call
on one port (listenShared) has a reactor for each thread, and the kernel spreads the connections among them. What work captures is
shared read-only; state that every thread sees lives in a database, not in a thread's memory.
serveConnections
function serveConnections(set: Ready, turnConnection: (stream: Stream) => i64): i64 throws IoErrorThe one scheduler of a server of any protocol: it answers the connections that the Ready set reports. turn(stream) reads
what the connection has sent, answers it, and returns the number of requests it served; it gives the connection back with
set.watch(stream) or closes it. A fault in a turn ends only its connection. Fill the set with set.accept(listener) (or let
a TLS layer fill it). It returns the sum of the counts when the set stops (the listener is closed; requests in flight
finish), or the error that stopped it. HTTP (gizlang:http) is a turn on this; so is a protocol you write.
Effects: fail, read, write, console, io.
ready
function ready(idleMs: i64): Ready throws IoErrorA set of connections that wait without a task, as epoll does: those it accepts or is given to watch are reported once each by wait() when bytes arrive or they end (bytes put back with unread do not count). A connection watched and silent for idleMs (0: no limit) is reported too, and its read fails with TIMED_OUT. It grants nothing: connections come from a Listener or a Stream the caller holds.
Effects: fail, io.
peerClosed
function peerClosed(descriptor: i64): boolWhether the peer of socket DESCRIPTOR (Stream.descriptor) has closed its side, without taking any of its bytes, on any thread; false for a socket still open or for another descriptor. A server's thread asks it during a long statement, whose client may have left.
Effects: fail, io.
proxyHeader
function proxyHeader(data: bytes): Option<ProxyHeader>The PROXY header at the start of data, if it has a whole one.
Effects: fail.
spawnOptions
function spawnOptions(): SpawnOptionsThe default options of System.spawn: inherited standard streams and environment, no handed descriptors.
direntKind
function direntKind(mode: i64): i64The kind of a Stat's mode, as a DIRENT value.
Effects: fail.
Methods
System.temporaryDir
function System.temporaryDir(self: System): Dir throws IoErrorA private fresh directory under $TMPDIR (else /tmp), recursively removed on close or task termination.
Effects: fail, io.
Dir.temporaryPath
function Dir.temporaryPath(self: Dir): string throws IoErrorA new path in this directory that no file has, for a temporary file that the caller makes.
Effects: fail, io.
System.exit
function System.exit(self: System, code: i64): bool throws IoErrorEnd the process without printing main's result. Codes are 0..255.
Effects: fail, io.
IoError.message
function IoError.message(self: IoError): stringThe text of the error, as the operating system describes its code.
Effects: fail, io.
System.time
function System.time(self: System): i64The working directory. Milliseconds since 1970-01-01 UTC by the system clock (gizlang:time reads them).
Effects: fail, io.
System.availableMemory
function System.availableMemory(self: System): i64 throws IoErrorThe bytes the host can still give this process before it runs out: the machine's available memory, and on Linux the room left in the process's cgroup and its ancestors (the allocator's own measure, Memory.roomBytes). This observation is not a reservation. NOT_SUPPORTED where the OS does not tell.
Effects: fail, read.
System.processUsage
function System.processUsage(self: System): ProcessUsage throws IoErrorThe process's resident memory, its peak, its CPU time and the bytes it read from and wrote to storage, on every OS.
Effects: fail, io.
System.usage
function System.usage(self: System): Usage throws IoErrorprocessUsage, and on Linux the totals of the process's cgroup. Cgroup totals include every process in the cgroup; they are not allocator credit or a per-process reservation.
Effects: fail, io.
System.memoryOf
function System.memoryOf(self: System, pid: i64): ProcessMemory throws IoErrorThe resident and peak memory of the process PID, in bytes.
Effects: fail, io.
System.entropy
function System.entropy(self: System): u6464 unpredictable bits from the operating system, to seed gizlang:random.
Effects: fail, io.
System.randomBytes
function System.randomBytes(self: System, n: i64): bytes throws IoErrorSecure bytes directly from the OS; zero is empty, negative lengths are EINVAL.
Effects: fail, io.
System.randomBelow
function System.randomBelow(self: System, below: i64): i64 throws IoError requires below> 0 { const first = try self.randomBytes(RANDOM_WORD_BYTES)Secure uniform integer in [below), with a fresh OS draw on each rejection.
Effects: fail, io.
System.files
function System.files(self: System): Dir throws IoErrorThe working directory.
Effects: fail, io.
System.currentDirectory
function System.currentDirectory(self: System): string throws IoErrorPhysical process working directory; never trust the mutable PWD environment. OS namespace confinement applies to the existing realpath primitive.
Effects: fail, io.
System.absolute
function System.absolute(self: System, path: string): string throws IoErrorpath unchanged when it is absolute, else read against currentDirectory.
Effects: fail, io.
System.copyFile
function System.copyFile(self: System, from: string, to: string): i64 throws IoErrorA bounded file copy, published through the same durable staging owner.
Effects: fail, read, write, console, io.
System.copyTree
function System.copyTree(self: System, from: string, to: string): bool throws IoErrorCopy an entry without following links; publish the completed tree once.
Effects: fail, read, write, console, io.
System.rename
function System.rename(self: System, from: string, to: string): bool throws IoErrorRename between independently confined parent grants. EXDEV is explicit; callers may copy regular files, but directory publication stays atomic.
Effects: fail, io.
System.move
function System.move(self: System, from: string, to: string): bool throws IoErrorCross-device moves copy beside TO, rename the copy into place, and remove the source after that publication: a reader of TO sees all of it or nothing. A copy straight into TO let another process read half of a shared cache entry when the build folder was on another file system.
Effects: fail, read, write, console, io.
System.touch
function System.touch(self: System, path: string): bool throws IoErrorDir.touch at PATH.
Effects: fail, io.
System.readFile
function System.readFile(self: System, path: string): bytes throws IoErrorThe path forms of Dir.readFile, Dir.readBounded, Dir.replaceFile, Dir.appendFile and Dir.info: the
entry's directory is opened, used once and closed. One owner, so callers keep no
directory(dirname) wrappers of their own.
Effects: fail, io.
System.readBounded
function System.readBounded(self: System, path: string, limit: i64): bytes throws IoErrorThe contents of the file PATH, failing when it is larger than LIMIT bytes.
Effects: fail, io.
System.replaceFile
function System.replaceFile(self: System, path: string, data: bytes): i64 throws IoErrorAtomic: a reader sees the old file or the new one, never part of it.
Effects: fail, read, write, console, io.
System.appendFile
function System.appendFile(self: System, path: string, data: bytes): i64 throws IoErrorAppends DATA to the file PATH, made when it is missing; the number of bytes written.
Effects: fail, io.
System.info
function System.info(self: System, path: string): FileInfo throws IoErrorThe size, modification time, kind and mode of PATH.
Effects: fail, io.
System.exists
function System.exists(self: System, path: string): boolWhether PATH exists (info finds it).
Effects: fail, io.
System.realPath
function System.realPath(self: System, path: string): string throws IoErrorResolve a path through the process namespace under the caller's System authority.
Effects: fail, io.
System.makeDirectories
function System.makeDirectories(self: System, path: string): bool throws IoErrorCreate parents using physical path traversal, without lexical dot reduction.
Effects: fail, io.
System.removeTree
function System.removeTree(self: System, path: string): bool throws IoErrorRemove one caller-selected tree. Child links are removed, never traversed.
Effects: fail, io.
System.directory
function System.directory(self: System, path: string): Dir throws IoErrorA directory the program is given, relative to the working directory or absolute (a path from the command line): everything opened through it stays below it.
Effects: fail, io.
System.executable
function System.executable(self: System): string throws IoErrorThis process's executable path from the OS, independent of argv[0] and environment. The same path/encoding bounds apply as for realPath.
Effects: fail, io.
System.arguments
function System.arguments(self: System): Vec<string>The command-line arguments after the program name.
Effects: fail, io.
System.environment
function System.environment(self: System, name: string): Option<string>The value of the environment variable NAME, or none when it is not set.
Effects: fail, io.
System.environmentVariables
function System.environmentVariables(self: System): Vec<EnvironmentVariable>Every environment variable of this process, in the OS's order.
Effects: fail, io.
System.importDescriptor
function System.importDescriptor(self: System, descriptor: i64, mode: i64): Stream throws IoErrorDuplicate a descriptor returned by a native OS ABI into task-owned I/O. The original remains caller-owned. Only READ/WRITE modes are accepted; positionless devices/pipes use read/write, not readAt/writeAt.
Effects: fail, io.
Stream.duplicate
function Stream.duplicate(self: Stream, mode: i64): Stream throws IoErrorDuplicate a file/native-descriptor stream with independently owned I/O. READ/WRITE permissions may only narrow. The logical file cursor is copied; the OS open-file description (including flock ownership) remains shared. TCP, TLS and in-process streams do not expose descriptor duplication.
Effects: fail, io.
Stream.release
function Stream.release(self: Stream): i64 throws IoErrorThe connection as a descriptor of its own, for another thread of this process to take (System.adopt), and the stream closed. A stream a Ready set holds, with TLS, or with bytes it read ahead is refused (EBUSY).
Effects: fail, io.
System.adopt
function System.adopt(self: System, descriptor: i64): Stream throws IoErrorThe connected TCP socket at DESCRIPTOR (Stream.release on another thread of this process) as this thread's stream, which a Ready set can watch. On an error the descriptor is closed.
Effects: fail, io.
System.streamPair
function System.streamPair(self: System): StreamPair throws IoErrorTwo connected streams: what one writes, the other reads.
Effects: fail, io.
System.socket
function System.socket(self: System): Stream throws IoErrorAllocate an unconnected TCP stream in the current task. A deadline child may connect/use it while this owner retains the handle and closes on uncertainty.
Effects: fail, io.
Stream.connect
function Stream.connect(self: Stream, host: string, port: i64): bool throws IoErrorConnects this stream to HOST and PORT.
Effects: fail, io.
System.connect
function System.connect(self: System, host: string, port: i64): Stream throws IoErrorA TCP connection to HOST and PORT.
Effects: fail, io.
System.connectUnix
function System.connectUnix(self: System, path: string): Stream throws IoErrorA connection to the unix-domain socket at path (at most 107 bytes): a
local server such as a database, and an isolated process's way to one
placed in its folder.
Effects: fail, io.
System.addresses
function System.addresses(self: System, host: string): Vec<string> throws IoErrorThe IPv4 and IPv6 addresses of host: an address as it is (IPv4 in
dotted decimal without leading zeros, IPv6 with or without brackets), else
the addresses /etc/hosts lists for it, else the A and AAAA answers of the first name server in /etc/resolv.conf to
answer within RESOLVE_MS, asking the name as written (no search domains).
A program that must know where it connects, as a server fetching URLs it is
given, checks these (publicAddress) and connects to one of them, so no
second lookup can answer differently. UNKNOWN_HOST when no address is found.
Effects: fail, io.
System.texts
function System.texts(self: System, host: string): Vec<string> throws IoErrorThe TXT records of host (the strings of each one joined), from the first name server in /etc/resolv.conf that has
any within RESOLVE_MS, asking the name as written. A domain's owner proves control with one (a verification token,
an ACME DNS-01 challenge). UNKNOWN_HOST when there is none.
Effects: fail, io.
System.textsFrom
function System.textsFrom(self: System, server: string, port: i64, host: string): Vec<string> throws IoErrorThe TXT records of host as the name server at server (an address) and port answers them within RESOLVE_MS:
a domain's own (authoritative) server, which no cache holds back. UNKNOWN_HOST when there is none.
Effects: fail, io.
System.listen
function System.listen(self: System, host: string, port: i64): Listener throws IoErrorListen for TCP connections; port 0 picks a free port (Listener.port).
Effects: fail, io.
System.listenUnix
function System.listenUnix(self: System, path: string): Listener throws IoErrorListen at the unix-domain socket path (at most 107 bytes; nothing may be
there yet; closing the listener removes it). Its connections are Streams
as TCP ones are; port() is 0.
Effects: fail, io.
System.listenShared
function System.listenShared(self: System, host: string, port: i64): Listener throws IoErrorListen on a port other listeners share: each Task.thread (or worker
process) of a server listens on it and the kernel spreads connections among
them (SO_REUSEPORT). Every listener on the port must be shared, and a second
program run by the same user could share it too, so plain listen is the
default: binding a port in use is an error there.
Effects: fail, io.
System.bind
function System.bind(self: System, host: string, port: i64): Socket throws IoErrorA UDP socket on a local address; port 0 picks a free port (Socket.port).
Effects: fail, io.
Dir.open
function Dir.open(self: Dir, path: string, mode: i64): Stream throws IoErrorA file below this directory; paths are relative and never leave it.
Effects: fail, io.
Dir.readFile
function Dir.readFile(self: Dir, path: string): bytes throws IoErrorThe whole file. Up to its size is read at once, then anything past it (a file of /proc or /sys tells a size that is not its length: /sys/devices/system/cpu/possible is 4,096 bytes for 5). readAll's 64 KiB reads were copied again at each doubling of its buffer, a fifth of the reads of a 10M-row COPY's commit (2026-10-17).
Effects: fail, io.
Dir.readBounded
function Dir.readBounded(self: Dir, path: string, limit: i64): bytes throws IoErrorRead a regular file through one confined handle, admitting its size before allocating. Negative limits and files above the limit are INVALID_ARGUMENT; shrinkage or growth during the read is IO_FAILURE. Every outcome closes the opened handle. A same-size concurrent rewrite requires a caller's digest.
Effects: fail, io.
Dir.writeFile
function Dir.writeFile(self: Dir, path: string, data: bytes): i64 throws IoErrorWrites DATA as the whole file PATH (made or truncated); the number of bytes written.
Effects: fail, io.
Dir.appendFile
function Dir.appendFile(self: Dir, path: string, data: bytes): i64 throws IoErrorPOSIX O_APPEND interoperates with other writers without cooperative locks.
Effects: fail, io.
Dir.copyFileTo
function Dir.copyFileTo(self: Dir, from: string, target: Dir, to: string): i64 throws IoErrorCopies the file FROM of this directory to TO in TARGET, with its mode; the number of bytes copied.
Effects: fail, read, write, console, io.
Dir.cloneFile
function Dir.cloneFile(self: Dir, from: string, target: Dir, to: string, immutable: bool): FileClone throws IoErrorCreate an exclusive, durable clone with no byte-copy fallback. A hard link is permitted only when immutable is true: neither namespace may write or truncate that inode for its entire lifetime. Atomic replacement and unlink are permitted. Mutable files require CoW. Hard-link fallback also requires WRITE on the source directory grant.
Effects: fail, io.
Dir.readLink
function Dir.readLink(self: Dir, path: string): string throws IoErrorRead the stored link text without resolving it.
Effects: fail, io.
Dir.makeLink
function Dir.makeLink(self: Dir, path: string, target: string): bool throws IoErrorStore link text; confined operations never follow the newly created link.
Effects: fail, io.
Dir.attribute
function Dir.attribute(self: Dir, path: string, name: string): string throws IoErrorThe extended attribute name (a "user." one) of the entry at path, without following a link at its end: "" when
it has none. A value is at most 4096 bytes of UTF-8.
Effects: fail, io.
Dir.setAttribute
function Dir.setAttribute(self: Dir, path: string, name: string, value: string): bool throws IoErrorSet the extended attribute name (a "user." one) of the entry at path to value; "" removes it.
Effects: fail, io.
Dir.watch
function Dir.watch(self: Dir, path: string): Watch throws IoErrorWatch folder path below this one ("" is this one): its entries made, removed, moved, written, or given other
attributes, and the folder itself removed or moved. Other systems refuse (not supported).
Effects: fail, io.
Watch.add
function Watch.add(self: Watch, dir: Dir, path: string): i64 throws IoErrorWatch folder path below dir ("" is dir) on this watch as well, with the same events: its watch number, which
the events name (the folder Dir.watch named is 1). A folder watched already keeps its number.
Effects: fail, io.
Watch.events
function Watch.events(self: mut Watch): Vec<WatchEvent> throws IoErrorThe changes since the last call, in order, waiting for at least one. Each wait is limited by Stream.timeout on
stream.
Effects: fail, io.
Watch.next
function Watch.next(self: mut Watch): Vec<string> throws IoErrorThe names of the entries that changed since the last call, each once, waiting for at least one: "" names the folder
itself (removed or moved away), or changes that came faster than they were read (the whole folder may have changed).
Each wait is limited by Stream.timeout on stream.
Effects: fail, io.
Watch.close
function Watch.close(self: Watch): boolStops the watch.
Effects: fail, io.
Dir.makeDir
function Dir.makeDir(self: Dir, path: string): bool throws IoErrorA new directory below this one.
Effects: fail, io.
Dir.makeDirectories
function Dir.makeDirectories(self: Dir, path: string): bool throws IoErrorRelative parent creation stays under this capability. Traverse physically through sub grants, never through symlinks or lexical parent reduction. Every created directory is synced itself and in its actual parent; directories that exist are not synced.
Effects: fail, io.
Dir.makeDirectoriesUnsynced
function Dir.makeDirectoriesUnsynced(self: Dir, path: string): bool throws IoErrormakeDirectories with no syncs: for a writer whose owner makes the whole tree durable at once (publishTree).
Effects: fail, io.
Dir.touch
function Dir.touch(self: Dir, path: string): bool throws IoErrorSet an existing entry's times to now, through this directory (it needs write authority). No descriptor holds the entry open for writing, so a program that another process runs at the same time still starts (ETXTBSY).
Effects: fail, io.
Dir.remove
function Dir.remove(self: Dir, path: string): bool throws IoErrorRemove a file or an empty directory.
Effects: fail, io.
Dir.removeTree
function Dir.removeTree(self: Dir, path: string): bool throws IoErrorMissing entries are already removed. Retained cursors close on every failure.
Effects: fail, io.
Dir.entries
function Dir.entries(self: Dir, path: string): DirectoryEntries throws IoErrorA bounded unsorted traversal of entries, excluding dot entries. The retained directory survives closing its parent. Concurrent mutations have OS iterator semantics; a cursor is not a namespace snapshot.
Effects: fail, io.
DirectoryEntries.read
function DirectoryEntries.read(self: DirectoryEntries, limit: i64): Vec<string> throws IoErrorThe next names of the listing, at most LIMIT; empty at the end.
Effects: fail, io.
DirectoryEntries.close
function DirectoryEntries.close(self: DirectoryEntries): boolEnds the listing.
Effects: fail, io.
Dir.list
function Dir.list(self: Dir, path: string): Vec<string> throws IoErrorSorted complete listing; callers needing bounded memory use entries().
Effects: fail, io.
Dir.info
function Dir.info(self: Dir, path: string): FileInfo throws IoErrorInspect the entry itself (including links); "" is this directory.
Effects: fail, io.
Dir.exists
function Dir.exists(self: Dir, path: string): boolWhether PATH exists (info finds it).
Effects: fail, io.
Dir.isDirectory
function Dir.isDirectory(self: Dir, path: string): boolWhether PATH is a directory (a link to one is not: as info).
Effects: fail, io.
Dir.rename
function Dir.rename(self: Dir, from: string, to: string): bool throws IoErrorRenames FROM to TO in this directory, replacing TO.
Effects: fail, io.
Dir.renameTo
function Dir.renameTo(self: Dir, destination: Dir, from: string, to: string): bool throws IoErrorMoves FROM of this directory to TO in DESTINATION, replacing TO.
Effects: fail, io.
Dir.renameToNoReplace
function Dir.renameToNoReplace(self: Dir, destination: Dir, from: string, to: string): bool throws IoErrorAtomically refuse an existing destination, including files, directories and links. Unsupported host filesystems fail rather than race or replace.
Effects: fail, io.
Dir.setMode
function Dir.setMode(self: Dir, path: string, mode: i64): bool throws IoErrorSets the permission bits of PATH to MODE.
Effects: fail, io.
Dir.sub
function Dir.sub(self: Dir, path: string): Dir throws IoErrorDelegate an existing subdirectory; the grant survives closing its parent.
Effects: fail, io.
Dir.walk
function Dir.walk(self: Dir, path: string): Vec<string> throws IoErrorEvery entry below PATH, at any depth, as paths from this directory.
Effects: fail, io.
Dir.replaceFile
function Dir.replaceFile(self: Dir, path: string, data: bytes): i64 throws IoErrorOne staging file in the target's directory: write, fsync, close, rename. A failure after rename is uncertain publication and never rolls the namespace back.
Effects: fail, read, write, console, io.
Dir.publishFile
function Dir.publishFile(self: Dir, path: string, data: bytes): i64 throws IoErrorPublish an immutable file only if its final name is absent. Existing files, directories and links are never overwritten. Uses the same durable staging and no-replace rename owner as publishTree.
Effects: fail, read, write, console, io.
Dir.replaceWith
function Dir.replaceWith(self: Dir, path: string, write: (stream: Stream) => Result<i64, IoError>): i64 throws IoErrorThe single atomic publication owner accepts an admitted streaming writer. The callback owns its bounded buffers; this owner owns staging and durability.
Effects: fail, read, write, console, io.
Dir.publishWith
function Dir.publishWith(self: Dir, path: string, write: (stream: Stream) => Result<i64, IoError>): i64 throws IoErrorThe streaming form of publishFile; the writer owns its bounded buffers.
Effects: fail, read, write, console, io.
Dir.replaceTree
function Dir.replaceTree(self: Dir, source: Dir, from: string, path: string): bool throws IoErrorA tree uses the same rename/sync publication owner as a streamed file. Each directory retains only a cursor page; child links are copied as links.
Effects: fail, read, write, console, io.
Dir.publishTree
function Dir.publishTree(self: Dir, path: string, write: (stage: Dir) => Result<bool, IoError>): bool throws IoErrorAssemble an immutable tree in an exclusively owned sibling stage, then atomically expose it only if path is absent. The writer writes plainly (writeFile, makeDirectoriesUnsynced) and closes its handles; this owner makes the tree durable with one file system sync (syncFilesystem), then syncs the parent. A sync for each file and directory of a 146-file compiler snapshot (replaceFile, makeDirectories) was ~1000 syncs one after another, 0.2 s of each live edit; on a build host its 146 file syncs alone took 0.65 s one after another, 0.24 s 16 at a time and 0.02-0.05 s as one syncfs (2026-10-15). Failure after rename is uncertain publication, never namespace rollback.
Effects: fail, read, write, console, io.
Dir.sync
function Dir.sync(self: Dir): bool throws IoErrorMakes the directory's entries durable: files created, renamed or removed in it survive a crash once this returns. The calling task waits; others run.
Effects: fail, io.
Dir.syncFilesystem
function Dir.syncFilesystem(self: Dir): bool throws IoErrorMakes all data written to the file system that holds this directory durable, with the entries of its directories: one call (syncfs) for many files, not one sync for each. It needs write authority. The calling task waits; others run.
Effects: fail, io.
Dir.close
function Dir.close(self: Dir): boolCloses the directory handle.
Effects: fail, io.
Stream.peer
function Stream.peer(self: Stream): stringThe address of the peer of a connection, as text (empty for a unix socket or a connection that is gone).
Effects: fail, io.
Stream.fixPeer
function Stream.fixPeer(self: Stream, address: string): boolMake address the peer of this connection (Stream.peer), once: false when a PROXY header gave it before.
Effects: fail, io.
Listener.proxyProtocol
function Listener.proxyProtocol(self: Listener, on: bool): voidThe connections of this listener start with a PROXY header (proxyHeader), which Http reads and fixes as the peer. Turn it on only for
a port that nothing but a balancer that always sends the header can reach: a client could write one itself. Call it before a set accepts.
Effects: fail, io.
Ready.proxied
function Ready.proxied(self: Ready): boolWhether the connection came through a PROXY protocol header.
Effects: fail, io.
Stream.read
function Stream.read(self: Stream, limit: i64): bytes throws IoErrorUp to LIMIT bytes from the stream; empty at its end.
Effects: fail, io.
Stream.readReady
function Stream.readReady(self: Stream, limit: i64): bytes throws IoErrorUp to limit bytes that a socket, pipe or POLLED device has now, without waiting: empty bytes when it has none,
and always for a file stream (its reads wait in read).
Effects: fail, io.
Stream.descriptor
function Stream.descriptor(self: Stream): i64The descriptor of a socket stream, -1 for another stream or one of another thread. It stays the stream's while the stream is open; peerClosed takes it on any thread.
Effects: fail, io.
Stream.readAll
function Stream.readAll(self: Stream): bytes throws IoErrorEverything until the end of the stream.
Effects: fail, io.
Stream.readExact
function Stream.readExact(self: Stream, count: i64): bytes throws IoErrorExactly count bytes, consuming no following bytes. Negative count is INVALID_ARGUMENT; premature EOF is IO_FAILURE. Read errors are preserved, partial data is discarded on failure, and the caller retains the stream. Each read asks for all that remains (the runtime bounds one read to 1 MiB), so a large message is a few reads, not one per 64 KiB: each read is a task switch and a copy, and 16 of them took about 2 ms of a storage node's 1 MiB request (2026-10-15). The caller must admit the requested output size.
Effects: fail, io.
Stream.unread
function Stream.unread(self: Stream, data: bytes): i64 throws IoErrorPut bytes back before what the next read returns, as a parser does with the start of a message it cannot finish yet; if the stream ends with nothing after them, reads report the end instead. Not on a TLS stream.
Effects: fail, io.
Stream.write
function Stream.write(self: Stream, data: bytes): i64 throws IoErrorWrite all of data; the number of bytes written.
Effects: fail, io.
Stream.shutdown
function Stream.shutdown(self: Stream): bool throws IoErrorEnds a connection's write side: the peer reads its end, and reads here go on (a TCP FIN; a pipe ends at its close).
Effects: fail, io.
Stream.copyTo
function Stream.copyTo(self: Stream, to: Stream): i64 throws IoErrorChecked bounded copy; neither stream is closed.
Effects: fail, io.
Stream.relay
function Stream.relay(self: Stream, other: Stream): voidCopies bytes both ways between two connections until either side ends, then stops the other way too; neither is closed.
Effects: fail, io.
Stream.setMode
function Stream.setMode(self: Stream, mode: i64): bool throws IoErrorChange permission bits on the held writable inode, before publication.
Effects: fail, io.
Stream.touch
function Stream.touch(self: Stream): bool throws IoErrorSets the modification time of the open file to now.
Effects: fail, io.
Stream.close
function Stream.close(self: Stream): boolCloses the stream.
Effects: fail, io.
Stream.handle
function Stream.handle(self: Stream): i64A number naming this open stream among the open ones, for tables of connections (a closed one's may be reused).
Stream.info
function Stream.info(self: Stream): FileInfo throws IoErrorAn open file's size in bytes and last modification in milliseconds since 1970 UTC; fails on a stream that is not a file.
Effects: fail, io.
Stream.timeout
function Stream.timeout(self: Stream, milliseconds: i64): i64 throws IoErrorLimit how long each read or write of a socket, pipe or POLLED stream may wait, in milliseconds (0, the start, waits forever); a wait past it fails with a timed-out IoError and the stream should be closed.
Effects: fail, io.
Stream.detach
function Stream.detach(self: Stream): i64 throws IoErrorGive a TCP stream to no task, so it outlives the task that owns it (a
client pool keeps an idle connection so); adopt gives it to the calling
task, which closes it when it ends. A stream in a Ready set is refused.
Effects: fail, io.
Stream.adopt
function Stream.adopt(self: Stream): i64 throws IoErrorGives the stream to the calling task, which closes it when it ends. See detach.
Effects: fail, io.
Stream.sync
function Stream.sync(self: Stream): bool throws IoErrorMakes what was written to the file durable (its data and size, as fdatasync): it survives a crash once this returns. The calling task waits; others run.
Effects: fail, io.
Stream.lock
function Stream.lock(self: Stream): bool throws IoErrorTakes the file's exclusive lock without waiting: true when this process now holds it, false when another process does. It lasts while the file is open, however the process ends, so one server owns a data folder at a time.
Effects: fail, io.
Stream.truncate
function Stream.truncate(self: Stream, length: i64): i64 throws IoErrorCuts the file to length bytes, or extends it with zeros.
Effects: fail, io.
Stream.readAt
function Stream.readAt(self: Stream, offset: i64, count: i64): bytes throws IoErrorcount bytes of the file from offset, fewer only at its end (pread). It
neither uses nor moves the position of read and write, and several run at once.
Effects: fail, io.
Stream.readMany
function Stream.readMany(self: Stream, parts: Vec<i64>): bytes throws IoErrorThe bytes of each part of parts (an offset, then a size, for each part), in their order in one value: the reads
of rows that sit apart in a file, in one call. A part past the end of the file is an error. Like readAt, it does
not use or move the position.
Effects: fail, io.
Stream.writeAt
function Stream.writeAt(self: Stream, offset: i64, data: bytes): i64 throws IoErrorWrites all of data at offset of the file (pwrite). It neither uses nor
moves the position of read and write, and several run at once.
Effects: fail, io.
Stream.seek
function Stream.seek(self: Stream, offset: i64): i64 throws IoErrorMove a file's read and write position to offset bytes from its start.
Effects: fail, io.
Ready.accept
function Ready.accept(self: Ready, listener: Listener): i64 throws IoErrorAccept the listener's connections into the set; each is watched.
Effects: fail, io.
Ready.watch
function Ready.watch(self: Ready, stream: Stream): i64 throws IoErrorReport the connection once more when it is ready. Until then the set holds it, not the task: give it back after answering what it sent.
Effects: fail, io.
Ready.channel
function Ready.channel<T>(self: Ready, channel: Task.Channel<T>): StreamA crossing channel in the set, with no socket: watch() the returned stream, and wait() returns it, once per watch, when another thread sent a value (or closed the channel). Drain it with Task.tryReceive, then watch it again. One set watches a channel. Close the stream to remove it.
Ready.wait
function Ready.wait(self: Ready): Stream throws IoErrorThe next ready connection, which now belongs to the calling task (it closes when the task ends); fails once the listener fails or the set is closed. Reading it returns what arrived at once.
Effects: fail, io.
Ready.idle
function Ready.idle(self: Ready): i64How many tasks are waiting in wait() now; 0 after a task took a connection means the next one would wait for a task to finish (add one, if wanted).
Effects: fail, io.
Ready.queued
function Ready.queued(self: Ready): boolWhether a connection is ready now, so wait() returns it at once: a server that answers after one write for all the requests of a pass (a log write) makes that write when none is.
Effects: fail, io.
Ready.time
function Ready.time(self: Ready): i64The wall clock (milliseconds since 1970 UTC) for a set that serves a listener or connections of a System, else 0: the Date of gizlang:http's responses.
Effects: fail, io.
Ready.close
function Ready.close(self: Ready): boolClose the set and the connections waiting in it.
Effects: fail, io.
System.signals
function System.signals(self: System, ids: Vec<i64>): Signals throws IoErrorThe signals in ids (TERM, INT, HUP, QUIT, USR1, USR2) as a stream a task
reads with next(), not as handlers: a program that subscribes to TERM no
longer ends on it, and ends when it decides to (after a checkpoint, for
example). A signal that comes while no task reads is kept for the next
read; the same signal sent twice before a read can arrive once, as the
kernel keeps one pending. The subscription closes when the task that opened
it ends.
Effects: fail, io.
Signals.next
function Signals.next(self: Signals): i64 throws IoErrorThe next signal not read yet (TERM, ...); it waits for one. Signals that wait together come in the order of their numbers.
Effects: fail, io.
Signals.close
function Signals.close(self: Signals): boolStop the subscription; a task waiting in next() gets an error.
Effects: fail, io.
Listener.port
function Listener.port(self: Listener): i64The port that the listener is bound to.
Effects: fail, io.
Listener.backlog
function Listener.backlog(self: Listener, capacity: i64): bool throws IoErrorSet the pending connection bound (1..2147483647). The kernel may clamp it to its system maximum. Existing connections and listener authority remain.
Effects: fail, io.
Listener.accept
function Listener.accept(self: Listener): Stream throws IoErrorWaits for the next connection and gives it.
Effects: fail, io.
Listener.close
function Listener.close(self: Listener): boolCloses the listener. Connections that it accepted stay open.
Effects: fail, io.
Socket.port
function Socket.port(self: Socket): i64The local port that the socket is bound to.
Effects: fail, io.
Socket.send
function Socket.send(self: Socket, host: string, port: i64, data: bytes): i64 throws IoErrorSend data as one datagram; the number of bytes sent. Delivery is not confirmed.
Effects: fail, io.
Socket.receive
function Socket.receive(self: Socket, limit: i64): Datagram throws IoErrorThe next datagram, waiting for one; at most limit bytes of it.
Effects: fail, io.
Socket.close
function Socket.close(self: Socket): boolCloses the socket.
Effects: fail, io.
ExitStatus.exitCode
function ExitStatus.exitCode(self: ExitStatus): i64The status as one exit code, as a shell gives it: the code, or 128 + N for signal N.
Effects: fail.
Output.ran
function Output.ran(self: Output): RanThe output as text.
Effects: fail.
System.stdin
function System.stdin(self: System): Stream throws IoErrorThe standard input of this process.
Effects: fail, io.
System.stdout
function System.stdout(self: System): Stream throws IoErrorThe standard output of this process.
Effects: fail, io.
System.stderr
function System.stderr(self: System): Stream throws IoErrorThe standard error of this process.
Effects: fail, io.
System.printError
function System.printError(self: System, line: string): voidLINE and a newline on standard error: diagnostics, kept apart from the output of the program.
Effects: fail, io.
System.handed
function System.handed(self: System, index: i64): Listener throws IoErrorThe listener the parent handed this process at INDEX (its SpawnOptions.handed), taken once: still bound to the parent's address and network.
Effects: fail, io.
System.spawn
function System.spawn(self: System, program: string, args: Vec<string>, options: SpawnOptions): Child throws IoErrorStarts PROGRAM with ARGS and OPTIONS. The child runs until it ends; Child.wait gives its status.
Effects: fail, io.
System.exec
function System.exec(self: System, program: string, args: Vec<string>, environment: Vec<string>): IoErrorThis process becomes PROGRAM (found on PATH, as spawn finds it) with ARGS and this environment plus ENVIRONMENT (NAME=VALUE; the last of a name wins): its PID, signals, handed listeners and exit status are then the program's own. Use it when nothing is left to do after the program, so that killing this process stops the program (a spawned child that is waited on outlives a killed parent). It returns only on a failure.
Effects: fail, io.
Child.stdin
function Child.stdin(self: Child): Option<Stream>The pipe to the standard input of the child, when the options asked for a pipe.
Effects: fail, io.
Child.stdout
function Child.stdout(self: Child): Option<Stream>The pipe from the standard output of the child, when the options asked for a pipe.
Effects: fail, io.
Child.stderr
function Child.stderr(self: Child): Option<Stream>The pipe from the standard error of the child, when the options asked for a pipe.
Effects: fail, io.
Child.pid
function Child.pid(self: Child): i64The process id of the child.
Effects: fail, io.
Child.wait
function Child.wait(self: Child): ExitStatus throws IoErrorWaits until the child ends; its exit code or the signal that stopped it.
Effects: fail, io.
System.kill
function System.kill(self: System, pid: i64, signal: i64): bool throws IoErrorSends SIGNAL to the process PID, any this user may signal (Child.kill signals a child by its handle). Signal 0 checks only that the process exists.
Effects: fail, io.
Child.kill
function Child.kill(self: Child, signal: i64): bool throws IoErrorSends SIGNAL to the child.
Effects: fail, io.
Child.close
function Child.close(self: Child): boolClosing a running child terminates and reaps it, like task cleanup.
Effects: fail, io.
System.run
function System.run(self: System, program: string, args: Vec<string>): Output throws IoErrorDrain both pipes concurrently before waiting: neither child's output buffer can keep it from exiting. Captured bytes are grown in place by readAll.
Effects: fail, read, write, io.
System.runWith
function System.runWith(self: System, program: string, args: Vec<string>, options: SpawnOptions, input: Option<bytes>): Output throws IoErrorThe same with options' working directory and environment, and input
(when given) written to standard input, which is then closed. Its streams
are always captured, whatever options say.
Effects: fail, read, write, io.
System.ranBounded
function System.ranBounded(self: System, program: string, args: Vec<string>, options: SpawnOptions, input: Option<bytes>, budget: CaptureBudget): RanrunBounded as text (Output.ran): a program that cannot start or ends past the budget gives code 127 and the reason.
Effects: fail, read, write, io.
System.runBounded
function System.runBounded(self: System, program: string, args: Vec<string>, options: SpawnOptions, input: Option<bytes>, budget: CaptureBudget): Result<CapturedOutput, IoError>Runs a child with a hard wall-clock deadline and one combined byte cap for stdout and stderr. No shell or retry is introduced. Timeouts return TIMED_OUT; reaching the byte cap kills/reaps the child and returns the bounded output with outputLimit=true. Child/task teardown removes its cgroup and descendants.
Effects: fail, read, write, io.
System.runStreams
function System.runStreams(self: System, program: string, args: Vec<string>, options: SpawnOptions, input: bytes, milliseconds: i64, outputBytes: i64): Result<CapturedOutput, IoError>Runs PROGRAM to its end with OPTIONS' streams as they are, as Node's spawnSync does: a pipe is captured (stdin a pipe gets INPUT, or nothing, then closes), any other stream is the child's own. At most MILLISECONDS (0: no limit; then TIMED_OUT) and OUTPUTBYTES captured (-1: no cap; past it the child is killed and outputLimit is set).
Effects: fail, read, write, io.
System.stat
function System.stat(self: System, path: string, follow: bool): Stat throws IoErrorstat(2) or, when FOLLOW is false, lstat(2).
Effects: fail, io.
System.statFd
function System.statFd(self: System, fd: i64): Stat throws IoErrorfstat(2).
Effects: fail, io.
System.statFs
function System.statFs(self: System, path: string): StatFs throws IoErrorstatfs(2).
Effects: fail, io.
System.openFd
function System.openFd(self: System, path: string, flags: i64, mode: i64): i64 throws IoErroropen(2) with Linux's flags (O_RDONLY, O_CREAT, ...; O_CLOEXEC is added; the runtime maps them on macOS), giving the descriptor.
Effects: fail, io.
System.closeFd
function System.closeFd(self: System, fd: i64): bool throws IoErrorCloses the file descriptor FD (close).
Effects: fail, io.
System.readFd
function System.readFd(self: System, fd: i64, count: i64, position: i64): bytes throws IoError requires count> = 0 { let out: bytes = filled(count, 0u)Up to COUNT bytes from FD, at POSITION (pread) or, when it is negative, at the descriptor's own offset. Empty at the end.
Effects: fail, io.
System.writeFd
function System.writeFd(self: System, fd: i64, data: bytes, position: i64): i64 throws IoErrorDATA to FD at POSITION (pwrite) or, when it is negative, at the descriptor's own offset; the bytes taken.
Effects: fail, io.
System.syncFd
function System.syncFd(self: System, fd: i64, dataOnly: bool): bool throws IoErrorFlushes FD to its device: its data only (fdatasync) when DATAONLY, else data and metadata (fsync).
Effects: fail, io.
System.truncateFd
function System.truncateFd(self: System, fd: i64, length: i64): bool throws IoErrorSets the length of the file of FD (ftruncate).
Effects: fail, io.
System.access
function System.access(self: System, path: string, mode: i64): bool throws IoErrorWhether the process may access PATH in MODE (access).
Effects: fail, io.
System.processId
function System.processId(self: System): i64This process's id (getpid).
System.parentProcessId
function System.parentProcessId(self: System): i64The id of the process that started this one.
Effects: io.
System.pageSize
function System.pageSize(self: System): i64The size of a memory page in bytes (getpagesize).
System.mapShared
function System.mapShared(self: System, fd: i64, offset: i64, length: i64, writable: bool = false, alignment: i64 = 1): u64 throws IoErrorLENGTH bytes of the descriptor FD from OFFSET, mapped shared and read-only (writable when WRITABLE), at an address that is a multiple of ALIGNMENT (a power of two; 1 for any): their address, which Native.read reads. Unmap it with unmap.
Effects: fail, io.
System.unmap
function System.unmap(self: System, address: u64, length: i64): bool throws IoErrorUnmaps LENGTH bytes at ADDRESS (munmap).
Effects: fail, io.
System.ring
function System.ring(self: System, entries: i64): Ring throws IoErrorA ring of ENTRIES submissions (1 to 32768).
Effects: fail, io.
Ring.command
function Ring.command(self: Ring, fd: i64, op: u64, userData: i64, w0: u64, w1: u64, w2: u64, w3: u64): boolQueues command OP on the descriptor FD with USER_DATA (0 to 2^31 - 1) and 32 bytes of command data, the four little-endian words W0 to W3. False when the ring is full: enter, then queue it again.
Effects: fail, io.
Ring.enter
function Ring.enter(self: Ring, wait: i64): i64 throws IoErrorSubmits the queued commands and waits until WAIT completions are ready (0: no wait): the number submitted. An interrupted wait fails with EINTR; call it again.
Effects: fail, io.
Ring.next
function Ring.next(self: Ring): Option<Completion>The oldest completion, consumed, or none when none is ready.
Effects: fail, io.
Ring.close
function Ring.close(self: Ring): voidCloses the ring and its mappings.
Effects: fail, io.
System.unlink
function System.unlink(self: System, path: string): bool throws IoErrorRemoves the file PATH (unlink).
Effects: fail, io.
System.removeDir
function System.removeDir(self: System, path: string): bool throws IoErrorRemoves the empty directory PATH (rmdir).
Effects: fail, io.
System.makeDir
function System.makeDir(self: System, path: string, mode: i64): bool throws IoErrorMakes the directory PATH with MODE (mkdir).
Effects: fail, io.
System.makeTempDir
function System.makeTempDir(self: System, prefix: string): string throws IoErrormkdtemp(3): PREFIX plus six random characters, the directory made; its path.
Effects: fail, io.
System.renamePath
function System.renamePath(self: System, from: string, to: string): bool throws IoErrorRenames FROM to TO, replacing TO (rename).
Effects: fail, io.
System.linkPath
function System.linkPath(self: System, from: string, to: string): bool throws IoErrorMakes TO a hard link of FROM (link).
Effects: fail, io.
System.symlinkPath
function System.symlinkPath(self: System, target: string, path: string): bool throws IoErrorMakes PATH a symbolic link to TARGET (symlink).
Effects: fail, io.
System.readSymlink
function System.readSymlink(self: System, path: string): string throws IoErrorThe target of the symbolic link PATH (readlink).
Effects: fail, io.
System.resolvePath
function System.resolvePath(self: System, path: string): string throws IoErrorrealpath(3): the canonical absolute path of an existing PATH.
Effects: fail, io.
System.changeMode
function System.changeMode(self: System, path: string, mode: i64): bool throws IoErrorSets the permission bits of PATH to MODE (chmod).
Effects: fail, io.
System.changeModeFd
function System.changeModeFd(self: System, fd: i64, mode: i64): bool throws IoErrorSets the permission bits of the file of FD to MODE (fchmod).
Effects: fail, io.
System.changeOwner
function System.changeOwner(self: System, path: string, uid: i64, gid: i64, follow: bool): bool throws IoErrorchown(2), or lchown(2) when FOLLOW is false; -1 leaves an id unchanged.
Effects: fail, io.
System.changeOwnerFd
function System.changeOwnerFd(self: System, fd: i64, uid: i64, gid: i64): bool throws IoErrorSets the owner and group of the file of FD; -1 leaves an id unchanged (fchown).
Effects: fail, io.
System.setTimes
function System.setTimes(self: System, path: string, atimeNs: i64, mtimeNs: i64, follow: bool): bool throws IoErrorutimensat(2): the access and modification times in nanoseconds since 1970 (TIME_OMIT keeps one), on the link itself when FOLLOW is false.
Effects: fail, io.
System.setTimesFd
function System.setTimesFd(self: System, fd: i64, atimeNs: i64, mtimeNs: i64): bool throws IoErrorSets the access and modification times of the file of FD, in nanoseconds since 1970 (futimens).
Effects: fail, io.
System.readDir
function System.readDir(self: System, path: string): Vec<DirEntry> throws IoErrorThe entries of directory PATH (without . and ..), in the order the OS gives them.
Effects: fail, io.
System.copyFd
function System.copyFd(self: System, from: string, to: string, exclusive: bool): bool throws IoErrorA copy of FROM at TO: the bytes, then the mode. With EXCLUSIVE an existing TO is EEXIST.
Effects: fail, io.
System.isTerminal
function System.isTerminal(self: System, fd: i64): boolWhether FD is a terminal.
Effects: fail, io.
System.terminalSize
function System.terminalSize(self: System, fd: i64): TerminalSize throws IoErrorThe columns and rows of the terminal on FD.
Effects: fail, io.
System.terminalState
function System.terminalState(self: System, fd: i64): bytes throws IoErrorThe terminal's current mode (opaque bytes: a termios, or a Windows console mode), to give back to terminalRestore.
Effects: fail, io.
System.terminalRestore
function System.terminalRestore(self: System, fd: i64, state: bytes): bool throws IoErrorGives the terminal on FD back the state that a raw-mode call returned.
Effects: fail, io.
System.terminalRaw
function System.terminalRaw(self: System, fd: i64): bool throws IoErrorRaw mode as libuv sets it: no echo, no canonical lines, no signals, no input translation; output stays cooked.
Effects: fail, io.
System.hostname
function System.hostname(self: System): string throws IoErrorThe host name of this machine.
Effects: fail, io.
System.loadAverage
function System.loadAverage(self: System): Vec<f64>The load averages of the last 1, 5 and 15 minutes; zeros on Windows, which has none.
Effects: fail, io.
System.osInfo
function System.osInfo(self: System): OsInfo throws IoErrorThe name, release, version and machine of the operating system (uname).
Effects: fail, io.
System.uptime
function System.uptime(self: System): f64Seconds since boot; 0 when the OS does not tell.
Effects: fail, io.
System.memoryInfo
function System.memoryInfo(self: System): MemoryInfoThe total and free memory of the machine, in bytes.
Effects: fail, io.
System.cpuInfo
function System.cpuInfo(self: System): Vec<CpuInfo>Each CPU: its model, its MHz and its times in milliseconds (libuv uv_cpu_info, Node's os.cpus).
Effects: fail, io.
System.availableParallelism
function System.availableParallelism(self: System): i64The CPUs this process may run on, as Node reports them (libuv: the affinity mask, then the cgroup quota): TFB clustered.mjs forks one worker per CPU, so the online count forked 32 workers onto a 4-CPU taskset.
Effects: fail, io.
System.interfaces
function System.interfaces(self: System): Vec<Interface> throws IoErrorThe network interfaces with an address, IPv4 and IPv6, each with the MAC of its interface (libuv, as Node's os.networkInterfaces).
Effects: fail, io.
System.userInfo
function System.userInfo(self: System, uid: i64): UserInfo throws IoErrorThe user UID (-1: the effective user): libuv's passwd entry. On Windows only the current user, with uid and gid -1 and no shell.
Effects: fail, io.
System.homeDirectory
function System.homeDirectory(self: System): string throws IoError$HOME, else the user's home folder (libuv: USERPROFILE on Windows, else the passwd entry).
Effects: fail, io.
System.priority
function System.priority(self: System, pid: i64): i64 throws IoErrorThe scheduling priority (nice) of PID (0: this process); libuv maps Windows' priority classes to it.
Effects: fail, io.
System.setPriority
function System.setPriority(self: System, pid: i64, priority: i64): bool throws IoErrorSets the scheduling priority of the process PID (-20 to 19; lower runs first).
Effects: fail, io.
System.credentials
function System.credentials(self: System): CredentialsThe user, group and supplementary group ids that the process runs with.
Effects: fail, io.
System.userId
function System.userId(self: System, name: string, group: bool): i64 throws IoErrorThe numeric user or group id of NAME, or NAME itself when it is a number.
Effects: fail, io.
System.setCredential
function System.setCredential(self: System, which: string, id: i64): bool throws IoErrorsetuid and the like: WHICH is "uid", "euid", "gid" or "egid".
Effects: fail, io.
System.setGroups
function System.setGroups(self: System, ids: Vec<i64>): bool throws IoErrorSets the supplementary groups of the process to IDS (setgroups); it needs the privilege to do so.
Effects: fail, io.
System.initGroups
function System.initGroups(self: System, user: string, group: i64): bool throws IoErrorSets the supplementary groups of the process to those of USER, plus GROUP (initgroups).
Effects: fail, io.
Constants
INVALID_ARGUMENT
const INVALID_ARGUMENT = -22The error code -22: invalid argument.
HUP
const HUP = 1Signal numbers for System.signals, as Linux numbers them (the runtime maps them on other platforms).
INT
const INT = 2The signal SIGINT (2).
QUIT
const QUIT = 3The signal SIGQUIT (3).
USR1
const USR1 = 10The signal SIGUSR1 (10).
USR2
const USR2 = 12The signal SIGUSR2 (12).
TERM
const TERM = 15The signal SIGTERM (15).
WINCH
const WINCH = 28The signal SIGWINCH (28).
READ
const READ = 1Opening modes, combined with |.
WRITE
const WRITE = 2The open flag WRITE (2).
CREATE
const CREATE = 4The open flag CREATE (4).
TRUNCATE
const TRUNCATE = 8The open flag TRUNCATE (8).
APPEND
const APPEND = 16An open modifier, requiring WRITE; every write appends atomically at the OS.
POLLED
const POLLED = 32An importDescriptor modifier: a device that polls (such as /dev/fuse) reads and writes as a stream on the event loop, each read when the device is ready, not by a file-pool thread that blocks in it.
NOT_FOUND
const NOT_FOUND = -2IoError codes a caller tells apart: no such file or directory, a path that is refused (not a regular file, or no permission), a path that would leave the directory or is malformed, a wait past a stream's timeout, and a host name with no address (System.addresses; connect gives it too).
IO_FAILURE
const IO_FAILURE = -5The error code -5: io failure.
OUT_OF_MEMORY
const OUT_OF_MEMORY = -12The error code -12: out of memory.
NO_SPACE
const NO_SPACE = -28The error code -28: no space.
CORRUPT_DATA
const CORRUPT_DATA = -74The error code -74: corrupt data.
STALE_RESOURCE
const STALE_RESOURCE = -116The error code -116: stale resource.
DENIED
const DENIED = -40301The error code -40301: denied.
BAD_PATH
const BAD_PATH = -40302The error code -40302: bad path.
TIMED_OUT
const TIMED_OUT = -110The error code -110: timed out.
CONNECTION_REFUSED
const CONNECTION_REFUSED = -111The error code -111: connection refused (nothing was sent).
UNKNOWN_HOST
const UNKNOWN_HOST = -3008The error code -3008: unknown host.
NOT_SUPPORTED
const NOT_SUPPORTED = -38The error code -38: the operating system does not support the call.
RESOLVE_MS
const RESOLVE_MS = 2000How long System.addresses waits for each name server's answer.
WORKERS
const WORKERS = 16Tasks running turns: serveConnections starts WORKERS and adds one whenever a connection is taken while none waits (a turn waiting on a timer, a file or an upstream holds its task), up to MOST_WORKERS.
MOST_WORKERS
const MOST_WORKERS = 65536The most worker tasks that serveConnections starts.
WATCH_CLOSE_WRITE
const WATCH_CLOSE_WRITE = 8A file open for writing was closed.
WATCH_MOVED_FROM
const WATCH_MOVED_FROM = 64An entry was moved out of the folder.
WATCH_MOVED_TO
const WATCH_MOVED_TO = 128An entry was moved into the folder.
WATCH_CREATE
const WATCH_CREATE = 256An entry was made in the folder.
WATCH_DELETE
const WATCH_DELETE = 512An entry of the folder was removed.
WATCH_DELETE_SELF
const WATCH_DELETE_SELF = 1024The folder itself was removed.
WATCH_MOVE_SELF
const WATCH_MOVE_SELF = 2048The folder itself was moved.
WATCH_OVERFLOW
const WATCH_OVERFLOW = 16384Changes came faster than they were read: some were lost.
WATCH_IGNORED
const WATCH_IGNORED = 32768The folder's watch ended (the folder is gone): its number is free.
WATCH_FOLDER
const WATCH_FOLDER = 1073741824The entry is a folder.
TIME_OMIT
const TIME_OMIT = 1073741822The time value that leaves a time unchanged.
DIRENT_UNKNOWN
const DIRENT_UNKNOWN = 0The directory entry kind: unknown, 0.
DIRENT_FILE
const DIRENT_FILE = 1The directory entry kind: file, 1.
DIRENT_DIR
const DIRENT_DIR = 2The directory entry kind: dir, 2.
DIRENT_LINK
const DIRENT_LINK = 3The directory entry kind: link, 3.
DIRENT_FIFO
const DIRENT_FIFO = 4The directory entry kind: fifo, 4.
DIRENT_SOCKET
const DIRENT_SOCKET = 5The directory entry kind: socket, 5.
DIRENT_CHAR
const DIRENT_CHAR = 6The directory entry kind: char, 6.
DIRENT_BLOCK
const DIRENT_BLOCK = 7The directory entry kind: block, 7.