Skip to reference

std.fs

wolf-std d58f9e1 · toolchain pin verified against wolf 0.2.41 (0261597). Source signatures and documentation; execution support is stated in each module.

All modules · Plain text · Stability tier: core

Module

std.fs — the filesystem, over rows: whole texts and whole BYTES, a file-descriptor tier for the streaming cases, directories, metadata, and pure path arithmetic. Stability tier: core.

Errors are rows, never traps (D30, and API-CONVENTIONS §2's trap rule): a missing file, a refused permission, a host failure and a text that is not UTF-8 are all ORDINARY outcomes a caller handles with else or propagates with ?. Nothing in this module traps, and nothing returns a sentinel. The vocabulary is the builtin tier's, adopted verbatim so that std adds no translation layer — s38's five, and s90's three:

- not_found — the path does not exist (or, on a write, its parent directory does not) - denied — the host refused the operation for permission reasons - io — every other host failure, coarsened to one tag because no caller can act differently on them yet (§12's rule 3) - utf8 — the bytes are not well-formed UTF-8; wolf str is UTF-8 by definition, so a text read that cannot decode is a miss. The BYTE tier below has no utf8 row anywhere, which is its point. - eof — a read reached the end of the file, which is an outcome rather than a failure (the fd tier only) - exists — the path is already there and the operation demanded to create it (create_dir, the exclusive creates create_new, create_new_with_mode and create_private, create_dir_mode, symlink and link) - invalid — DECLARED AND UNREACHABLE FROM TYPED CODE since sc35. It named a List[int] element that is not a byte (outside 0..255) offered to a byte write — the WRITE's spelling of the refusal str_from_utf8 makes on the way in (writing is not decoding, so utf8 would be a lie). The byte writes take List[byte] now, so no typed caller can build the argument that raises it; the tag stays in the vocabulary because §14 says the vocabulary is the toolchain's and an FFI caller's wrong-width list still earns it (wolf-lang#231's own posture, adopted verbatim) - cross_device — declared by fs_rename and never raised by this module: move_file HANDLES it, which is what the fallback below is for - busy — not now, and not the host's fault (sc72, wolf 0.2.35): a lock another open holds (lock), a non-blocking handle that takes no byte now (write_some), the host's EAGAIN either way

**Capability: fs (I13).** Every function here reaches the host filesystem, is tagged fs in the toolchain's sandbox table, and is categorically refused at comptime (D33) — a comptime fn cannot read a file, and the refusal names the reason. s90 widened the surface and did NOT widen the sandbox: the fifteen new builtins carry the same tag and the same categorical refusal. The pure path helpers at the bottom of this module are the exception in both directions: they touch nothing and are comptime-safe.

The three-way split (§8/§9's rule, applied to files). The IMPLEMENTATION owns the builtins this module delegates to — s38's nine (fs_read_text, fs_write_text, fs_open, fs_create, fs_read, fs_write, fs_close, fs_remove, fs_exists) and s90's fifteen (fs_open_mode, fs_read_bytes, fs_write_bytes, fs_read_chunk, fs_write_chunk, fs_read_dir, fs_create_dir, fs_create_dir_all, fs_remove_dir, fs_remove_dir_all, fs_rename, fs_is_file, fs_is_dir, fs_size, fs_modified_ms), s142's fs_fstat, s199's three (fs_seek, fs_tell, fs_read_at — wolf-lang#426, with the standard streams as handles 0, 1 and 2, #424), s248's three (fs_sync, fs_sync_dir, fs_realpath, wolf 0.2.34), and wolf 0.2.35's eight: s253's fs_adopt and s254's seven (fs_access, fs_fstat_record, fs_lock, fs_unlock, fs_mkfifo, fs_set_nonblock, fs_write_some), with open-mode bit 16 (NOFOLLOW, this module's first constants beside LOCK_SHARED and LOCK_EXCLUSIVE), and the calls wolf-std#141 asked for: wolf 0.2.26's fs_copy_chunk ([os.fs.copy]) and wolf 0.2.37's fs_set_mode_fd ([os.fs.mode.fd]), fs_statfs ([os.fs.statfs]) and the nine calls relative to a held directory (fs_open_at, fs_stat_at, fs_lstat_at, fs_remove_at, fs_remove_dir_at, fs_create_dir_at, fs_symlink_at, fs_link_at, fs_read_dir_entries_at, [os.fs.at]), with open-mode bit 32 (DIRECTORY, [os.fs.open.directory]) — so their semantics are part of this module's contract and are documented per function. std owns everything else: the File value, the consuming close, the mode choice behind append_text/open_append, move_file's fast path and its fallback, and the path arithmetic. The LANGUAGE owns nothing here; there is no file syntax.

**Paths are str, forward slashes travel everywhere.** wolf has no Path type at v0 and this module does not invent one: a path is a str the host interprets. Write forward slashes in wolf literals on every platform — windows accepts them at the API, and a backslash in a wolf literal is an ESCAPE ("C:\Users" does not lex, seven times over in the s38 test sweep). The path helpers here therefore split on / only, and say so.

THE WORKAROUNDS ARE GONE, AND WHAT REPLACED THEM IS WORTH NAMING (s90, wolf-lang#51/#52, F-0044 and F-0045 both CLOSED). For seven sprints three of this module's functions were shaped by builtins that did not exist, and their docs said so:

- append_text read the whole file, concatenated in memory and wrote it back, behind an fs_exists check its own doc called a race. It is fs_open_mode(path, 2) + one write + one close now: it touches no existing byte, it asks no question whose answer can change under it, and its utf8 row went with the read that no longer happens. - copy_file and move_file were TEXT operations, so a file holding a lone 0x80 did not survive them. Both are byte operations now, and both lost utf8 for the same reason. - move_file was copy-then-remove as its ONLY path. fs_rename is the fast path now and copy-then-remove is the FALLBACK, reached through the cross_device row the builtin declares for exactly this purpose.

What is still deliberately absent, each a reviewed contract rather than an approximation:

- rename(from, to) as an ATOMIC move — WITHDRAWN, not blocked. The contract asked for atomicity; the language deliberately does not promise it, because POSIX rename(2) replaces a destination atomically and windows MoveFileEx is documented to replace but not to replace atomically. Upstream therefore ships fs_rename claiming only the EFFECT and no fs_rename_atomic at all, per the platform rule (a promise that cannot be kept on a tier-1 target does not get a #[cfg] that keeps it on two out of three). std adopts that reading rather than re-promising it one level up: move_file is the wrapper, it says what it does and does not guarantee, and there is no second name for the same call. The one atomically-promisable primitive the language DOES offer everywhere is fs_open_mode's create-new mode, which nothing in std needed until wolf 0.2.34 gave a save its syncs: sc69 wraps it as create_new (and create_new_with_mode), the first of the atomic save's five calls — create_new, write, sync, move_file (a rename in one directory, atomic on every unix), sync_dir — which sync's doc spells out. The promise is the save's, made of calls that each keep theirs; there is still no rename_atomic. - stem / extension — a pair that has to decide what a dot means (a leading dot, a doubled extension, no dot at all). That was never a filing about the builtin tier; it is a design question this module has not answered, and the earlier citation of F-0044 beside it was wrong. - is_absolute, and join's behaviour on an absolute name — documented on join itself. - io.Read/io.Write traits and buffering — blocked on trait dispatch (F-0004), not on the filesystem. Every write here is unbuffered and every function says so.

What this module CANNOT witness, stated rather than implied (§14's rule for a claim a green rig would otherwise imply): denied needs a permission call, cross_device needs two filesystems, and read_dir's utf8 needs a file name the host holds in bytes no str can carry. None of the three has a portable litmus, so no test here observes them; their meanings are documented on the functions and nothing claims more. move_file's fallback is reached only through cross_device, so the TRIGGER is unwitnessed here even though the fallback's body — copy_file then remove — is two tested functions.

Lanes (re-measured at the sc12 pin, one call at a time). BOTH compiler rungs are executing lanes: the checked tier performs real host operations and the native rung lowers all twenty-four fs builtins over the eu ABI (s90, RT_SYMBOLS 83 -> 94), so every new function here lands with two lanes from its first commit rather than gaining the second one later. The comptime sandbox is the one place these operations are refused (D33). lupin has no fs builtins by design, and the refusal for the s90 names is the generic unknown-name one (`unsupported: fs_read_dir does not resolve, measured) rather than a reasoned decline — but lupin resolves module bodies LAZILY, so the pure path helpers RUN there: tests/fs/path_helpers.lu is a lupin run row at this pin, which is a property of the lane split rather than a leak. The posture is the rig's to record once (CONTRIBUTING.md`, the ledger's fs section) rather than each test's to restate.

Types and traits

File

struct · Source line 199

pub struct File { fd: int, }

An open file: the host descriptor this process may read from or write to, according to how it was opened.

The field is an int because that is what the builtin tier hands out — a small non-negative index into the machine's file table, never a pointer, and never reused after close at this pin. Reading it is legal and occasionally useful in a diagnostic; passing a hand-built File to read or write is not a trap but a miss (io), because a forged descriptor is a checkable condition rather than a contract violation.

Staleness is prevented by the mode system, not by a generation counter. close takes its File by take (X1), so a caller that closes a file and then reads it is rejected statically as a use-after-move — the discipline a generational handle would enforce dynamically, enforced earlier and for free. std.pool's handles need generations because a pool hands out many; a File has exactly one owner.

The value does not record which MODE opened it. Writing to a handle open produced is io, and reading one create produced is io, because the host refuses — not because this struct checked.

Stat

struct · Source line 1191

pub struct Stat { kind: int, size: int, modified_ms: int, }

What one metadata read on an open handle answers: a kind, a size and a modification time.

**A typed value rather than the [kind, size, modified_ms] triple the builtin hands over.** fs_fstat answers a List[int], and a caller reading got[0], got[1], got[2] is a caller who has to remember an ORDER — §14's rule is that when a builtin hands std a positional row whose meaning is the contract, std names the positions in a type. stat.size cannot be confused with stat.modified_ms; got[1] and got[2] can be, and silently.

kind is 0 for a regular file, 1 for a directory, 2 for anything else — a fifo, a socket, a device. It is an int and not an enum because std has no closed-enum vocabulary at this pin and a three-constant enum invented here would be a shape no other module shares; the numbers are the clause's own ([os.fs.fstat]) and the predicates below are what a program actually calls.

size is bytes, fs.size's word in fs.size's units. modified_ms is milliseconds from the Unix epoch, negative before it — fs.modified_ms's word in its units, deliberately, so the handle's answer and the path's compare with no conversion. The unit rides in the field name for exactly the reason it rides in modified_ms's function name, and that doc carries the argument.

Info

struct · Source line 1284

pub struct Info { kind: int, size: int, modified_ms: int, have: int, mode: int, nlink: int, uid: int, gid: int, blocks: int, dev: int, ino: int, rdev: int, atime_s: int, atime_ns: int, mtime_s: int, mtime_ns: int, ctime_s: int, ctime_ns: int, btime_s: int, btime_ns: int, }

The full stat record of one path: what ls -l shows.

[os.fs.stat] (wolf-lang#625, #536). Twenty host words, named. The first three are Stat's, in its units — kind, size in bytes, modified_ms from the Unix epoch — and kind is finer here: 0 regular file, 1 directory, 2 anything the host does not name, 3 symbolic link, 4 fifo, 5 socket, 6 character device, 7 block device.

have says which words the host ANSWERED: bit i for word i of the clause's table (0 kind, 1 size, 2 modified_ms, 3 have, 4 mode, 5 nlink, 6 uid, 7 gid, 8 blocks, 9 dev, 10 ino, 11 rdev, 12–13 atime, 14–15 mtime, 16–17 ctime, 18–19 btime). A word whose bit is clear is 0 and is the host's refusal, by name — windows answers no mode, nlink, owner, blocks, identity or ctime; linux answers a birth time only where the filesystem keeps one. answered(info, word) reads the bit.

mode is the permission bits with set-user-id, set-group-id and sticky (0o7777), the file type being kind. blocks is in 512-byte units. dev and ino are the file's identity: two paths name one file when both agree — compare them, never order them. A time is a timespec: whole seconds from the epoch (negative before it) and nanoseconds in 0..999999999.

**A new type, not a wider Stat**: Stat's three fields are built by literal in programs that already exist, and a wider struct would refuse every one of them.

FileSystem

struct · Source line 1418

pub struct FileSystem { have: int, block_size: int, fragment_size: int, blocks: int, free: int, available: int, files: int, free_files: int, name_max: int, flags: int, type_number: int, id: int, }

The record of a file system, what df and stat -f print: the twelve words statfs answers, named, with have saying which of them the host answered.

[os.fs.statfs] (wolf-std#141). The fields are the clause's words in order: 0 have, bit i set when word i was answered (bit 0 always); 1 block_size, the size the host prefers for a transfer, in bytes; 2 fragment_size, the unit of the next three, in bytes; 3 blocks, 4 free and 5 available, the total, the free, and the free a process that is not privileged may use, in fragments; 6 files and 7 free_files, the file serial numbers, total and free; 8 name_max, the longest name a directory entry may have, in bytes; 9 flags, bit 0 read-only and bit 1 set-id bits ignored, the same two bits on every host; 10 type_number, the host's number for the file system's type (ext4 0xef53, tmpfs 0x1021994); 11 id, the file system's identity. A word the host did not answer is 0 with its have bit clear (has_answer), never a guess. The counts are the host's unsigned words in an int's 64 bits, and bytes are a count times fragment_size: the room a copy needs to find is available * fragment_size.

**Built by statfs or by file_system, never by a literal.** If a later wolf answers a thirteenth word, this struct gains a field, and a literal of it stops compiling (the CHANGELOG would say so). A program that has the words from elsewhere, a test or a replay, calls file_system, which keeps compiling.

Entry

struct · Source line 1584

pub struct Entry { kind: int, name: List[byte], }

One directory entry: its own kind (Info's codes; a link is 3, never what it names; 2 when the host gave none) and its name's bytes.

Time

struct · Source line 2105

pub struct Time { s: int, ns: int, }

One time set_times writes: a moment, "now", or "leave it".

[os.fs.times]. s is whole seconds from the Unix epoch (negative before it) and ns nanoseconds in 0..999999999 — Info's mtime_s/mtime_ns, so what stat read can be written back — or ns is one of the clause's two special values, which time_now and time_keep build so that no caller writes the numbers.

Functions and methods

read_text

fn · Source line 222

pub fn read_text(path: str) -> str ! {not_found, denied, io, utf8}

The whole contents of the file at path, decoded as UTF-8.

Rows: not_found when the path does not exist, denied when the host refuses, io for any other host failure, utf8 when the bytes are not well-formed UTF-8 (nothing is returned in that case — this is not a lossy decode). Never traps.

read_bytes is the same read without the decode, and it is what a program reaches for when the file is not text.

Capability fs; refused at comptime (D33). Delegates to fs_read_text, whose whole-file read is not incremental: a file larger than the process wants to hold is the fd tier's business.

fs.write_text("doc-read-text.tmp", "three wolves\n")?
(fs.read_text("doc-read-text.tmp") else "?") == "three wolves\n"
fs.remove("doc-read-text.tmp")?

write_text

fn · Source line 251

pub fn write_text(path: str, text: str) -> () ! IoErrors

Write text to path, replacing whatever was there and creating the file if it does not exist.

Rows: not_found when the path's parent directory does not exist, denied when the host refuses, io for any other host failure. There is no utf8 row in either direction: a wolf str is already well-formed UTF-8, so writing one cannot fail to encode. Never traps.

Not atomic: a failure part-way leaves the file part-written, exactly as the host's write does. A caller who needs all-or-nothing writes to a temporary path and then calls move_file — which is a host rename when both paths share a filesystem, and which promises the EFFECT rather than atomicity (see its doc, and the module header on why the atomic name does not exist).

Capability fs; refused at comptime (D33). Delegates to fs_write_text.

fs.write_text("doc-write-text.tmp", "alpha")?
(fs.read_text("doc-write-text.tmp") else "?") == "alpha"
fs.write_text("doc-write-text.tmp", "beta")?
(fs.read_text("doc-write-text.tmp") else "?") == "beta"
fs.remove("doc-write-text.tmp")?

append_text

fn · Source line 296

pub fn append_text(path: str, text: str) -> () ! IoErrors

Append text to the end of the file at path, creating it when it is absent.

Rows: not_found when the parent directory does not exist, denied when the host refuses, io for any other host failure. Never traps.

It is an append now, and the three things that used to be true about it are not. Until s90 there was no append-mode open, so this function read the whole file, concatenated in memory and wrote it back — behind an fs_exists check that was a check-then-use race its own doc had to warn about. It opens the file in append mode, writes once and closes:

- it reads NO existing byte, so its cost is in text rather than in the file's size, and a utf8 row is gone with the decode that no longer happens — appending to a file that is not valid UTF-8 is now an ordinary append; - it asks no question whose answer can change before it acts: the create and the open are one host call, so the absent-file case needs no probe; - every write lands at the end of the file AS IT IS AT THE MOMENT OF THE WRITE (the mode's whole point), so two processes appending lines to one log no longer lose one of them.

What it still does not promise: that ONE call is atomic. A single short write to an append handle is what the host makes of it, and nothing in the language claims more.

The handle is closed on every exit, including the error path, by a defer — which is the idiom §12 records for exactly this and the reason a failed write here does not leak a descriptor.

Capability fs; refused at comptime (D33). Delegates to fs_open_mode (mode 2), fs_write and fs_close.

fs.write_text("doc-append.tmp", "one\n")?
fs.append_text("doc-append.tmp", "two\n")?
(fs.read_text("doc-append.tmp") else "?") == "one\ntwo\n"
fs.remove("doc-append.tmp")?

read_bytes

fn · Source line 328

pub fn read_bytes(path: str) -> List[byte] ! IoErrors

The whole contents of the file at path, as bytes — no decode, no utf8 row, nothing refused for being data.

Rows: not_found when the path does not exist, denied when the host refuses, io for any other host failure. Never traps.

This is the read copy_file is built from, and the reason a file holding a lone 0x80 survives this module now. std.bytes is the vocabulary for what comes back; std.bytes.to_str is the way to text when the caller wants to find out whether it IS text.

Capability fs; refused at comptime (D33). Delegates to fs_read_bytes.

var raw = List[byte]()
(mut raw).push(128 as byte)
(mut raw).push(0 as byte)
(mut raw).push(255 as byte)
fs.write_bytes("doc-read-bytes.tmp", raw)?
let back = fs.read_bytes("doc-read-bytes.tmp") else List[byte]()
back.len == 3
back[0] as int == 128
back[2] as int == 255
fs.remove("doc-read-bytes.tmp")?

write_bytes

fn · Source line 371

pub fn write_bytes(path: str, b: List[byte]) -> () ! {not_found, denied, invalid, io}

Write b to path as bytes, replacing whatever was there and creating the file if it does not exist.

Rows: not_found when the path's parent directory does not exist, denied when the host refuses, io for any other host failure, and **invalid — declared and UNREACHABLE from typed code (sc35).** It named an element of b that is not a byte (outside 0..255), which the interim List[int] currency (§11) made spellable; b is a List[byte] now and cannot hold one. Never traps.

The tag is not removed, and that is deliberate: §14 says the row vocabulary is the toolchain's, fs_write_bytes still declares invalid (wolf-lang#231 kept it on purpose — an FFI caller's wrong-width list still earns it), and dropping a tag a caller may have written a handler for is a breaking change this rename is not. The witness moved with the contract: tests/fs/invalid_row.lu is a static E0401 rejection now.

The row was a deliberate departure from §11's encoder rule, which has hex.encode TRAP on an element out of range — and at sc35 both halves of that disagreement are moot, because neither door can be reached. The reasoning is kept because it is still the rule for the next row: a library that traps where the toolchain raises has taken a decision away from its caller.

Not atomic, exactly as write_text is not.

Capability fs; refused at comptime (D33). Delegates to fs_write_bytes.

var raw = List[byte]()
(mut raw).push(119 as byte)
(mut raw).push(0 as byte)
(mut raw).push(102 as byte)
fs.write_bytes("doc-write-bytes.tmp", raw)?
(fs.size("doc-write-bytes.tmp") else 0 - 1) == 3
fs.remove("doc-write-bytes.tmp")?

exists

fn · Source line 397

pub fn exists(path: str) -> bool

Does something exist at path?

Total: no rows, no traps — a path the process cannot even ask about answers false rather than raising, which is what makes this the probe you write before a read_text and never the probe you rely on afterwards: between the two calls the answer can change, and only the row from the operation itself is authoritative (the check-then-use race is the caller's to avoid, not this function's to hide).

Answers true for a directory as well as a file. is_file and is_dir are the two that say WHICH, and they are total for the same reason this one is.

Capability fs; refused at comptime (D33). Delegates to fs_exists.

fs.exists("doc-exists.tmp") == false
fs.write_text("doc-exists.tmp", "x")?
fs.exists("doc-exists.tmp") == true
fs.remove("doc-exists.tmp")?
fs.exists("doc-exists.tmp") == false

is_file

fn · Source line 423

pub fn is_file(path: str) -> bool

Is there a regular FILE at path?

Total: no rows, no traps. A missing path is not a file, a directory is not a file, and a path the process cannot ask about answers false — the same posture exists takes, and for the same reason (a predicate that raised would be a predicate every caller had to wrap).

Like exists, this is a probe and not a lock: the answer can change between this call and the next one, and only the row from the operation itself is authoritative.

Capability fs; refused at comptime (D33). Delegates to fs_is_file.

fs.write_text("doc-is-file.tmp", "x")?
fs.is_file("doc-is-file.tmp") == true
fs.is_dir("doc-is-file.tmp") == false
fs.is_file("doc-is-file-absent.tmp") == false
fs.remove("doc-is-file.tmp")?

is_dir

fn · Source line 441

pub fn is_dir(path: str) -> bool

Is there a DIRECTORY at path?

Total: no rows, no traps — is_file's twin, with the same probe-not-lock caveat.

Capability fs; refused at comptime (D33). Delegates to fs_is_dir.

fs.create_dir("doc-is-dir.tmp")?
fs.is_dir("doc-is-dir.tmp") == true
fs.is_file("doc-is-dir.tmp") == false
fs.is_dir("doc-is-dir-absent.tmp") == false
fs.remove_dir("doc-is-dir.tmp")?

size

fn · Source line 468

pub fn size(path: str) -> int ! IoErrors

The size of the file at path, in BYTES.

Rows: not_found when the path does not exist, denied when the host refuses, io for any other host failure. Never traps.

Bytes are the currency here as they are in std.str (§9): this is the number read_bytes will hand back, and for a text file it is the number read_text's result reports as len. The size of a DIRECTORY is whatever the host says it is and means nothing portable; ask read_dir how many entries there are instead.

A size read is not a lease. The file can grow between this call and the read that follows it, which is why nothing in this module sizes a file in order to read it.

Capability fs; refused at comptime (D33). Delegates to fs_size.

fs.write_text("doc-size.tmp", "héllo")?
(fs.size("doc-size.tmp") else 0 - 1) == 6
(fs.size("doc-size-absent.tmp") else 0 - 1) == 0 - 1
fs.remove("doc-size.tmp")?

modified_ms

fn · Source line 506

pub fn modified_ms(path: str) -> int ! IoErrors

When the file at path was last modified, in MILLISECONDS from the Unix epoch — negative before it.

Rows: not_found when the path does not exist, denied when the host refuses, io for any other host failure, which includes a host that has a file but no modification time for it. Never traps.

The unit is in the name, and that is a departure this doc owes an explanation. §14's rule is that when a builtin hands std a bare int whose UNIT is the whole contract, std names the unit in a TYPE — which is why std.time ships Instant and Duration. Returning a time.Instant here would make std.fs depend on std.time, and a dependency between two std modules is charged per PROGRAM at this pin (two modules that declare a same-named function cannot be linked into one native binary, F-0026), so every program that touched a file would carry the calendar. The unit therefore rides in the name, where it is at least impossible to miss. The scale is deliberately time_unix_ms's, so time.unix_ms() - fs.modified_ms(p)? is an age in milliseconds with no conversion — and the day a Path/Instant pair is worth the dependency, that is the signature change to make.

Resolution is the host's: a filesystem that stores seconds answers multiples of 1000, and nothing here rounds or pretends otherwise.

Capability fs; refused at comptime (D33). Delegates to fs_modified_ms.

fs.write_text("doc-modified.tmp", "x")?
let stamp = fs.modified_ms("doc-modified.tmp") else 0 - 1
stamp > 0
(fs.modified_ms("doc-modified-absent.tmp") else 0 - 1) == 0 - 1
fs.remove("doc-modified.tmp")?

remove

fn · Source line 529

pub fn remove(path: str) -> () ! IoErrors

Remove the file at path.

Rows: not_found when there is nothing to remove — removing an absent file is a MISS, not a silent success, because a caller who wanted "make sure it is gone" can say so with else and a caller who expected a file wants to hear about it. denied when the host refuses, io for any other host failure, which includes asking to remove a DIRECTORY: remove_dir and remove_dir_all are the two that do that, and the tag stays io because the platforms spell the refusal differently and no caller acts differently on them. Never traps.

Capability fs; refused at comptime (D33). Delegates to fs_remove.

fs.write_text("doc-remove.tmp", "x")?
fs.remove("doc-remove.tmp")?
fs.exists("doc-remove.tmp") == false

copy_file

fn · Source line 568

pub fn copy_file(from: str, to: str) -> () ! IoErrors

Copy the BYTES of from to to, replacing to if it exists.

Rows: not_found when from does not exist or to's parent directory does not, denied when the host refuses either half, io for any other host failure. Never traps.

It is a byte copy now, and the row it lost says so. Until s90 it was read_text + write_text, which meant a file holding a lone 0x80 came back refused with utf8 — a copy that works on text and corrupts (or declines) everything else. It is fs_read_bytes + fs_write_bytes, there is no decode anywhere in it, and utf8 is gone from the row because nothing here can raise it.

fs_write_bytes declares invalid for an element that is not a byte. This function cannot raise it: the bytes came out of fs_read_bytes one line earlier and are bytes by construction. The handler below therefore reports io on that arm — the coarsening a caller could not act on differently — rather than widening this signature with a tag no input can reach (§14: a function's row is the union of what its delegates raise, MINUS what it handles itself).

Not atomic, and it reads the whole file into memory: a file larger than the process wants to hold wants the fd tier's read_chunk / write_chunk in a loop. Copying a file onto itself truncates it and is not a supported operation.

Capability fs; refused at comptime (D33).

fs.write_text("doc-copy-src.tmp", "wolves\n")?
fs.copy_file("doc-copy-src.tmp", "doc-copy-dst.tmp")?
(fs.read_text("doc-copy-dst.tmp") else "?") == "wolves\n"
fs.remove("doc-copy-src.tmp")?
fs.remove("doc-copy-dst.tmp")?

move_file

fn · Source line 625

pub fn move_file(from: str, to: str) -> () ! IoErrors

Move the file at from to to.

Rows: not_found when from does not exist or to's parent directory does not, denied when the host refuses, io for any other host failure. Never traps.

The host rename is the fast path and copy-then-remove is the fallback — which is the other way round from every earlier pin, where the copy was the only path. The rename moves the directory entry without reading a byte, so a gigabyte within one filesystem costs the same as an empty file. Two of fs_rename's rows are the fallback's triggers rather than failures, and this function handles both:

- cross_device — from and to are on different filesystems (EXDEV, ERROR_NOT_SAME_DEVICE), which no rename can do anywhere. The fallback is copy_file then remove, and because copy_file is a BYTE copy the fallback is a real fallback and not a text operation wearing a disguise. - exists — the destination is there and this host's rename will not replace it. unix replaces a file and an empty directory; windows refuses a directory outright. The fallback replaces it, so callers see one behaviour on every tier-1 target instead of the platform's.

It is not atomic and it does not claim to be. A host rename is atomic within a filesystem on unix; windows does not promise that, so the LANGUAGE does not promise it (there is no fs_rename_atomic) and neither does this function. On the fallback path it is plainly not atomic: a failure between the copy and the remove leaves both files, which is the same exposure this function has always had and is now the uncommon case rather than the only one.

The fallback's TRIGGER cannot be witnessed portably — a test would need two filesystems — so no test here reaches it, and the module header says so. Its body is copy_file followed by remove, both of which are tested.

Capability fs; refused at comptime (D33). Delegates to fs_rename, and to copy_file + fs_remove on the fallback.

fs.write_text("doc-move-src.tmp", "pack\n")?
fs.move_file("doc-move-src.tmp", "doc-move-dst.tmp")?
fs.exists("doc-move-src.tmp") == false
(fs.read_text("doc-move-dst.tmp") else "?") == "pack\n"
fs.remove("doc-move-dst.tmp")?

read_dir

fn · Source line 681

pub fn read_dir(path: str) -> List[str] ! {not_found, denied, utf8, io}

The entry NAMES directly inside the directory at path, SORTED.

Rows: not_found when the path does not exist, denied when the host refuses, io for any other host failure — which includes asking a regular file for its entries. utf8 when an entry's name is bytes no str can carry: the LISTING fails rather than the entry being dropped, because a read_dir that silently omits a file lies about the directory. Never traps.

Names, not paths. An entry comes back as "today.txt", never as "logs/today.txt" — join it yourself with join, which is the pure helper at the bottom of this module and exists for exactly this. Returning names is the builtin's decision and std does not decorate it: a caller who wants paths says so in one call, and a caller who wants names cannot get them back out of a path without cutting.

Sorted is a promise, and it is the toolchain's. Filesystem order differs per filesystem, so an unsorted listing makes every program written against it machine-dependent and every test of one a coin flip. The order is by the name's bytes, which is str's own relational order ([mem.str.order]) and therefore the order std.sort would put them in. . and .. are not entries and do not appear.

The listing is a snapshot, not a lock: an entry can be gone by the time the caller opens it, which is the same check-then-use caveat exists carries.

Capability fs; refused at comptime (D33). Delegates to fs_read_dir.

fs.create_dir("doc-read-dir.tmp")?
fs.write_text("doc-read-dir.tmp/beta.txt", "b")?
fs.write_text("doc-read-dir.tmp/alpha.txt", "a")?
let names = fs.read_dir("doc-read-dir.tmp") else List[str]()
names.len == 2
names[0] == "alpha.txt"
names[1] == "beta.txt"
fs.remove_dir_all("doc-read-dir.tmp")?

create_dir

fn · Source line 711

pub fn create_dir(path: str) -> () ! {exists, not_found, denied, io}

Create ONE directory at path.

Rows: exists when something is already there — a directory, a file, anything — because this function's contract is that it CREATED the directory, and "it was already here" is a different outcome a caller may well act on. not_found when the parent directory does not exist: this form creates exactly one level. denied when the host refuses, io for any other host failure. Never traps.

create_dir_all is the idempotent form: it creates the parents and an existing directory is not an error there, which is what makes it the one to reach for before a write. Reach for THIS one when the creation is the point — a lock directory, a run whose output must not land on top of an earlier one.

Capability fs; refused at comptime (D33). Delegates to fs_create_dir.

fs.create_dir("doc-create-dir.tmp")?
fs.is_dir("doc-create-dir.tmp") == true
var again = false
fs.create_dir("doc-create-dir.tmp") else |_| { again = true }
again == true
fs.remove_dir("doc-create-dir.tmp")?

create_dir_all

fn · Source line 736

pub fn create_dir_all(path: str) -> () ! {denied, io}

Create the directory at path and every missing parent of it.

Rows: denied when the host refuses, io for any other host failure — which includes a path whose parent is a regular FILE, since no directory can be created under it. Never traps.

**It is idempotent, and that is why it has no exists row**: a directory that is already there is success, because the caller asked for the directory to EXIST rather than for it to be created. There is no not_found either — a missing parent is the thing this function makes.

Capability fs; refused at comptime (D33). Delegates to fs_create_dir_all.

fs.create_dir_all("doc-create-all.tmp/a/b")?
fs.is_dir("doc-create-all.tmp/a/b") == true
fs.create_dir_all("doc-create-all.tmp/a/b")?
fs.remove_dir_all("doc-create-all.tmp")?

remove_dir

fn · Source line 761

pub fn remove_dir(path: str) -> () ! IoErrors

Remove the EMPTY directory at path.

Rows: not_found when there is nothing there, denied when the host refuses, io for any other host failure — which includes a directory that is not empty and a path that is a regular file. The non-empty case is io rather than a tag of its own because the platforms spell the errno differently and a caller's response is the same either way (§12's rule 3: one tag per failure mode a caller can ACT on). Never traps.

remove_dir_all is the recursive form, and it is the one that deletes data a caller did not name.

Capability fs; refused at comptime (D33). Delegates to fs_remove_dir.

fs.create_dir("doc-remove-dir.tmp")?
fs.remove_dir("doc-remove-dir.tmp")?
fs.exists("doc-remove-dir.tmp") == false

remove_dir_all

fn · Source line 789

pub fn remove_dir_all(path: str) -> () ! IoErrors

Remove the directory at path and EVERYTHING inside it.

Rows: not_found when there is nothing there, denied when the host refuses, io for any other host failure. Never traps.

This deletes files the caller did not name, which is the one operation in this module with that property, and it is worth one sentence of ceremony: there is no confirmation, no dry run and no undo, and a path assembled from data is a path that can name somewhere unintended. remove_dir is the form that refuses to delete anything it was not pointed at.

It is not atomic: a failure part-way leaves part of the tree, exactly as the host's walk does.

Capability fs; refused at comptime (D33). Delegates to fs_remove_dir_all.

fs.create_dir_all("doc-remove-all.tmp/a")?
fs.write_text("doc-remove-all.tmp/a/x.txt", "x")?
fs.remove_dir_all("doc-remove-all.tmp")?
fs.exists("doc-remove-all.tmp") == false

open

fn · Source line 816

pub fn open(path: str) -> File ! IoErrors

Open the file at path for READING and return its handle.

Rows: not_found when the path does not exist, denied when the host refuses, io for any other host failure. Never traps.

The handle must be closed with close, which consumes it. create is the write-and-truncate mode, open_append the append mode and create_new the exclusive create-new mode; the builtin tier also has a read-write mode, which std does not wrap yet and which the module header accounts for. defer is the idiom for the close, and errdefer the idiom for a close on the error path only (§12); neither is available inside a doc example, so the example below closes explicitly.

Capability fs; refused at comptime (D33). Delegates to fs_open.

fs.write_text("doc-open.tmp", "abcdef")?
var f = fs.open("doc-open.tmp")?
(fs.read(mut f, 3) else "?") == "abc"
fs.close(take f)?
fs.remove("doc-open.tmp")?

open_append

fn · Source line 850

pub fn open_append(path: str) -> File ! IoErrors

Open the file at path for APPENDING and return its handle, creating the file when it is absent.

Rows: not_found when the parent directory does not exist, denied when the host refuses, io for any other host failure. Never traps.

Every write through this handle lands at the end of the file as it is at the moment of the write, so a second writer cannot be overwritten by this one's stale idea of where the end was. The handle is write-only: reading it is io.

append_text is this function plus one write and one close, and is what a program that appends once should call. Reach for the handle when a program appends repeatedly — a log writer opens once and pays for one open instead of one per line.

The handle must be closed with close, which consumes it.

Capability fs; refused at comptime (D33). Delegates to fs_open_mode (mode 2).

fs.write_text("doc-open-append.tmp", "one\n")?
var f = fs.open_append("doc-open-append.tmp")?
fs.write(mut f, "two\n")?
fs.write(mut f, "three\n")?
fs.close(take f)?
(fs.read_text("doc-open-append.tmp") else "?") == "one\ntwo\nthree\n"
fs.remove("doc-open-append.tmp")?

create

fn · Source line 874

pub fn create(path: str) -> File ! {denied, io}

Create (or truncate) the file at path for WRITING and return its handle.

Rows: denied when the host refuses, io for any other host failure — including a parent directory that does not exist, which the builtin tier does not distinguish here the way write_text does. Never traps.

An existing file is truncated to nothing, which is the operation's point: create is how a program writes a file it means to own. The handle must be closed with close, which consumes it.

Capability fs; refused at comptime (D33). Delegates to fs_create.

var f = fs.create("doc-create.tmp")?
fs.write(mut f, "pack")?
fs.close(take f)?
(fs.read_text("doc-create.tmp") else "?") == "pack"
fs.remove("doc-create.tmp")?

create_new

fn · Source line 912

pub fn create_new(path: str) -> File ! {exists, not_found, denied, io}

Create a NEW file at path, open for reading and writing, and fail if anything is already there: the EXCLUSIVE create, the one atomicity every tier-1 host promises ([os.fs.open]'s mode 4).

Two programs that race to create_new one name: exactly one gets the file, the other exists — what a lock file, a unique temporary name and an atomic save's temporary file need. It never truncates and never follows a name to a file someone else made. The file gets 0o666 less the process's umask, as create does (create_new_with_mode names its bits from the first instant).

Rows: exists when anything is at path (a file, a directory, a link, a dangling one included); not_found when the parent directory is missing; denied when the host refuses; io otherwise. Never traps. Served on every machine, lupin included, and on windows (ruling #97 R3: no third spelling in the toolchain; this is std's).

Capability fs; refused at comptime (D33). Delegates to fs_open_mode (mode 4).

var f = fs.create_new("doc-create-new.tmp")?
fs.write(mut f, "first")?
fs.close(take f)?
var taken = false
var g = fs.create_new("doc-create-new.tmp") else |_| {
    taken = true
    fs.File { fd: 0 - 1 }
}
fs.close(take g) else |_| { }
let text = fs.read_text("doc-create-new.tmp")?
fs.remove("doc-create-new.tmp")?
taken == true && text == "first"

create_new_with_mode

fn · Source line 952

pub fn create_new_with_mode(path: str, mode: int) -> File ! { exists, not_found, denied, invalid, unsupported, io, }

create_new, with the permission bits the file has from its first instant: mode less the process's umask (env.umask), never wider for a moment — an atomic save's temporary file with the target's bits, before it is renamed over the target.

[os.fs.create.mode]'s fs_open_perm with open mode 4. mode is the nine permission bits; the three above them are set afterwards with set_mode, because the hosts disagree about them at a creation.

Rows: invalid when mode is outside 0..=0o777; exists when anything is at path; not_found when the parent directory is missing; denied; unsupported on a host with no permission bits (windows, by name: create_new is the call there); io otherwise. Never traps.

Capability fs; refused at comptime (D33). Delegates to fs_open_perm.

var served = true
var f = fs.create_new_with_mode("doc-create-new-mode.tmp", 0o600) else |_| {
    served = false
    fs.create_new("doc-create-new-mode.tmp")?
}
fs.close(take f)?
let info = fs.stat("doc-create-new-mode.tmp")?
fs.remove("doc-create-new-mode.tmp")?
(served && info.mode == 0o600) || (!served && !fs.answered(info, 4))

read

fn · Source line 994

pub fn read(mut f: File, max: int) -> str ! {eof, io, utf8}

Read up to max bytes from f, decoded as UTF-8, advancing the file's position.

Rows: eof when the file is already at its end — the outcome that ends a read loop, and the reason a reader is written as a loop over this function rather than a test against a length. io when the handle is closed or foreign, or the host failed. utf8 when the bytes read are not well-formed UTF-8, WHICH INCLUDES a chunk boundary that lands inside a code point: a fixed-size read of text is not safe in general. **read_chunk is the honest fix and it exists now** — it hands back the bytes and lets the caller decide where a code point ends, which is a decision only the caller can make when the boundaries are unknown. ASCII text chunks at any size, and a max at or above the file's remaining size always decodes.

mut f because the operation advances the file's POSITION: the bytes a second call sees depend on the first, which is state the value names even though its fd field does not change. max at or below zero reads nothing and answers the empty string.

Never traps. Capability fs; refused at comptime (D33). Delegates to fs_read.

fs.write_text("doc-read.tmp", "wolfwolf")?
var f = fs.open("doc-read.tmp")?
(fs.read(mut f, 4) else "?") == "wolf"
(fs.read(mut f, 4) else "?") == "wolf"
fs.close(take f)?
fs.remove("doc-read.tmp")?

read_chunk

fn · Source line 1028

pub fn read_chunk(mut f: File, max: int) -> List[byte] ! {eof, io}

Read up to max BYTES from f, advancing the file's position — no decode, no utf8 row, no boundary to land inside.

Rows: eof when the file is already at its end, io when the handle is closed, foreign or write-only, or the host failed. Never traps.

This is the streaming read that works on data: read refuses a chunk whose boundary splits a code point, and nothing can choose a safe chunk size for a file whose contents are unknown. A caller that wants text from a stream reads chunks, joins them, and decodes the join with std.bytes.to_str — where the validation happens once, over the whole thing, instead of once per arbitrary boundary.

mut f for the same reason read takes it: the position advances, and the bytes a second call sees depend on the first.

Capability fs; refused at comptime (D33). Delegates to fs_read_chunk.

var w = fs.create("doc-read-chunk.tmp")?
fs.write(mut w, "wolf")?
fs.close(take w)?
var f = fs.open("doc-read-chunk.tmp")?
let head = fs.read_chunk(mut f, 2) else List[byte]()
head.len == 2
head[0] as int == 119
fs.close(take f)?
fs.remove("doc-read-chunk.tmp")?

write

fn · Source line 1056

pub fn write(mut f: File, text: str) -> () ! {io}

Write text to f at its current position, advancing it.

Rows: io when the handle is closed, foreign or read-only, or the host failed. Never traps, and there is no utf8 row: a str is already well-formed UTF-8.

mut f for the same reason read takes it: the position advances. Writes are unbuffered — every call reaches the host — so a program that writes small pieces in a loop pays for each one, and the buffered writer that would fix it waits on trait dispatch (F-0004).

On a handle from open_append the position is the END of the file at the moment of each write, so "current position" means what the mode says rather than what an earlier write left behind.

Capability fs; refused at comptime (D33). Delegates to fs_write.

var f = fs.create("doc-write.tmp")?
fs.write(mut f, "one ")?
fs.write(mut f, "two")?
fs.close(take f)?
(fs.read_text("doc-write.tmp") else "?") == "one two"

write_chunk

fn · Source line 1087

pub fn write_chunk(mut f: File, b: List[byte]) -> () ! {invalid, io}

Write the bytes b to f at its current position, advancing it.

Rows: invalid when an element of b is not a byte (outside 0..255), io when the handle is closed, foreign or read-only, or the host failed. Never traps.

invalid is reachable here where it is not reachable inside copy_file, and the difference is whose bytes they are: a caller builds this list, so a non-byte in it is data this function must report rather than an impossibility it may coarsen. See write_bytes for why the answer is a row and not a trap.

Unbuffered, exactly as write is, and mut f for the same reason.

Capability fs; refused at comptime (D33). Delegates to fs_write_chunk.

var raw = List[byte]()
(mut raw).push(128 as byte)
(mut raw).push(255 as byte)
var f = fs.create("doc-write-chunk.tmp")?
fs.write_chunk(mut f, raw)?
fs.close(take f)?
(fs.size("doc-write-chunk.tmp") else 0 - 1) == 2
fs.remove("doc-write-chunk.tmp")?

copy_chunk

fn · Source line 1136

pub fn copy_chunk(mut src: File, mut dst: File, max: int) -> int ! {eof, io}

One copy the host makes: at most max bytes from src's position to dst's, both advancing, and how many moved. It is read_chunk then write_chunk with the bytes never passing through the program, which is cat's and cp's inner loop.

[os.fs.copy] (wolf-std#141). One call moves at least one byte and at most max (the host clamps a call to 1 GiB). How many it moves is the host's choice: linux tries copy_file_range, sendfile and splice before a read and a write, while macOS, freebsd and windows read and write at most 256 KiB at a time. So a program loops until eof and relies on the total, never on the split. max at or below zero answers 0 without asking the host. The standard streams are handles too (stdin(), stdout()), and a copy to standard output keeps its order with print.

Rows: eof when src is already at its end, an outcome as for read_chunk; io for a closed or forged handle on either side (checked before max), and for a failure of the read or of the write, the host's number in os_error(). After an io a source that can seek stands just past what the sink took (tell(mut src) says where), so a retry starts from the truth; a pipe or a terminal cannot be put back. A caller that must say which side failed retries the read. There is no invalid: no argument can be malformed once the handles are checked. Never traps.

mut src and mut dst: both positions advance. Capability fs; refused at comptime (D33). Delegates to fs_copy_chunk, which every lane serves; the checked machine and lupin move the bytes through a buffer of their own, with the same bytes and offsets.

fs.write_text("doc-copy-chunk-a.tmp", "wolves")?
var src = fs.open("doc-copy-chunk-a.tmp")?
var dst = fs.create("doc-copy-chunk-b.tmp")?
var total = 0
var more = true
while more { total = total + (fs.copy_chunk(mut src, mut dst, 4) else |_| { more = false; 0 }) }
let none = fs.copy_chunk(mut src, mut dst, 0)?
fs.close(take src)?
fs.close(take dst)?
let text = fs.read_text("doc-copy-chunk-b.tmp")?
fs.remove("doc-copy-chunk-a.tmp")?
fs.remove("doc-copy-chunk-b.tmp")?
total == 6 && none == 0 && text == "wolves"

close

fn · Source line 1163

pub fn close(take f: File) -> () ! {io}

Close f, consuming it.

Rows: io when the handle was already closed or is foreign. Never traps.

take is the mode of the operation's meaning (§3: take only where the value is genuinely gone afterwards): closing ends the handle's life, so the caller spells fs.close(take f) and the compiler rejects every later use of f as a use-after-move. That is the whole staleness story for files, and it costs nothing at run time.

A closed descriptor is never reused by the builtin tier at this pin, so a forged or stale File answers io rather than reaching another caller's file. Do not depend on that beyond this pin: the mode system is the guarantee, the table's behaviour is an implementation detail.

Capability fs; refused at comptime (D33). Delegates to fs_close.

var f = fs.create("doc-close.tmp")?
fs.close(take f)?
fs.remove("doc-close.tmp")?

fstat

fn · Source line 1251

pub fn fstat(mut f: File) -> Stat ! IoErrors

One metadata read on the open handle f.

[os.fs.fstat]. This is fs.size and fs.modified_ms and fs.is_dir and fs.is_file, answered together, off the handle a program is about to read anyway — one host call instead of four path resolutions.

The reason is a measurement, not a tidiness. wolf-lang#261: a static-file server was paying four path stats per request (is_dir, is_file, size, modified_ms) where nginx pays one open and one fstat, and the last two could not move into the program because nothing in this module answered off a handle. Now something does, and the four path calls stay exactly where they are for the callers that have a path and no handle.

Rows are the path stat's, so one handler serves both spellings: not_found, denied, io. On a HANDLE the hosts answer io for nearly everything — the entry is already resolved, so the misses the path calls have are behind it — and a closed or forged handle is io, this family's rule. A size or a time outside int is io, fs.size's rule. Never traps.

**The one host difference is fs.open's, and it is stated.** linux, macOS and freebsd open a directory read-only, so a File over a directory exists there and kind 1 is reachable. **Windows refuses to open a directory as a file — fs.open answers denied, not this call** — so on windows every handle this function ever sees is a file or a device, kind 1 never appears, and a server that classifies directories does it BY PATH with fs.is_dir, as it did before this call existed. That is a difference in what can be OPENED, not in what fstat reports, and no row here moves with the host.

mut f because a metadata read is a host call on the handle, and §14's stream rule has the call site spell it. The handle's read position is not disturbed.

Capability fs; refused at comptime (D33). Delegates to fs_fstat (s142) — both compiler lanes. The clause says every tier-1 host on every tier serves it, "the checked machine reads the same handle metadata the runtime does", and lupin still answers unsupported: the REFERENCE machine has no filesystem at all by design, so the whole fs tier is declined there rather than mocked, and that is a posture and not a release date. It is the one place a zero pairing gap buys this module nothing.

fs.write_text("doc-fstat.tmp", "wolves")?
var f = fs.open("doc-fstat.tmp")?
let st = fs.fstat(mut f)?
fs.close(take f)?
fs.remove("doc-fstat.tmp")?
st.kind == 0 && st.size == 6 && st.modified_ms > 0

stat

fn · Source line 1345

pub fn stat(path: str) -> Info ! IoErrors

The record of path, FOLLOWING a final symbolic link: what the link names. A dangling link is not_found.

[os.fs.stat]: one host call (stat). Rows: not_found, denied, io — size's. Never traps. Capability fs; refused at comptime (D33). Delegates to fs_stat.

fs.write_text("doc-stat.tmp", "wolves")?
let info = fs.stat("doc-stat.tmp")?
fs.remove("doc-stat.tmp")?
info.kind == 0 && info.size == 6 && fs.answered(info, 2)

lstat

fn · Source line 1365

pub fn lstat(path: str) -> Info ! IoErrors

The record of path ITSELF, a symbolic link included: a link is kind 3, its size the length of its target, its times its own. On anything that is not a link it is stat's answer.

[os.fs.stat]: one host call (lstat). Rows as stat's; a dangling link answers a record here and not_found there. Capability fs; refused at comptime (D33). Delegates to fs_lstat.

fs.write_text("doc-lstat.tmp", "x")?
let a = fs.lstat("doc-lstat.tmp")?
let b = fs.stat("doc-lstat.tmp")?
fs.remove("doc-lstat.tmp")?
a.kind == b.kind && a.size == b.size

answered

fn · Source line 1379

pub fn answered(info: Info, word: int) -> bool

Whether the host answered word word of info (Info's table); false for a word outside 0..20. Total.

fs.write_text("doc-answered.tmp", "x")?
let info = fs.stat("doc-answered.tmp")?
fs.remove("doc-answered.tmp")?
fs.answered(info, 0) && fs.answered(info, 14) && !fs.answered(info, 20)

file_system

fn · Source line 1445

pub fn file_system(words: List[int]) -> FileSystem

The FileSystem of statfs's words in their order, words[0] being have. A word past the end of words is 0 with its have bit cleared, and a word past the twelfth is ignored. Total.

statfs builds its answer here, and so does a program that has the words from elsewhere. Pure, comptime-safe: it reaches nothing.

let v = fs.file_system([7, 4096, 512])
v.block_size == 4096 && v.fragment_size == 512 && v.blocks == 0
fs.has_answer(v, 2) && !fs.has_answer(v, 3)

has_answer

fn · Source line 1484

pub fn has_answer(v: FileSystem, word: int) -> bool

Whether the host answered word word of v (FileSystem's table); false for a word outside 0..12. Total and pure.

let v = fs.file_system([1, 4096])
fs.has_answer(v, 0) && !fs.has_answer(v, 1) && !fs.has_answer(v, 12)

statfs

fn · Source line 1519

pub fn statfs(path: str) -> FileSystem ! IoErrors

**The record of the file system that holds what path names**, a final symbolic link followed: what df and stat -f print, from one host call (statfs(2); macOS adds a pathconf for name_max).

[os.fs.statfs] (wolf-std#141). Linux answers every word, flags where the kernel marks them valid; macOS answers every word; windows answers blocks, free and available in bytes with fragment_size 1, and none of the rest (has_answer says which). The free counts move under any writer, so two reads may differ; a file's record is its directory's.

Rows: not_found when nothing is at path, denied when the host refuses, io otherwise (a path holding a NUL included), the host's number in os_error(): stat's rows. Never traps.

Capability fs; refused at comptime (D33). Delegates to fs_statfs. lupin 0.1.62 answers a missing path's row and refuses a record by name, since it has no statfs of its own (wolf-interp#315).

let v = fs.statfs(".")?
fs.has_answer(v, 0) && fs.has_answer(v, 5) && v.fragment_size > 0
v.available <= v.free && v.free <= v.blocks

realpath

fn · Source line 1578

pub fn realpath(path: str) -> str ! {io, not_found}

**s248 ([os.fs.realpath]): the canonical name of path** — absolute, every symbolic link followed, every . and .. taken (a .. AFTER the link before it, so l/.. is the parent of the link's TARGET), and no trailing slash: what realpath(3) resolves. A relative path is resolved against the working directory. Two spellings of one file answer one name, which is how an editor keys a workspace by its directory. The answer is the host's: macOS's /tmp is /private/tmp, and windows answers its final name in the \\?\ form.

Rows: not_found for a missing name, a dangling link included, and the empty path; io for a loop of links, a component that is not a directory (on unix; windows says not_found), a refused search, and an answer that is not UTF-8 (read_link is the byte-exact call), the host's number in os_error() where it gave one. Never traps. lupin 0.1.56 canonicalizes inside its served tree and refuses a path outside it by name (0.1.55 did not resolve the call, wolf-interp#268).

Capability fs; refused at comptime (D33). Delegates to fs_realpath.

fs.create_dir_all("doc-realpath.tmp")?
let a = fs.realpath("doc-realpath.tmp/")?
let b = fs.realpath("doc-realpath.tmp/../doc-realpath.tmp")?
var missing = false
let none = fs.realpath("doc-realpath-none.tmp") else |_| {
    missing = true
    ("")
}
fs.remove_dir("doc-realpath.tmp")?
a == b && a != "doc-realpath.tmp" && missing == true && none == ""

entries

fn · Source line 1608

pub fn entries(path: str) -> List[Entry] ! IoErrors

The entries of the directory path in the order the host keeps them — NOT sorted — without . and .., each with its own kind.

[os.fs.readdir] (wolf-lang#626). A name that is not UTF-8 is listed like any other: name is bytes, so this listing has no utf8 row and one odd name cannot fail it (read_dir keeps its sorted str names and its utf8). The order differs between filesystems, so a program that wants one sorts. Rows: not_found, denied, io. Capability fs; refused at comptime (D33). Delegates to fs_read_dir_entries.

fs.create_dir("doc-entries.tmp")?
fs.create_dir("doc-entries.tmp/sub")?
fs.write_text("doc-entries.tmp/f", "x")?
let es = fs.entries("doc-entries.tmp")?
fs.remove_dir_all("doc-entries.tmp")?
es.len == 2 && es[0].kind + es[1].kind == 1

stdin

fn · Source line 1654

pub fn stdin() -> File

The process's standard input, as a File.

[os.fs.std] (wolf-lang#424): the handle numbers 0, 1 and 2 are the three streams the process was started with, and no open ever answers one of them. This is that number in this module's type, so the handle calls below can ask what standard input IS — a regular file (fstat(mut f)?.kind == 0, and then its size), a pipe or a terminal (kind 2) — and, when it is a file, read it at an offset without reading forward to get there.

What it serves: fstat, seek, seek_by, seek_end, tell and read_at (wolf 0.2.22, s199), and, from wolf 0.2.26 (s200, wolf-lang#405), the BYTES: read, read_chunk, write and write_chunk serve 0, 1 and 2 as the descriptors themselves ([os.fs.std]). A read of 0 starts at the offset this process shares with whoever started it and moves it; a pipe, socket or terminal is read as what it is, and eof at its end. A write to 1 or 2 lands in program order with print and std.io's writers, unbuffered by this module. A closed standard stream is io (the host's EBADF), never a silent success. What it does not: close answers io on it, as on any handle no open made — nothing here closes a standard stream, and there is no way to. tests/fs/std_bytes_rows.lu writes 1 between two prints and reads 0 to its end.

Total, and reaches nothing until a call is made on the value. Capability fs for the calls that take it.

The example runs with descriptor 1 a pipe — the rig's — and a pipe has no position, so the seek is refused (unseekable, by name; tests/fs/std_handles.lu asserts the tag):

var o = fs.stdout()
let at = fs.seek(mut o, 0) else 0 - 7
at == 0 - 7

stdout

fn · Source line 1662

pub fn stdout() -> File

The process's standard output, as a File — stdin's doc in every respect, for descriptor 1. write and write_chunk through it put bytes on standard output in program order with print (wolf 0.2.26, [os.fs.std]); std.io.write stays the writer for text.

stderr

fn · Source line 1669

pub fn stderr() -> File

The process's standard error, as a File — stdin's doc in every respect, for descriptor 2. write and write_chunk through it put bytes on standard error; std.io.write_err stays the writer for text.

seek

fn · Source line 1703

pub fn seek(mut f: File, off: int) -> int ! {invalid, io, unseekable}

Move f's position to byte off from the START of the file, and answer it.

[os.fs.seek] (wolf-lang#426), whence 0. Rows: invalid when off is below zero (decided before the host is touched, and the position does not move), unseekable when the handle has no position — a pipe, a fifo, a socket, a terminal — and io for a closed or forged handle or a host failure. A position past the end is legal; a read there is eof. Never traps.

unseekable is its own tag because the response to it is: a program that wanted to skip ahead reads forward instead, as tail does through a pipe. Three functions rather than one with a whence argument, because a bare int whose meaning is the contract is the shape §14 names in a type or a name — seek_end(mut f, 0 - 10) cannot be misread, seek(mut f, 0 - 10, 2) can.

mut f because the position moves.

Capability fs; refused at comptime (D33). Delegates to fs_seek.

fs.write_text("doc-seek.tmp", "0123456789")?
var f = fs.open("doc-seek.tmp")?
(fs.seek(mut f, 6) else 0) == 6
let rest = fs.read_chunk(mut f, 8) else List[byte]()
rest.len == 4
fs.close(take f)?
fs.remove("doc-seek.tmp")?

seek_by

fn · Source line 1725

pub fn seek_by(mut f: File, delta: int) -> int ! {invalid, io, unseekable}

Move f's position by delta bytes from where it is, and answer the new position from the start.

[os.fs.seek], whence 1. Rows as seek's: invalid when the move would land below zero (the position does not move), unseekable, io. Never traps.

Capability fs; refused at comptime (D33). Delegates to fs_seek.

fs.write_text("doc-seek-by.tmp", "0123456789")?
var f = fs.open("doc-seek-by.tmp")?
let head = fs.read_chunk(mut f, 2) else List[byte]()
head.len == 2
(fs.seek_by(mut f, 3) else 0) == 5
fs.close(take f)?
fs.remove("doc-seek-by.tmp")?

seek_end

fn · Source line 1749

pub fn seek_end(mut f: File, off: int) -> int ! {invalid, io, unseekable}

Move f's position to off bytes from the END of the file — zero is the end, negative is before it — and answer it from the start.

[os.fs.seek], whence 2. seek_end(mut f, 0) answers the file's size, the way tail finds where to walk back from. Rows as seek's: invalid when the position would land below zero, unseekable, io. Never traps.

Capability fs; refused at comptime (D33). Delegates to fs_seek.

fs.write_text("doc-seek-end.tmp", "0123456789")?
var f = fs.open("doc-seek-end.tmp")?
(fs.seek_end(mut f, 0) else 0) == 10
(fs.seek_end(mut f, 0 - 3) else 0) == 7
let last = fs.read_chunk(mut f, 8) else List[byte]()
last.len == 3
fs.close(take f)?
fs.remove("doc-seek-end.tmp")?

tell

fn · Source line 1774

pub fn tell(mut f: File) -> int ! {io, unseekable}

f's position, from the start of the file, without moving it.

[os.fs.tell] (wolf-lang#426). A handle fresh from open answers 0; after reads of a and b bytes it answers a + b. Rows: unseekable for a handle with no position, io for a closed or forged handle or a host failure. Never traps.

mut f for the stream rule (§14): the call site spells that the handle is in play, as fstat does.

Capability fs; refused at comptime (D33). Delegates to fs_tell.

fs.write_text("doc-tell.tmp", "wolves")?
var f = fs.open("doc-tell.tmp")?
let head = fs.read_chunk(mut f, 4) else List[byte]()
head.len == 4
(fs.tell(mut f) else 0) == 4
fs.close(take f)?
fs.remove("doc-tell.tmp")?

read_at

fn · Source line 1807

pub fn read_at(mut f: File, off: int, max: int) -> List[byte] ! {eof, invalid, io, unseekable}

Up to max bytes of f starting at byte off, leaving f's own position exactly where it was.

[os.fs.read_at] (wolf-lang#426) — pread. The order is the fd tier's: the handle (closed or forged is io), then the offset (below zero is invalid), then max (at or below zero answers the empty list and touches nothing), the 1 MiB cap read_chunk carries, and no bytes at a positive max is eof — the offset is at or past the end. unseekable for a handle with no position. Never traps.

This is the read for a program that knows where the bytes are: tail -n 10 takes the size from fstat and walks back a block at a time, touching a few kilobytes of a file of any size, where reading forward touched all of it. Because the position does not move, two readers of one File need no seek between them.

Capability fs; refused at comptime (D33). Delegates to fs_read_at.

fs.write_text("doc-read-at.tmp", "0123456789")?
var f = fs.open("doc-read-at.tmp")?
let mid = fs.read_at(mut f, 5, 3) else List[byte]()
mid.len == 3
mid[0] as int == 53
(fs.tell(mut f) else 1) == 0
fs.close(take f)?
fs.remove("doc-read-at.tmp")?

join

fn · Source line 1834

pub fn join(base: str, name: str) -> str

base and name joined with a single /.

Total: no rows, no traps — and pure, so unlike everything above it is comptime-safe and reaches no host. An empty base answers name unchanged; a base that already ends in / does not grow a second one. An absolute name is NOT special-cased: joining "a" with "/b" gives "a//b" rather than silently discarding base, because a path helper that decides to ignore one of its arguments is a helper that hides a bug (the day is_absolute exists, this doc says what it does about it).

This is the function that turns a read_dir NAME into a path, which is the shape every directory walk takes.

Separators are / on every platform (see the module header): windows accepts forward slashes at the API, and a backslash in a wolf literal is an escape.

fs.join("logs", "today.txt") == "logs/today.txt"
fs.join("logs/", "today.txt") == "logs/today.txt"
fs.join("", "today.txt") == "today.txt"

parent

fn · Source line 1859

pub fn parent(path: str) -> str ! {none}

Everything in path before its last /.

Rows: none when there is no / at all (a bare file name has no parent to name) — absence, not an error, so else is the whole handling story. A path whose last / is its first character answers "/", the root, rather than the empty string. Total otherwise: no traps, no host access, comptime-safe.

Byte offsets are the currency (§9) and this function never lands inside a code point: it cuts at a /, which is a one-byte ASCII boundary by construction, and reads the result through the recoverable slice.

(fs.parent("logs/2026/today.txt") else "?") == "logs/2026"
(fs.parent("today.txt") else "?") == "?"
(fs.parent("/etc/hosts") else "?") == "/etc"
(fs.parent("/hosts") else "?") == "/"

file_name

fn · Source line 1884

pub fn file_name(path: str) -> str ! {none}

The last segment of path — everything after its last /.

Rows: none when there is no last segment to name: an empty path, or a path that ends in / (a directory spelling names no file). A path with no / at all IS its own file name. Total otherwise: no traps, no host access, comptime-safe.

This is the base name including any extension; splitting the extension off wants a stem/extension pair, which is a reviewed contract rather than a guess about what a dot means. That contract is blocked on nothing — it is a design decision this module has not taken (see the module header).

(fs.file_name("logs/2026/today.txt") else "?") == "today.txt"
(fs.file_name("today.txt") else "?") == "today.txt"
(fs.file_name("logs/") else "?") == "?"
(fs.file_name("") else "?") == "?"

set_mode

fn · Source line 1918

pub fn set_mode(path: str, mode: int) -> () ! {not_found, denied, invalid, unsupported, io}

Set the permission bits of what is at path to exactly mode.

[os.fs.mode] (wolf-lang#346): chmod. mode is the twelve bits Info.mode reads — the nine permission bits with set-user-id, set-group-id and sticky — written in octal, 0o640; the umask plays no part. A final symbolic link is FOLLOWED: the call changes what the link names, never the link.

Rows: invalid when mode is outside 0..=0o7777, decided before the host is asked; not_found when nothing is at path (a dangling link included); denied when this process does not own the file; unsupported on a host with no permission bits (windows, by name); io otherwise. Never traps.

Capability fs; refused at comptime (D33). Delegates to fs_set_mode.

fs.write_text("doc-set-mode.tmp", "x")?
var row = "ok"
fs.set_mode("doc-set-mode.tmp", 0o600) else |_| { row = "refused" }
let info = fs.stat("doc-set-mode.tmp")?
fs.remove("doc-set-mode.tmp")?
(row == "ok" && info.mode == 0o600) || (row == "refused" && !fs.answered(info, 4))

create_private

fn · Source line 1951

pub fn create_private(path: str) -> File ! {exists, not_found, denied, unsupported, io}

Create a NEW file at path that only its owner can read or write, open for reading and writing.

[os.fs.create.mode] (wolf-lang#346, wolf-std#5): one exclusive create with mode 0o600, so the file is never readable by anyone else, not even for the instant between a create and a set_mode — the shape a key, a token or a temporary file wants. It never reuses a file that is already there.

Rows: exists when anything is at path; not_found when the parent directory is missing; denied when the host refuses; unsupported on a host with no permission bits (windows, by name: a private file there is an access-control list, which this call does not pretend to write); io otherwise. Never traps.

Capability fs; refused at comptime (D33). Delegates to fs_open_perm.

var made = true
var f = fs.create_private("doc-create-private.tmp") else |_| {
    made = false
    fs.create("doc-create-private.tmp")?
}
fs.close(take f)?
let info = fs.stat("doc-create-private.tmp")?
fs.remove("doc-create-private.tmp")?
!made || info.mode == 0o600

create_with_mode

fn · Source line 1988

pub fn create_with_mode(path: str, mode: int) -> File ! { not_found, denied, invalid, unsupported, io, }

create, with the permission bits the file gets if this call creates it: mode less the process's umask (env.umask).

[os.fs.create.mode]. An existing file is truncated and KEEPS its mode. mode is the nine permission bits; the three above them are set afterwards with set_mode, because the hosts disagree about them at a creation.

Rows: invalid when mode is outside 0..=0o777; not_found, denied; unsupported on a host with no permission bits; io otherwise. Never traps.

Capability fs; refused at comptime (D33). Delegates to fs_open_perm.

var refused = false
var f = fs.create_with_mode("doc-create-mode.tmp", 0o1000) else |_| {
    refused = true
    fs.create("doc-create-mode.tmp")?
}
fs.close(take f)?
fs.remove("doc-create-mode.tmp")?
refused == true

create_dir_mode

fn · Source line 2024

pub fn create_dir_mode(path: str, mode: int) -> () ! { exists, not_found, denied, invalid, unsupported, io, }

create_dir, with the directory's permission bits: mode less the process's umask.

[os.fs.create.mode]. One level, as create_dir; mkdir -m is this call and then set_mode, since -m is not subject to the umask.

Rows: invalid when mode is outside 0..=0o777; exists, not_found, denied; unsupported on a host with no permission bits; io otherwise. Never traps.

Capability fs; refused at comptime (D33). Delegates to fs_create_dir_mode.

var row = "ok"
fs.create_dir_mode("doc-dir-mode.tmp", 0o1000) else |_| { row = "refused" }
row == "refused" && !fs.exists("doc-dir-mode.tmp")

time

fn · Source line 2116

pub fn time(s: int, ns: int) -> Time

The moment s seconds and ns nanoseconds from the Unix epoch.

let t = fs.time(1577854800, 123456789)
t.s == 1577854800 && t.ns == 123456789

time_now

fn · Source line 2126

pub fn time_now() -> Time

"Now": the HOST's clock at the set_times call, not a clock this program read ([os.fs.times]'s -1).

fs.time_now().ns == 0 - 1

time_keep

fn · Source line 2136

pub fn time_keep() -> Time

"Leave this time as it is" ([os.fs.times]'s -2): how one time is set and the other kept, with no read in between.

fs.time_keep().ns == 0 - 2

set_times

fn · Source line 2164

pub fn set_times(path: str, atime: Time, mtime: Time) -> () ! {not_found, denied, invalid, io}

Set the access time and the modification time of what is at path, following a final symbolic link.

[os.fs.times] (wolf-lang#700): one host call. Each of atime and mtime is a time(s, ns), time_now() or time_keep(), so one call sets both, sets one and keeps the other, or stamps now — touch, touch -a, touch -m, and the last step of cp -p. A file system keeps the precision it has (windows 100 ns steps; some keep seconds): compare what stat reads back, not what was asked.

Rows: invalid when a Time's ns is neither a count below one second nor one of the two special values; not_found; denied; io otherwise. Never traps.

Capability fs; refused at comptime (D33). Delegates to fs_set_times.

fs.write_text("doc-set-times.tmp", "x")?
fs.set_times("doc-set-times.tmp", fs.time_keep(), fs.time(1500000000, 0))?
let info = fs.stat("doc-set-times.tmp")?
fs.remove("doc-set-times.tmp")?
info.mtime_s == 1500000000 && info.modified_ms == 1500000000000

owner_keep

fn · Source line 2203

pub fn owner_keep() -> int

The word set_owner and its kin read as "leave this id as it is".

Total and pure. It is -1, the builtin tier's own word ([os.fs.owner]); the name exists so no caller writes the number — time_keep's reason.

fs.owner_keep() == 0 - 1

set_owner

fn · Source line 2234

pub fn set_owner(path: str, uid: int, gid: int) -> () ! { not_found, denied, invalid, unsupported, io, }

Set the owner and the group of what is at path, following a final symbolic link — chown.

[os.fs.owner] (wolf-lang#701): one host call. uid and gid are the ids stat answers (Info.uid, Info.gid), or owner_keep() to leave one as it is — so chgrp is set_owner(p, fs.owner_keep(), gid). Who may is the host's rule: the super-user may set any owner; anyone else may move a file they own to a group they are in, and may not give a file away. The host clears the set-user-id and set-group-id bits when an owner changes, so a program that wants them sets the owner first and the mode after (set_mode) — cp -p's order.

Rows: invalid when an id is neither owner_keep() nor in 0..=4294967294 (decided before the host), or is one the host has no mapping for; denied when this process may not make the change; not_found (a dangling link included); unsupported on a host with no owners (windows, by name); io otherwise. Never traps.

Capability fs; refused at comptime (D33). Delegates to fs_set_owner.

var refused = false
fs.set_owner("doc-set-owner.tmp", 0 - 2, fs.owner_keep()) else |_| { refused = true }
refused == true

set_file_owner

fn · Source line 2291

pub fn set_file_owner(mut f: File, uid: int, gid: int) -> () ! {denied, invalid, unsupported, io}

Set the owner and the group of the file behind f — fchown.

[os.fs.owner]: the file the handle holds, whatever its name is by now, so a rename between a creation and this call cannot send the change to another file. stdin(), stdout() and stderr() are handles too: handing a terminal to the user a program is about to become is this call on the stream.

Rows: invalid and denied as set_owner's; unsupported on a host with no owners (windows, by name); io for a closed or forged handle and for every other host refusal. Never traps.

Capability fs; refused at comptime (D33). Delegates to fs_set_owner_fd.

var refused = false
var out = fs.stdout()
fs.set_file_owner(mut out, 0 - 2, 0 - 2) else |_| { refused = true }
refused == true

set_file_mode

fn · Source line 2328

pub fn set_file_mode(mut f: File, mode: int) -> () ! {denied, invalid, io, unsupported}

Set the permission bits of the file behind f to exactly mode: fchmod, the handle form of set_mode.

[os.fs.mode.fd] (wolf-std#141): the file the handle holds, whatever its name is by now, so a mode applied after a creation cannot land on another file renamed over the name in between. mode is set_mode's twelve bits, written in octal (0o600); the umask plays no part. A handle over a directory is a directory's mode.

Rows: invalid when mode is outside 0..=0o7777, decided before the host is asked; denied when this process does not own the file; unsupported on windows, which has no permission bits, after the shape; io for a closed or forged handle and for every other host refusal, the host's number in os_error() (macOS refuses a pipe's end with EINVAL, where linux sets the pipe's mode). Never traps.

mut f, as set_file_owner: the call acts on the file the handle names. Capability fs; refused at comptime (D33). Delegates to fs_set_mode_fd, which every lane serves.

fs.write_text("doc-set-file-mode.tmp", "x")?
var f = fs.open("doc-set-file-mode.tmp")?
var row = "set"
fs.set_file_mode(mut f, 0o600) else |_| { row = "refused" }
var past = "set"
fs.set_file_mode(mut f, 0o10000) else |_| { past = "refused" }
let held = fs.fstat_record(mut f)?
fs.close(take f)?
fs.remove("doc-set-file-mode.tmp")?
past == "refused"
(row == "set" && held.mode == 0o600) || (row == "refused" && !fs.answered(held, 4))

truncate

fn · Source line 2355

pub fn truncate(mut f: File, len: int) -> () ! {invalid, io}

Make the file behind f exactly len bytes long.

[os.fs.truncate] (wolf-lang#702): shorter, the tail gone; or longer, the new bytes zeros no write stored. The handle's position does NOT move, so a write after a truncation lands where the last one ended.

Rows: invalid when len is negative; io for every host refusal — a handle not open for writing, a directory, a pipe — and for a closed or forged handle. Never traps.

Capability fs; refused at comptime (D33). Delegates to fs_truncate.

var f = fs.create("doc-truncate.tmp")?
fs.write(mut f, "0123456789")?
fs.truncate(mut f, 4)?
fs.close(take f)?
let size = fs.size("doc-truncate.tmp")?
fs.remove("doc-truncate.tmp")?
size == 4

sync

fn · Source line 2391

pub fn sync(mut f: File) -> () ! {io}

**s248 ([os.fs.sync]): put f's bytes and metadata on the disk** before answering — fsync(2) on linux, F_FULLFSYNC on macOS (whose fsync leaves them in the drive's cache), FlushFileBuffers on windows. A write that answered has reached the host, not the disk; a program that must survive a crash syncs what it wrote. sync_dir makes a creation, a rename or a removal in a directory durable.

The atomic save, five calls, a crash between any two leaving the old file or the new one under the name, whole: create_new a temporary file in the target's directory, write it, sync it, move_file it over the target (a rename in one directory: atomic on every unix), sync_dir the directory.

Rows: io for a closed or forged handle, and for every host refusal, its number in os_error() (a pipe on linux and macOS; a windows handle open only for reading). Never traps. lupin serves it from 0.1.56 (0.1.55 did not resolve the call, wolf-interp#268). The cost is the flush: 5–9 ms for 24 bytes on kasumi's btrfs, 1–9 ms on CI's macOS runner (upstream's measurement).

mut f, as truncate: the call acts on the file the handle names. Capability fs; refused at comptime (D33). Delegates to fs_sync.

var f = fs.create("doc-sync.tmp")?
fs.write(mut f, "kept")?
fs.sync(mut f)?
fs.close(take f)?
let text = fs.read_text("doc-sync.tmp")?
fs.remove("doc-sync.tmp")?
text == "kept"

sync_dir

fn · Source line 2419

pub fn sync_dir(path: str) -> () ! {denied, invalid, io, not_found, unsupported}

**s248 ([os.fs.sync]): put the directory path's entries on the disk**, so that a creation, a rename or a removal in it survives a crash — the last call of sync's atomic save.

Rows: not_found for a missing name; invalid for a name that is not a directory; denied for a refused search; unsupported on windows, by name, before the path is read (no directory opens as a file there, and NTFS orders a rename through its own log; ruling #97 R4); io otherwise. Never traps. lupin serves it from 0.1.56 (0.1.55 did not resolve the call, wolf-interp#268).

Capability fs; refused at comptime (D33). Delegates to fs_sync_dir.

fs.sync_dir(".") else |_| { }
fs.write_text("doc-sync-dir.tmp", "x")?
var on_a_file = "synced"
fs.sync_dir("doc-sync-dir.tmp") else |_| { on_a_file = "refused" }
var missing = "synced"
fs.sync_dir("doc-sync-dir-none.tmp") else |_| { missing = "refused" }
fs.remove("doc-sync-dir.tmp")?
on_a_file == "refused" && missing == "refused"

open_mode

fn · Source line 2495

pub fn open_mode(path: str, mode: int) -> File ! {not_found, denied, exists, invalid, io}

**Open path in one of [os.fs.open]'s six modes, by number** — the moded open the named ones above are spellings of, and the only one that reaches modes 3 and 5 and the NOFOLLOW and DIRECTORY flags:

- 0 read (open), 1 write, creating and truncating (create), 2 append, creating (open_append); - 3 read and write, creating, NOT truncating — an editor's in-place save, a journal reopened; - 4 the exclusive create (create_new); - 5 read without parking: a fifo or a device with no writer answers at once, a regular file is unaffected (a static-file server's open, before fstat classifies the handle).

mode + NOFOLLOW refuses a final symbolic link (NOFOLLOW's doc); mode 4 answers exists on a link with or without it. DIRECTORY added to mode 0 or 5 refuses anything but a directory (DIRECTORY's doc; open_dir is mode 0 with both flags).

Rows: invalid for a mode outside the six (with or without the flags) and any other bit above them, and for DIRECTORY beside a writing mode, before the filesystem is touched; for a final link under NOFOLLOW and a name that is not a directory under DIRECTORY; exists for mode 4 on a taken name; not_found for a missing name (modes 0 and 5) or parent; denied; io otherwise. Never traps. lupin serves the six modes inside its tree, and both flags from 0.1.60 (wolf-interp#278).

Capability fs; refused at comptime (D33). Delegates to fs_open_mode.

fs.write_text("doc-open-mode.tmp", "wolf")?
var f = fs.open_mode("doc-open-mode.tmp", 3)?
fs.write(mut f, "W")?
fs.close(take f)?
var bad = false
var g = fs.open_mode("doc-open-mode.tmp", 6) else |_| {
    bad = true
    fs.File { fd: 0 - 1 }
}
fs.close(take g) else |_| { }
let text = fs.read_text("doc-open-mode.tmp")?
fs.remove("doc-open-mode.tmp")?
text == "Wolf" && bad == true

open_dir

fn · Source line 2539

pub fn open_dir(path: str) -> File ! {not_found, denied, invalid, io}

A held directory: path opened read-only as a directory, a final symbolic link refused (open_mode(path, DIRECTORY + NOFOLLOW)), for the …_at calls, which look a name up in the directory the handle holds whatever its path has become.

[os.fs.open.directory], [os.fs.at] (wolf-std#141). The handle is a File: fstat_record, set_file_mode, set_file_owner and close serve it, and a read of it is io. A walk that must stay inside a tree starts here and goes down only by open_dir_at, one name at a time. A link in a middle component of path is followed, as by every path call.

A link as the last component is refused even when it names a directory, so on macOS open_dir("/tmp") is invalid (/tmp is a link to /private/tmp); a program that means to open a linked directory resolves the path first, open_dir(realpath(path)?), as the example does.

Rows: invalid for a name that is not a directory or is a link (the host's ENOTDIR in os_error(), on linux and macOS alike), and on windows for every path, before the host; not_found for a missing name; denied; io otherwise. Never traps. lupin serves it inside its tree.

Capability fs; refused at comptime (D33). Delegates to fs_open_mode.

fs.create_dir_all("doc-open-dir.tmp/real")?
var linked = true
fs.symlink("real", "doc-open-dir.tmp/link") else |_| { linked = false }
var direct = "held"
var a = fs.open_dir("doc-open-dir.tmp/link") else |_| { direct = "refused"; fs.stdin() }
let real = fs.realpath("doc-open-dir.tmp/link") else ""
var resolved = "held"
var b = fs.open_dir(real) else |_| { resolved = "refused"; fs.stdin() }
fs.close(take a) else |_| { }
fs.close(take b) else |_| { }
fs.remove_dir_all("doc-open-dir.tmp")?
(linked && direct == "refused" && resolved == "held") || (!linked && resolved == "refused")

open_dir_at

fn · Source line 2579

pub fn open_dir_at(dir: File, name: str) -> File ! {denied, invalid, io, not_found, unsupported}

**The directory name in the held directory dir**, opened the way open_dir opens a path: read-only, a directory or refused, a link refused. A walk that goes down only by this call cannot be carried out of its tree by a directory someone swaps for a link between two of its steps.

[os.fs.at.open] (wolf-std#141): open_at(dir, name, DIRECTORY + NOFOLLOW, 0). One component is the confining use; .. and a name with slashes are served as the host resolves them, as for open_at.

Rows: invalid for an empty or absolute name, before the host; for a name that is not a directory or is a link; and for a dir that is not a directory (ENOTDIR in os_error()); unsupported on windows, after the shape; not_found for a missing name; denied; io for a closed or forged handle and otherwise. Never traps. lupin 0.1.62 checks the shape and refuses the call by name (wolf-interp#321).

dir is read: the call acts on a name the directory holds, never on the handle, so one handle serves any number of calls. Capability fs; refused at comptime (D33). Delegates to fs_open_at.

fs.create_dir_all("doc-open-dir-at.tmp/sub")?
fs.write_text("doc-open-dir-at.tmp/f", "x")?
var held = true
var d = fs.open_dir("doc-open-dir-at.tmp") else |_| { held = false; fs.stdin() }
var sub = "held"
var s = fs.open_dir_at(d, "sub") else |_| { sub = "refused"; fs.stdin() }
var file = "held"
var f = fs.open_dir_at(d, "f") else |_| { file = "refused"; fs.stdin() }
fs.close(take s) else |_| { }
fs.close(take f) else |_| { }
fs.close(take d) else |_| { }
fs.remove_dir_all("doc-open-dir-at.tmp")?
(held && sub == "held" && file == "refused") || (!held && sub == "refused")

open_at

fn · Source line 2621

pub fn open_at(dir: File, name: str, mode: int, perm: int) -> File ! { denied, exists, invalid, io, not_found, unsupported, }

**name in the held directory dir, opened** in one of open_mode's six modes with its flags, a file the call creates getting perm less the umask from its first instant: openat(2), the open relative to a directory the program holds.

[os.fs.at.open] (wolf-std#141). mode is open_mode's: 0 read, 1 write creating and truncating, 2 append, 3 read and write creating, 4 the exclusive create, 5 read without waiting; plus NOFOLLOW, and on 0 and 5 DIRECTORY. perm is create_with_mode's nine bits, only checked when nothing is created. open_dir_at is this call with DIRECTORY + NOFOLLOW.

Rows: invalid, before the host, for a mode outside the six or a bit above the flags, for perm outside 0..=0o777 and for an empty or absolute name; then for a final link under NOFOLLOW, a name that is not a directory under DIRECTORY and a dir that is not a directory; unsupported on windows, after the shape; exists for mode 4 on a taken name, a link included; not_found for a missing name (modes 0 and 5) or middle component; denied; io for a closed or forged handle and otherwise. Never traps. lupin 0.1.62 checks the shape and refuses the call by name (wolf-interp#321).

dir is read, as in every …_at call. Capability fs; refused at comptime (D33). Delegates to fs_open_at.

fs.create_dir_all("doc-open-at.tmp")?
var held = true
var d = fs.open_dir("doc-open-at.tmp") else |_| { held = false; fs.stdin() }
var made = true
var f = fs.open_at(d, "new", 4, 0o600) else |_| { made = false; fs.stdin() }
if made { fs.write(mut f, "wolves")? }
fs.close(take f) else |_| { }
fs.close(take d) else |_| { }
let text = fs.read_text("doc-open-at.tmp/new") else ""
fs.remove_dir_all("doc-open-at.tmp")?
(held && made && text == "wolves") || (!held && !made)

stat_at

fn · Source line 2659

pub fn stat_at(dir: File, name: str) -> Info ! {denied, invalid, io, not_found, unsupported}

**The record of name in the held directory dir**, a final link followed: stat's twenty words as an Info, from one host call relative to the handle (statx(2) on linux, fstatat(2) elsewhere), so the record is of the name in that directory whatever its path is by now.

[os.fs.at.stat] (wolf-std#141). Rows: invalid for an empty or absolute name, before the host, and for a dir that is not a directory; unsupported on windows, after the shape; not_found for a missing name, a dangling link included; denied; io for a closed or forged handle and otherwise. Never traps. lupin 0.1.62 refuses the call by name (wolf-interp#321).

dir is read. Capability fs; refused at comptime (D33). Delegates to fs_stat_at.

fs.create_dir_all("doc-stat-at.tmp")?
fs.write_text("doc-stat-at.tmp/f", "wolves")?
var held = true
var d = fs.open_dir("doc-stat-at.tmp") else |_| { held = false; fs.stdin() }
var answered = true
let info = fs.stat_at(d, "f") else |_| { answered = false; fs.stat("doc-stat-at.tmp")? }
fs.close(take d) else |_| { }
fs.remove_dir_all("doc-stat-at.tmp")?
(held && answered && info.kind == 0 && info.size == 6) || (!held && !answered)

lstat_at

fn · Source line 2688

pub fn lstat_at(dir: File, name: str) -> Info ! {denied, invalid, io, not_found, unsupported}

**The record of name ITSELF in the held directory dir**, a link included (kind 3, its own size and times): lstat relative to the handle, the question a walk asks of each entry before it opens one. On a name that is not a link it is stat_at's record; a dangling link is a record here and not_found there.

[os.fs.at.lstat] (wolf-std#141). Rows as stat_at's. lupin 0.1.62 refuses the call by name (wolf-interp#321).

dir is read. Capability fs; refused at comptime (D33). Delegates to fs_lstat_at.

fs.create_dir_all("doc-lstat-at.tmp")?
fs.write_text("doc-lstat-at.tmp/f", "x")?
var linked = true
fs.symlink("f", "doc-lstat-at.tmp/l") else |_| { linked = false }
var d = fs.open_dir("doc-lstat-at.tmp") else |_| { linked = false; fs.stdin() }
var kind = 0 - 1
if linked { kind = fs.lstat_at(d, "l")?.kind }
fs.close(take d) else |_| { }
fs.remove_dir_all("doc-lstat-at.tmp")?
kind == 3 || !linked

remove_at

fn · Source line 2718

pub fn remove_at(dir: File, name: str) -> () ! {denied, invalid, io, not_found, unsupported}

**Remove the name name from the held directory dir**: a file, a link (never what it names) or a fifo, remove relative to the handle.

[os.fs.at.remove] (wolf-std#141). Rows: invalid for an empty or absolute name, before the host, and for a dir that is not a directory; unsupported on windows, after the shape; not_found for a missing name; denied where the host refuses, and on macOS for a directory (EPERM), which linux refuses io (EISDIR), as remove does; io for a closed or forged handle and otherwise. Never traps. lupin 0.1.62 refuses the call by name (wolf-interp#321).

dir is read. Capability fs; refused at comptime (D33). Delegates to fs_remove_at.

fs.create_dir_all("doc-remove-at.tmp")?
fs.write_text("doc-remove-at.tmp/f", "x")?
var held = true
var d = fs.open_dir("doc-remove-at.tmp") else |_| { held = false; fs.stdin() }
if held { fs.remove_at(d, "f")? }
fs.close(take d) else |_| { }
let gone = !fs.exists("doc-remove-at.tmp/f")
fs.remove_dir_all("doc-remove-at.tmp")?
gone == held

remove_dir_at

fn · Source line 2753

pub fn remove_dir_at(dir: File, name: str) -> () ! {denied, invalid, io, not_found, unsupported}

**Remove the EMPTY directory name from the held directory dir**: remove_dir relative to the handle. One that is not empty is io, and a file or a link is invalid, so a walk never removes through a link; with open_dir_at and remove_at it is rm -r as a walk that never names more than one component.

[os.fs.at.remove.dir] (wolf-std#141). Rows: invalid for an empty or absolute name, before the host, for a name that is a file or a link and for a dir that is not a directory (ENOTDIR in os_error()); unsupported on windows, after the shape; not_found for a missing name; denied; io for a directory that is not empty (ENOTEMPTY), for a closed or forged handle and otherwise. Never traps. lupin 0.1.62 refuses the call by name (wolf-interp#321).

dir is read. Capability fs; refused at comptime (D33). Delegates to fs_remove_dir_at.

fs.create_dir_all("doc-remove-dir-at.tmp/sub")?
fs.create_dir_all("doc-remove-dir-at.tmp/full")?
fs.write_text("doc-remove-dir-at.tmp/full/f", "x")?
var held = true
var d = fs.open_dir("doc-remove-dir-at.tmp") else |_| { held = false; fs.stdin() }
var full = "removed"
fs.remove_dir_at(d, "full") else |_| { full = "refused" }
if held { fs.remove_dir_at(d, "sub")? }
fs.close(take d) else |_| { }
let gone = !fs.exists("doc-remove-dir-at.tmp/sub")
fs.remove_dir_all("doc-remove-dir-at.tmp")?
full == "refused" && gone == held

create_dir_at

fn · Source line 2784

pub fn create_dir_at(dir: File, name: str, mode: int) -> () ! { denied, exists, invalid, io, not_found, unsupported, }

**Make the directory name in the held directory dir**, its permission bits mode less the umask from its first instant: create_dir_mode relative to the handle, one level.

[os.fs.at.mkdir] (wolf-std#141). Rows: invalid, before the host, for a mode outside 0..=0o777 and then for an empty or absolute name, and for a dir that is not a directory; unsupported on windows, after the shape; exists for a taken name, a dangling link included; not_found for a missing middle component; denied; io for a closed or forged handle and otherwise. Never traps. lupin 0.1.62 checks the shape and refuses the call by name (wolf-interp#321).

dir is read. Capability fs; refused at comptime (D33). Delegates to fs_create_dir_at.

fs.create_dir_all("doc-create-dir-at.tmp")?
var held = true
var d = fs.open_dir("doc-create-dir-at.tmp") else |_| { held = false; fs.stdin() }
if held { fs.create_dir_at(d, "sub", 0o755)? }
var again = "made"
fs.create_dir_at(d, "sub", 0o755) else |_| { again = "refused" }
fs.close(take d) else |_| { }
let made = fs.is_dir("doc-create-dir-at.tmp/sub")
fs.remove_dir_all("doc-create-dir-at.tmp")?
made == held && again == "refused"

entries_at

fn · Source line 2941

pub fn entries_at(mut dir: File) -> List[Entry] ! {denied, invalid, io, not_found, unsupported}

**The entries of the held directory dir**, in entries' shape: the host's order (not sorted), no . or .., each entry its own kind and its name's bytes, a name that is not UTF-8 listed like any other. Every call reads from the first entry.

[os.fs.at.readdir] (wolf-std#141). The listing is read through a duplicate of the handle that shares its position, so two listings of one handle at once would split the entries between them: mut dir makes that a compile error within a program, and a program that lists one directory in two tasks opens it twice. A kind the host's entry does not carry is asked of the entry without following it; an entry gone in between is kind 2.

Rows: invalid for a dir that is not a directory (ENOTDIR); unsupported on windows; not_found, denied; io for a closed or forged handle and otherwise. Never traps. lupin 0.1.62 refuses the call by name (wolf-interp#321).

Capability fs; refused at comptime (D33). Delegates to fs_read_dir_entries_at.

fs.create_dir_all("doc-entries-at.tmp/sub")?
fs.write_text("doc-entries-at.tmp/f", "x")?
var held = true
var d = fs.open_dir("doc-entries-at.tmp") else |_| { held = false; fs.stdin() }
var n = 0
if held { n = fs.entries_at(mut d)?.len }
var again = 0
if held { again = fs.entries_at(mut d)?.len }
fs.close(take d) else |_| { }
fs.remove_dir_all("doc-entries-at.tmp")?
(held && n == 2 && again == 2) || (!held && n == 0)

access

fn · Source line 2985

pub fn access(path: str, mode: int) -> () ! {denied, invalid, io, not_found, unsupported}

**s254 ([os.fs.access], wolf 0.2.35): may this process do what mode asks of path**, by its REAL user and group ids — access(2), a final link followed. mode is 0 (the name exists) or a sum of 4 read, 2 write and 1 execute (POSIX's R_OK, W_OK, X_OK, the same numbers on every unix). Ok is a grant.

Advice, not a lock: the answer can be stale by the next call, and a program that must know opens. It is the question to ask BEFORE any file is made — whether a directory takes a write, so a save chooses the atomic rename or the in-place write — and it sees what a test of the mode bits cannot: an access-control list, a read-only mount. The real ids are the effective ones unless the program is set-id or has changed its ids (process.set_ids); an open uses the effective ones. Root is the host's rule: every read and write granted, an execute only where some execute bit is set.

Rows: invalid for a mode outside 0..=7, before the host; then unsupported on windows (its permission is an access-control list the three bits do not describe); denied for the host's refusal (a write on a read-only mount included); not_found for a missing name, a dangling link included; io otherwise (a component that is no directory, a loop of links), the host's number in os_error(). Never traps. lupin resolves the call from 0.1.59 (wolf-interp#278).

Capability fs; refused at comptime (D33). Delegates to fs_access.

fs.write_text("doc-access.tmp", "x")?
var row = "granted"
fs.access("doc-access.tmp", 8) else |_| { row = "refused" }
var missing = "granted"
fs.access("doc-access-none.tmp", 0) else |_| { missing = "refused" }
fs.remove("doc-access.tmp")?
row == "refused" && missing == "refused"

fstat_record

fn · Source line 3024

pub fn fstat_record(mut f: File) -> Info ! {io}

**s254 ([os.fs.fstat.record], wolf 0.2.35; ruling asked R-sc72-1): the full record of the file f HOLDS**, stat's twenty words as an Info, from one metadata read on the handle (fstat(2), statx(2) on linux) — its identity (dev, ino), link count, mode, owner and nanosecond times with no path walked between the open and the question. "Is the file I opened still the one under that name" is fstat_record(mut f)? against stat(name)?, dev and ino equal; "is my input my output" is the same comparison of two handles.

fstat's Stat keeps its three words (programs build it by literal); this is the path record's type, so one reader serves both. A handle never names a link (an open follows it, or refuses it under NOFOLLOW), so kind is never 3: a pipe's end is 4, a socket 5. The standard streams are handles 0..2. Windows answers its column of stat's table — a handle that is no disk file is kind 2 there — with the unanswered words' have bits clear.

Rows: io for every refusal — a closed or forged handle, a word outside int — because on a handle there is no name to be missing or refused. Never traps. The cost: one host call and one twenty-word list, stat's. lupin serves the call from 0.1.60 (wolf-interp#278).

mut f, as fstat. Capability fs; refused at comptime (D33). Delegates to fs_fstat_record.

fs.write_text("doc-fstat-record.tmp", "wolves")?
var f = fs.open("doc-fstat-record.tmp")?
let held = fs.fstat_record(mut f)?
fs.close(take f)?
let named = fs.stat("doc-fstat-record.tmp")?
fs.remove("doc-fstat-record.tmp")?
held.kind == 0 && held.size == 6 && held.ino == named.ino && held.dev == named.dev

lock

fn · Source line 3087

pub fn lock(mut f: File, kind: int) -> () ! {busy, invalid, io, unsupported}

**s254 ([os.fs.lock], wolf 0.2.35): an advisory lock on the file behind f**, LOCK_SHARED or LOCK_EXCLUSIVE, tried once and never waited for — a conflicting lock held through ANOTHER OPEN of the file is busy (a program polls with its own deadline; a wait in the kernel would park a worker where a kill cannot reach it).

The lock belongs to the open file (BSD flock(2)'s rule; LockFileEx over the whole file on windows): two opens of one file conflict even in one process; a child's copy of the handle shares the lock; the lock lasts until unlock or until the last copy is closed, and closing some other handle of the file releases nothing. A second lock on a handle that holds one is the host's (unix converts it, not atomically; windows answers busy): a portable program unlocks first. Advisory on unix — it binds only the programs that ask — and mandatory on windows, where another handle's read or write of the file fails while it is held. On linux an flock lock does not see a C program's fcntl record lock.

Rows: invalid for a kind other than 1 or 2, before the handle is looked at; busy for a conflict (EWOULDBLOCK in os_error(); windows ERROR_LOCK_VIOLATION); io for a closed or forged handle; unsupported where the kernel has no lock call or the filesystem keeps no locks. Never traps. lupin 0.1.56 does not resolve the call (wolf-interp#278).

mut f: the call acts on the file the handle names. Capability fs; refused at comptime (D33). Delegates to fs_lock.

fs.write_text("doc-lock.tmp", "x")?
var a = fs.open("doc-lock.tmp")?
var b = fs.open("doc-lock.tmp")?
fs.lock(mut a, fs.LOCK_EXCLUSIVE)?
var busy = false
fs.lock(mut b, fs.LOCK_SHARED) else |_| { busy = true }
fs.unlock(mut a)?
fs.lock(mut b, fs.LOCK_SHARED)?
fs.close(take a)?
fs.close(take b)?
fs.remove("doc-lock.tmp")?
busy == true

unlock

fn · Source line 3110

pub fn unlock(mut f: File) -> () ! {io, unsupported}

**s254 ([os.fs.lock], wolf 0.2.35): release the lock f's open file holds.** A handle that holds none is ok on every host.

Rows: io for a closed or forged handle; unsupported where the kernel has no lock call. Never traps. lupin 0.1.56 does not resolve the call (wolf-interp#278).

Capability fs; refused at comptime (D33). Delegates to fs_unlock.

fs.write_text("doc-unlock.tmp", "x")?
var a = fs.open("doc-unlock.tmp")?
fs.unlock(mut a)?
fs.lock(mut a, fs.LOCK_EXCLUSIVE)?
fs.unlock(mut a)?
fs.close(take a)?
fs.remove("doc-unlock.tmp")?
fs.exists("doc-unlock.tmp") == false

mkfifo

fn · Source line 3138

pub fn mkfifo(path: str, perm: int) -> () ! {denied, exists, invalid, io, not_found, unsupported}

**s254 ([os.fs.mkfifo], wolf 0.2.35): make a fifo named path**, mkfifo(3), its permission bits perm less the process's umask (create_dir_mode's rule). It is stat's kind 4; open_mode(path, 5) is the open that does not park on it with no writer, and a plain read open waits for one.

Rows: invalid for a perm outside 0..=0o777, before the host; unsupported on windows, by name, before the path is read (its named pipes are servers in another namespace), and where the filesystem or kernel makes no fifo; exists for a taken name, a dangling link included; not_found for a missing parent; denied for a refused write of the directory; io otherwise. Never traps. lupin 0.1.56 does not resolve the call (wolf-interp#278).

Capability fs; refused at comptime (D33). Delegates to fs_mkfifo.

var made = true
fs.mkfifo("doc-mkfifo.tmp", 0o600) else |_| { made = false }
var kind = 4
if made { kind = fs.lstat("doc-mkfifo.tmp")?.kind }
if made { fs.remove("doc-mkfifo.tmp")? }
kind == 4

set_nonblock

fn · Source line 3170

pub fn set_nonblock(mut f: File, on: bool) -> () ! {invalid, io, unsupported}

**s254 ([os.fs.nonblock], wolf 0.2.35): set (on) or clear the non-blocking flag on the open file behind f** (O_NONBLOCK). On a handle with the flag, write_some answers busy where it would park and read_chunk answers io (EAGAIN in os_error()) where there is nothing to read; signal.wait_fds is the wait before either. The flag is the open file's: a child's copy of the handle sees it, and a pipe's two ends are two open files.

Rows: invalid for the standard streams 0, 1 and 2, by name (their open file is shared with whoever started the process, and a flag set there outlives the program); unsupported on windows; io for a closed or forged handle. Never traps. The cost: two fcntl(2)s (one when the flag is already as asked). lupin 0.1.56 does not resolve the call (wolf-interp#278).

mut f: the call acts on the file the handle names. Capability fs; refused at comptime (D33). Delegates to fs_set_nonblock. The example uses a standard stream, since a pipe comes from std.process; a clipboard writer sets its pipe's write end with fs.set_nonblock(mut w, true)?, writes with write_some until busy, then waits on the end under a deadline.

var out = fs.stdout()
var row = "set"
fs.set_nonblock(mut out, true) else |_| { row = "refused" }
row == "refused"

write_some

fn · Source line 3238

pub fn write_some(mut f: File, b: List[byte]) -> int ! {busy, invalid, io}

**s254 ([os.fs.nonblock], wolf 0.2.35): ONE write of b to f, and how many bytes the host took** — all of them or a first part; at least 1 for a non-empty list, 0 for an empty one (the handle still checked). On a non-blocking handle that can take nothing now it is busy; on a blocking one it waits as write_chunk does, for the first byte only. write_chunk writes everything or answers a row and, on a non-blocking handle, loses how much it wrote: this is the write that says.

Rows: busy (EAGAIN in os_error()) as above; invalid for a list of the wrong element width (an FFI caller's); io for a closed or forged handle, and for a pipe whose reader has gone once a program ignores signal.broken_pipe() (otherwise the host's SIGPIPE comes first). The standard streams 1 and 2 are written after std's own buffer is flushed. Windows serves it (one WriteFile, never busy). Never traps. The cost: one write(2), no copy of the list. lupin 0.1.56 does not resolve the call (wolf-interp#278).

mut f, as write_chunk. Capability fs; refused at comptime (D33). Delegates to fs_write_some.

var raw = List[byte]()
for c in [119, 111, 108, 102] { (mut raw).push(c as byte) }
var f = fs.create("doc-write-some.tmp")?
let n = fs.write_some(mut f, raw)?
let none = fs.write_some(mut f, List[byte]())?
fs.close(take f)?
let text = fs.read_text("doc-write-some.tmp")?
fs.remove("doc-write-some.tmp")?
n == 4 && none == 0 && text == "wolf"

The partial-write loop (sc82): a server keeps one output queue per client and never parks on one. The handle is non-blocking; each call takes what fits, and the queue's offset moves by the count; busy means "nothing fits now", and the server waits for WRITE on the handle (std.poll) before writing again. A pty master holds some kilobytes (20480 bytes on PAX) and a pipe 64 KiB on linux, so a large queue is written in parts. Here a fifo opened read and write, which nobody reads, is the slow client: 16 lists of 8192 bytes are more than it holds, and the loop stops at busy with part of the queue taken (windows has no fifo, and the example asserts only what it made). The example's handler stops on any row, since a line holding a match arm reads as an assertion to §4's extractor; a server's loop matches busy alone and passes invalid and io on, as tests/poll/write_partial.lu does.

var chunk = List[byte]()
for i in 0..8192 { (mut chunk).push(120 as byte) }
var made = true
fs.mkfifo("doc-write-some.fifo", 0o600) else |_| { made = false }
var f = fs.stdin()
if made { f = fs.open_mode("doc-write-some.fifo", 3)? }
if made { fs.set_nonblock(mut f, true)? }
var took = 0
var stopped = !made
for turn in 0..16 { if !stopped { took = took + (fs.write_some(mut f, chunk) else |_| { stopped = true; 0 }) } }
if made { fs.close(take f)? }
if made { fs.remove("doc-write-some.fifo")? }
stopped == true
(took > 0 && took < 16 * 8192) == made

adopt

fn · Source line 3277

pub fn adopt(fd: int) -> File ! {invalid, io, unsupported}

**s253 ([os.proc.adopt], wolf 0.2.35): a descriptor this process INHERITED, as a File that owns it** — prog 5>out, a supervisor's pipe, the ready descriptor a test driver hands its child. Every handle call serves the answer, close closes the descriptor, and a descriptor map hands it to a child (process.set_fd). The handle is a number of this module's table, not the descriptor's (3 in a program that has opened nothing); the descriptor keeps its own.

What may be adopted is told by close-on-exec: a descriptor that came across exec carries no such flag, and every one the runtime makes carries it from birth, as does one adopted before — so the rule is open, and not close-on-exec. The adoption marks it close-on-exec, so a child started after gets it only through a descriptor map; a child started before inherited it as the host passed it.

Rows: invalid for 0, 1 and 2 (the standard streams, stdin, stdout and stderr already) and a number outside 3..=2147483647, before the host; then unsupported on windows (a handle there is not a small number a parent names by position); io for a number that is not open (EBADF in os_error()) and for one this process already holds. Never traps. The checked machine adopts the wolf process's own inherited descriptor. lupin 0.1.56 does not resolve the call (wolf-interp#277).

Capability fs; refused at comptime (D33). Delegates to fs_adopt.

var row = "adopted"
var f = fs.adopt(2) else |_| {
    row = "refused"
    fs.File { fd: 0 - 1 }
}
fs.close(take f) else |_| { }
row == "refused"

read_into

fn · Source line 3317

pub fn read_into(mut f: File, mut buf: List[byte], max: int) -> int ! {eof, io}

**#94: read up to max bytes from f INTO buf**, whose contents become the bytes read and whose storage is kept (List.reset, then a push per byte), and answer how many — C's read(2) shape, for a loop that must not grow: an editor's key reader, a pipe pump. Nothing is kept per call: the chunk the host answers (read_chunk's fresh list) is made in a region this call opens and dropped with it, and buf grows in its own region only past its largest read so far, so a loop of reads holds memory flat (tests/fs/read_into_rows.lu measures it). Not allocation-free in the strict sense: each call still opens one region, and the bytes are copied once into buf.

buf's parameter is ambient-clean ([mem.region.outer-write]: it takes resets and byte pushes only), so a caller may call this inside a per-turn region block of its own with buf declared outside it.

Rows: eof when the file is already at its end and io when the handle is closed or foreign or the host failed (read_chunk's two), and on a row buf is as it was. max at or below zero reads nothing, empties buf and answers 0. Never traps. lupin 0.1.56 does not resolve List.reset (wolf-interp#289, is81), so the call is unsupported there.

mut f (the position advances) and mut buf (its contents are the answer). Capability fs; refused at comptime (D33). Delegates to fs_read_chunk.

fs.write_text("doc-read-into.tmp", "wolves")?
var f = fs.open("doc-read-into.tmp")?
var buf = List[byte]()
let n = fs.read_into(mut f, mut buf, 4)?
let m = fs.read_into(mut f, mut buf, 4)?
fs.close(take f)?
fs.remove("doc-read-into.tmp")?
n == 4 && m == 2 && buf.len == 2

Constants

NOFOLLOW

const · Source line 2434

pub const NOFOLLOW: int = 16

The flag that makes open_mode refuse a final symbolic link ([os.fs.open.nofollow], wolf 0.2.35): bit 16, added to any of the six modes — fs.open_mode(path, 3 + fs.NOFOLLOW). A path whose LAST component is a link is then invalid (the host's ELOOP in os_error()) and nothing is created or truncated; a link in a middle component is followed either way. Windows refuses the bit invalid, before the host.

fs.NOFOLLOW == 16

DIRECTORY

const · Source line 2448

pub const DIRECTORY: int = 32

The flag that makes an open refuse anything but a directory ([os.fs.open.directory], wolf 0.2.37): bit 32, added to read mode 0 or 5 of open_mode or open_at. fs.open_mode(path, fs.DIRECTORY + fs.NOFOLLOW) is open_dir. A name that is not a directory is then invalid (the host's ENOTDIR in os_error()), and a fifo is refused before it is opened, so the open never waits on one. Beside a writing mode the bit is invalid before the host, and so it is on windows, where no directory opens as a file.

fs.DIRECTORY == 32

LOCK_SHARED

const · Source line 3035

pub const LOCK_SHARED: int = 1

lock's kind 1: a shared lock, any number of which may be held at once through different opens of one file ([os.fs.lock]).

fs.LOCK_SHARED == 1

LOCK_EXCLUSIVE

const · Source line 3043

pub const LOCK_EXCLUSIVE: int = 2

lock's kind 2: an exclusive lock, which no other open of the file may hold beside it, shared or exclusive ([os.fs.lock]).

fs.LOCK_EXCLUSIVE == 2

Errors and row tags

Tags named by public signatures: busy, cross_device, denied, eof, exists, invalid, io, none, not_found, unseekable, unsupported, utf8. Their conditions are documented on the functions that return them.

IoErrors

error · Source line 170

pub error IoErrors = {not_found, denied, io}

The row fourteen signatures below carry, named once ([type.err.alias]). Transparent: the alias and the expanded row are the same type in both directions, and the diagnostic still names tags ([type.err.alias.diag]).