~/bend-docscommunity

src/Fs.bend relies on unsafe/foreign

raw source on the hub · import mylsm-lsm-store@0.6.0.0/src/Fs.bend as Fs

6 imports
import Base
import bend-kit-bytes@0.3.2.0/bytes.bend as StorageBytes
import ./FilesCompat.bend as PackedFiles
import ./FsPolicy.bend as Policy
import ./coordinator/QueuePolicy.bend as QueuePolicy
import ./ReadAtPolicy.bend as ReadAtPolicy

Types

type WriteWordsState source · line 20 · raw

Type

Tracks each bounded write syscall and its terminal outcome.

type ReadAtState source · line 246 · raw

Type

Retains the file and bounded positional-read progress between host calls.

Definitions

def read_words source · line 12 · raw

@file:File -> @max:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>))

Read at most 1 MiB as packed words. Short reads are valid progress; zero is EOF.

def u32.clone.pair.result source · line 26 · raw

@copies:Pair(Nat, Nat) -> Pair(U32, U32)

def u32.clone.pair source · line 30 · raw

@value:U32 -> Pair(U32, U32)

def u32.clone.triple.finish source · line 33 · raw

@first:U32 -> @copies:Pair(U32, U32) -> Pair(U32, Pair(U32, U32))

def u32.clone.triple.first source · line 40 · raw

@pair:Pair(U32, U32) -> Pair(U32, Pair(U32, U32))

def u32.clone.triple source · line 45 · raw

@value:U32 -> Pair(U32, Pair(U32, U32))

def write_words.state.remaining.copied source · line 48 · raw

@file:File -> @for_write_offset:U32 -> @for_read_offset:U32 -> @remaining:Pair(U32, Pair(U32, U32)) -> @words:Array<U32> -> WriteWordsState

def write_words.state.remaining source · line 61 · raw

@file:File -> @offsets:Pair(U32, U32) -> @remaining:Pair(U32, Pair(U32, U32)) -> @words:Array<U32> -> WriteWordsState

def write_words.state source · line 72 · raw

@file:File -> @offset:U32 -> @remaining:U32 -> @words:Array<U32> -> WriteWordsState

def write_words.after.choose source · line 81 · raw

@file:File -> @offset:U32 -> @remaining:U32 -> @words:Array<U32> -> @no_progress:Bool -> WriteWordsState

def write_words.after.checked source · line 92 · raw

@file:File -> @offset:U32 -> @remaining:U32 -> @copies:Pair(U32, Pair(U32, U32)) -> @words:Array<U32> -> WriteWordsState

def write_words.after source · line 105 · raw

@pair:Pair(File, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>) -> @offset:U32 -> @remaining:U32 -> WriteWordsState

def write_words.loop source · line 116 · raw

@fuel:Nat -> @state:WriteWordsState -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Unit>))

def write_words source · line 161 · raw

@file:File -> @len:U32 -> @words:Array<U32> -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Unit>))

Writes one packed buffer through bounded single-syscall steps.

def read_bytes.wrap source · line 170 · raw

@result:Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)> -> Result<&1, &1, Pair(U32, String), 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>

def read_bytes.pair source · line 180 · raw

@pair:Pair(File, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>) -> Pair(File, Result<&1, &1, Pair(U32, String), 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>)

def read_bytes source · line 189 · raw

@file:File -> @max:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>))

Read one bounded packed chunk; nonempty short reads are not EOF.

def read_at.pack.finish source · line 198 · raw

@offset:U32 -> @result:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes

def read_at.nat.clone source · line 203 · raw

@+value:Nat -> Pair(Nat, Nat)

def read_at.nat.clone.triple source · line 206 · raw

@+value:Nat -> Pair(Nat, Pair(Nat, Nat))

def read_at.pack.go source · line 209 · raw

@fuel:Nat -> @values:List<&2, U32> -> @result:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+offset:U32 -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes

def read_at.pack.buffer.length source · line 224 · raw

@values:List<&2, U32> -> @lengths:Pair(Nat, Nat) -> @buf:Array<U32> -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes

def read_at.pack.buffer source · line 234 · raw

@values:List<&2, U32> -> @buffer:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes

def read_at.pack source · line 242 · raw

@max:U32 -> @values:List<&2, U32> -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes

def read_at.finish source · line 255 · raw

@file:File -> @chunks:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>))

def read_at.exhausted source · line 264 · raw

@state:ReadAtState -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>))

Returns an explicit error if bounded progress unexpectedly runs out.

def read_at.loop source · line 283 · raw

@fuel:Nat -> @state:ReadAtState -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>))

Assembles a positional read from bounded chunks without moving the file cursor.

def read_at.range.valid source · line 320 · raw

@offset:Nat -> @max:Nat -> Bool

def read_at.start.validated source · line 323 · raw

@file:File -> @offset:Nat -> @maxima:Pair(Nat, Nat) -> @valid:Bool -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>))

def read_at.start source · line 339 · raw

@file:File -> @offsets:Pair(Nat, Nat) -> @maxima:Pair(Nat, Pair(Nat, Nat)) -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>))

