code wiki / (root) / nx_fsops_lib.nx

nx_fsops_lib.nx

buildroot/runtime/nx_fsops_lib.nx

28495 B580 linesdepth 3pulls 6 transitivereach 7 importersview sourcekind librarytopic fsops
docsdependenciesstructsconstsfunctions

about

nx_fsops_lib.nx -- CONSOLIDATED filesystem tool (MCP name: nx_fs, tool #4 of the 15), LIBRARY half. (Source is named nx_fsops because nx_fs.nx is the safety-enveloped file-I/O STDLIB -- a different thing.) READ-ONLY first increment: `read` (bounded file read) + `ls` (typed dir listing). Retires ssh-cat for remote reads per rule 27 (api-first, no shell plumbing). BOUNDARY DEFENSE (rule 12 -- MCP callers are EXTERNAL input): `read` REFUSES any path that matches the secret DENY-LIST: compiled-in default needles (secret/key/token/passw/.pem, matched case-insensitively against the WHOLE path) plus data-driven extras from fs_read_deny.conf (one lowercase needle per line, CWD-relative -- rule 11: policy in data, not code). The tools-api runs where key material lives; an arbitrary-read tool that could return opaque_keys.bin or tools_cap_secret.key would convert a read-cap into a key-theft primitive. Over-blocking is the SAFE failure direction for v1. WRITE/EDIT increment (2026-07-16): fsx_write (ATOMIC tmp+fsync+rename) + fsx_edit (exact-string replace with the Claude-Edit UNIQUENESS contract). Exposed as the SEPARATE tools-api name `nx_fs_write` (its own cap class per knowledge/mcp/exposure_policy.txt: read=broad, write=cap) -- the `nx_fs` name stays read-only. The write DENY is a superset of the read deny (never clobber key material) PLUS the OS device/kernel/ firmware namespace via the nx_os_fs seam (rule 26 never-brick BY CONSTRUCTION -- not config-disableable) PLUS the tool-registry escalation surface ("allowlist") PLUS data-driven extras (fs_write_deny.conf). license_tier: ORIGINAL

dependencies 5 imports · 5 importers

nx_syscalls.nx nx_itoa_lib.nx nx_vsz_watchdog_core.nx nx_os_fs.nx nx_os_proc.nx nx_fsops_lib.nx nx_fsops.nx nx_fsops_gate.nx nx_fsops_outline.nx nx_fsops_write.nx nx_site_publish_lib.nx

imports: nx_syscalls.nxnx_itoa_lib.nxnx_vsz_watchdog_core.nxnx_os_fs.nxnx_os_proc.nx

imported by: nx_fsops.nxnx_fsops_gate.nxnx_fsops_outline.nxnx_fsops_write.nxnx_site_publish_lib.nx

structs

none

consts

24const FSX_MAGIC_4095: i64 = 4095
26const FSX_READ_CAP: i64 = 1048576 // max bytes returned by `read` (truncation is MARKED, never silent)
27const FSX_DENY_CAP: i64 = 8192 // fs_read_deny.conf read cap
28const FSX_PATH_CAP: i64 = 1024 // lowercased path work buffer
29const FSX_DENT_BUF: i64 = 65536 // getdents64 batch buffer (matches the proven vsz/heal sizing)
30const FSX_LS_CAP: i64 = 200 // scale-law: max ls entries EMITTED; true total ALWAYS declared (65KB-dump fix)
31const FSX_RC_ABSENT: i64 = 3 // exit: path absent/unreadable (mirrors nx_fileop's exists convention)
32const FSX_RC_DENIED: i64 = 5 // exit: deny-list refused the read
33const FSX_UPPER_A: i64 = 65 // 'A' (ASCII lowercasing)
34const FSX_UPPER_Z: i64 = 90 // 'Z'
35const FSX_CASE_OFF: i64 = 32 // 'a' - 'A'
36const FSX_ASCII_0: i64 = 48 // '0' (decimal print)
121const FSX_SNIFF_CAP: i64 = 4096
318const FSX_LINES_SCAN: i64 = 1048576 // line-addressing scan window (matches the proven read cap)
319const FSX_LINES_MAXOUT: i64 = 262144 // max bytes emitted by one `lines` call (transport-friendly)
320const FSX_LINES_DEFN: i64 = 40 // default line count when the caller omits it
321const FSX_LINES_MAXN: i64 = 400 // max lines per call
385const FSX_MODE_RW: i64 = 0x1a4 // 0644 -- the ecosystem's file-create mode idiom
386const FSX_DEC: i64 = 10 // decimal base (pid rendering in the tmp suffix)
387const FSX_EDIT_OUT: i64 = 2097152 // edit output buffer (2x read cap: bounded replacement growth)
388const FSX_TMP_ROOM: i64 = 32 // reserved room for ".nxw" + pid digits + NUL in the tmp name
389const FSX_RC_IO: i64 = 4 // exit: io failure (open/short-write/rename)
390const FSX_RC_NOMATCH: i64 = 6 // exit: edit found 0 occurrences (file UNCHANGED)
391const FSX_RC_AMBIG: i64 = 7 // exit: edit found >1 occurrences without `all` (file UNCHANGED)

functions

38func fsx_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
43func fsx_putn(v: i64) -> i64 { nxi_out(v); return 0 }
45func fsx_lower(s: *u8, out: *u8, cap: i64) -> i64
58func fsx_seq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 }
69func fsx_cas_val(tok: *u8) -> *u8
called by 1: fsx_cas_ok
77func fsx_cas_ok(cur: i64, tok: *u8) -> i64
called by 1: main calls 2: fsx_cas_valfsx_seq
93func fsx_deny_hit(lp: *u8, ln: i64, needle: *u8) -> i64
100func fsx_conf_deny(lp: *u8, ln: i64, conf: *u8) -> i64
123func fsx_isalnum(c: i64) -> i64
called by 1: fsx_word_has
130func fsx_ends_with(lp: *u8, ln: i64, suf: *u8) -> i64
called by 2: fsx_basename_isfsx_denied calls 1: vw_slen
142func fsx_basename_is(lp: *u8, ln: i64, name: *u8) -> i64
called by 1: fsx_denied calls 2: vw_slenfsx_ends_with
156func fsx_word_has(lp: *u8, ln: i64, w: *u8) -> i64
181func fsx_content_secret(path: *u8) -> i64
213func fsx_denied(path: *u8) -> i64
257func fsx_fail(path: *u8, rc: i64) -> i64
270func fsx_read(path: *u8, cap: i64) -> i64
292func fsx_read_at(path: *u8, cap: i64, off: i64) -> i64
329func fsx_read_lines(path: *u8, start: i64, count: i64) -> i64
395func fsx_write_denied(path: *u8) -> i64
406func fsx_write(path: *u8, body: *u8, blen: i64) -> i64
452func fsx_count_occ(hay: *u8, hn: i64, nee: *u8, nl: i64) -> i64
called by 1: fsx_edit
465func fsx_replace(hay: *u8, hn: i64, nee: *u8, nl: i64, rep: *u8, rl: i64, out: *u8, ocap: i64, allf: i64) -> i64
called by 1: fsx_edit
499func fsx_edit(path: *u8, olds: *u8, news: *u8, allf: i64) -> i64
528func fsx_ls(dir: *u8) -> i64 { return fsx_ls_from(dir, 0) }
called by 1: main calls 1: fsx_ls_from
530func fsx_ls_from(dir: *u8, skip: i64) -> i64