code wiki / _hdl_build / nx_nishifs_cow.nx

nx_nishifs_cow.nx

buildroot/runtime/_hdl_build/nx_nishifs_cow.nx

11354 B177 linesdepth 5pulls 6 transitivereach 0 importersview sourcekind tooltopic nishifs
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_itoa_lib.nx nx_sha256.nx nx_nishifs_cow.nx

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

main ui_puts sys_write ui_slen sys_mmap arena_put sha256_digest sys_mmap ↻ sha256_init sys_mmap ↻ sha256_k sha256_update sha256_compress_ni_blocks blk_set_byte sha256_compress sha256_compress_ni blk_word blk_byte sha256_final blk_set_byte ↻ sha256_compress ↻ sys_mmap ↻ arena_find rd_u32_le wr_u32_le make_dir sys_mmap ↻ arena_put ↻ read_by_root sys_mmap ↻ arena_get sys_mmap ↻ arena_find ↻ sha256_digest ↻ cid_eq dir_find arena_find ↻ cid_eq ↻ ui_num nxi_out

structs

none

consts

19const GET_MAGIC_65536: i64 = 65536
21const GET_OK: i64 = 0
22const GET_NOTFOUND: i64 = 3
23const GET_INTEGRITY: i64 = 7

functions

25func 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 }
called by 1: main calls 1: sys_write
30func ui_num(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
31func ui_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 1: main
32func 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 }
called by 2: arena_getmain
33func 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
34func 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
37func arena_find(arena: *u8, endsz: i64, cid: *u8, outlen: *i64) -> i64
called by 3: arena_putarena_getmain calls 1: rd_u32_le
49func arena_put(arena: *u8, endp: *i64, blob: *u8, n: i64, cidout: *u8) -> i64
61func arena_get(arena: *u8, endsz: i64, cid: *u8, out: *u8, cap: i64, lenout: *i64) -> i64
74func make_dir(arena: *u8, endp: *i64, nA: *u8, cA: *u8, nB: *u8, cB: *u8, rootout: *u8) -> i64
called by 1: main calls 2: sys_mmaparena_put
84func dir_find(buf: *u8, len: i64, name: *u8, cidout: *u8) -> i64
called by 1: read_by_root
97func read_by_root(arena: *u8, endsz: i64, root: *u8, name: *u8, out: *u8, cap: i64, lenout: *i64) -> i64
called by 1: main calls 3: sys_mmaparena_getdir_find
107func main() -> i64