code wiki / _hdl_build / nx_nishifs_cow.nx
nx_nishifs_cow.nx
buildroot/runtime/_hdl_build/nx_nishifs_cow.nx
about
nx_nishifs_cow.nx -- ladder C6 (the FS): CoW SNAPSHOTS for NishiFS (Merkle structural sharing, git-style).
The payoff of content-addressing: a SNAPSHOT is just a root CID, and COPY-ON-WRITE means modifying a file
writes a NEW object (new content -> new CID) + a NEW directory -> a NEW root CID, while the OLD root still
references the OLD (unchanged) objects. So: snapshots are FREE (remember a root CID), unchanged files are
SHARED across snapshots (same CID = stored once = dedup), old snapshots are IMMUTABLE (history preserved),
and snapshots are ISOLATED (tampering a new object never affects an old snapshot). This is git's model.
KAT 6/6: T1 CoW makes a new root (old root unchanged); T2 structural sharing/dedup (unchanged file's object
is NOT duplicated -- arena does not grow, same CID); T3 snapshot immutability (root1 still reads the OLD a,
root2 reads the NEW a); T4 CoW touched only the change (a's CID changed, b's CID unchanged); T5 both snapshots
read the SHARED b object; T6 liar-kill + isolation (tamper a's NEW object -> root2 read fails integrity, but
root1 read of a is UNAFFECTED).
composes nx_sha256 (CID) + nx_syscalls. Uses an IN-MEMORY content-addressed arena (same model as the C2
file store / C4 on-disk object region; arena chosen for a self-contained sovereign KAT -- no external dirs).
NEVER-BRICK (Rule 26): writes NOTHING (pure in-memory) -- cannot touch any device, by construction. expect_exit: 0 license_tier: ORIGINAL
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnx_itoa_lib.nxnx_sha256.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 19 | const GET_MAGIC_65536: i64 = 65536 |
| 21 | const GET_OK: i64 = 0 |
| 22 | const GET_NOTFOUND: i64 = 3 |
| 23 | const GET_INTEGRITY: i64 = 7 |
functions
| 25 | func ui_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 30 | func ui_num(v: i64) -> i64 { nxi_out(v); return 0 } |
| 31 | func ui_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } called by 1: main |
| 32 | func cid_eq(a: *u8, b: *u8) -> i64 { var i: i64=0; while i<32 { if a[i]!=b[i] { return 0 } i=i+1 } return 1 } |
| 33 | func wr_u32_le(d: *u8, off: i64, v: i64) -> i64 { d[off]=(v & 0xFF) as u8; d[off+1]=((v>>8)&0xFF) as u8; d[off+2]=((v>>16)&0xFF) as u8; d[off+3]=((v>>24)&0xFF) as u8; return 0 } called by 1: arena_put |
| 34 | func rd_u32_le(d: *u8, off: i64) -> i64 { return (d[off] as i64) | ((d[off+1] as i64)<<8) | ((d[off+2] as i64)<<16) | ((d[off+3] as i64)<<24) } called by 1: arena_find |
| 37 | func arena_find(arena: *u8, endsz: i64, cid: *u8, outlen: *i64) -> i64 |
| 49 | func arena_put(arena: *u8, endp: *i64, blob: *u8, n: i64, cidout: *u8) -> i64 |
| 61 | func arena_get(arena: *u8, endsz: i64, cid: *u8, out: *u8, cap: i64, lenout: *i64) -> i64 |
| 74 | func make_dir(arena: *u8, endp: *i64, nA: *u8, cA: *u8, nB: *u8, cB: *u8, rootout: *u8) -> i64 |
| 84 | func dir_find(buf: *u8, len: i64, name: *u8, cidout: *u8) -> i64 called by 1: read_by_root |
| 97 | func read_by_root(arena: *u8, endsz: i64, root: *u8, name: *u8, out: *u8, cap: i64, lenout: *i64) -> i64 |
| 107 | func main() -> i64 |