def read_at source · line 352 · raw

@file:File -> @+offset:U32 -> @+max:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>))

Reads bounded bytes at a file offset without changing its current position.

def write_bytes source · line 361 · raw

@file:File -> @bytes:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Unit>))

Write the significant bytes of a packed buffer through the pinned host effect.

def rename source · line 390 · raw

@old:String -> @new:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)

Atomically rename a filesystem path.

def remove source · line 399 · raw

@path:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)

Remove a file or empty directory.

def exists.result source · line 428 · raw

@result:Result<&1, &1, Pair(U32, String), 0x8f9a5c58059f5db5361cb2eddb73ec7f/src/FilesCompat.Info> -> Result<&1, &1, Pair(U32, String), Bool>

Check whether a filesystem path exists.

def exists source · line 436 · raw

@path:String -> IO(Result<&1, &1, Pair(U32, String), Bool>)

Returns whether a path exists and preserves other stat errors.

def grab_name source · line 448 · raw

@nm:String -> @acc:List<&1, String> -> List<&1, String>

Pure accumulator step (leaf: matches structurally, never recurses). Past-end fetches answer "" (SNil{}), which is skipped.

def read_go source · line 457 · raw

@fuel:Nat -> @+path:String -> @+idx:Nat -> @acc:List<&1, String> -> IO(List<&1, String>)

Fuel-bounded sweep 0..count-1. Startup-only use (spec §10 below): the directory is stable during recovery, so count-then-fetch is exact.

def read_dir source · line 467 · raw

@+path:String -> IO(Result<&1, &1, Pair(U32, String), List<&1, String>>)

List directory names using the bounded count-then-fetch host API.

def write_text.closed source · line 473 · raw

@pair:Pair(File, Result<&1, &1, Pair(U32, String), Unit>) -> IO(Result<&1, &1, Pair(U32, String), Unit>)

def write_text.opened source · line 482 · raw

@opened:Result<&1, &1, Pair(U32, String), File> -> @data:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)

def write_text source · line 494 · raw

@path:String -> @data:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)

Writes a whole text file, replacing what was there.

def read_text.closed source · line 499 · raw

@pair:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> IO(Result<&1, &1, Pair(U32, String), String>)

def read_text.opened source · line 508 · raw

@opened:Result<&1, &1, Pair(U32, String), File> -> IO(Result<&1, &1, Pair(U32, String), String>)

def read_text source · line 520 · raw

@path:String -> IO(Result<&1, &1, Pair(U32, String), String>)

Reads a whole text file in one bounded call.

Effects (foreign code)

effect fsync source · line 370 · raw

@path:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)

Sync file contents to stable storage.

foreign: src/effs/fsync.c, src/effs/fsync.js

effect clock_monotonic source · line 375 · raw

IO(Result<&1, &1, Pair(U32, String), Nat>)

Reads one monotonic clock sample as nanoseconds.

foreign: src/effs/clock_monotonic.c, src/effs/clock_monotonic.js

effect sleep_ms source · line 380 · raw

@milliseconds:U32 -> IO(Result<&1, &1, Pair(U32, String), Unit>)

Sleeps once for the requested bounded millisecond duration.

foreign: src/effs/sleep.c, src/effs/sleep.js

effect truncate source · line 385 · raw

@path:String -> @offset:Nat -> IO(Result<&1, &1, Pair(U32, String), Unit>)

Handle truncate in the filesystem effects.

foreign: src/effs/truncate.c, src/effs/truncate.js

effect rename_noreplace source · line 394 · raw

@old:String -> @new:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)

Atomically rename a filesystem path only when the destination is absent.

foreign: src/effs/rename_noreplace.c, src/effs/rename_noreplace.js

effect read_dir_count source · line 403 · raw

@path:String -> IO(Result<&1, &1, Pair(U32, String), Nat>)

Return the number of entries available through the indexed directory API.

foreign: src/effs/read_dir.c, src/effs/read_dir.js

effect read_dir_at source · line 408 · raw

@path:String -> @idx:Nat -> IO(Result<&1, &1, Pair(U32, String), String>)

Fetch one directory entry by index.

foreign: src/effs/read_dir.c, src/effs/read_dir.js

effect make_dir source · line 413 · raw

@path:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)

Create one directory.

foreign: src/effs/make_dir.c, src/effs/make_dir.js

effect canonical_path source · line 418 · raw

@path:String -> IO(Result<&1, &1, Pair(U32, String), String>)

Resolves an existing database path to its filesystem identity.

foreign: src/effs/canonical_path.c, src/effs/canonical_path.js

effect chmod source · line 423 · raw

@path:String -> @bits:U32 -> IO(Result<&1, &1, Pair(U32, String), Unit>)

Set POSIX permission bits.

foreign: src/effs/chmod.c, src/effs/chmod.js

effect file_size source · line 442 · raw

@path:String -> IO(Result<&1, &1, Pair(U32, String), Nat>)

Read-only byte size for Bend-side accounting (no shell wc needed).

foreign: src/effs/file_size.c, src/effs/file_size.js