code wiki / _hdl_build / nx_blockfs.nx

nx_blockfs.nx

buildroot/runtime/_hdl_build/nx_blockfs.nx

7878 B112 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_blockfs.nx -- SOVEREIGN on-disk FILESYSTEM (OS gap: FILESYSTEM, the block layer; complements the nx_fs coreutils file-ops tool). A block-structured FS over an arena (a RAM/disk image): block 0 = superblock (magic/nblocks/ next_free), blocks 1..16 = inode table (one inode/block: used/size/start/count/name/datasum), blocks 17.. = bump-allocated contiguous data (ADDITIVE-ONLY, rule 13: history-preserving). Own format (no ext4/FAT). Persistence: save/load the image to disk.img. Integrity: per-file checksum (tamper-evident). T1 format. T2 create 2 files + ls=2. T3 read-back byte-exact. T4 persist->clear->reload byte-exact. T5 teeth: corrupt->verify detects. expect_exit: 0 Sovereign: nx_syscalls. NEVER-BRICK: operates on RAM/an image file, writes 0 firmware.

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_g_puts_lib.nx nx_blockfs.nx

imports: nx_syscalls.nxnx_itoa_lib.nxnx_g_puts_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main g_puts sys_write sys_mmap fs_format fs_wr ino_off fs_rd fs_count fs_rd ↻ ino_off ↻ ck g_puts ↻ fs_create fs_rd ↻ ino_off ↻ fs_wr ↻ fs_setname fs_sum g_pn nxi_out nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap fs_read fs_find ino_off ↻ fs_rd ↻ fs_namematch ino_off ↻ fs_rd ↻ streq_n sys_write ↻ fs_save sys_openat_wr sys_write ↻ sys_close fs_load

structs

none

consts

19const BS: i64 = 256
20const NB: i64 = 256
21const NI: i64 = 16
22const DATA0: i64 = 17
23const MAGIC: i64 = 0x4E534653

functions

16func g_pn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
17func ck(name: *u8, c: i64) -> i64 { if c==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return c }
called by 1: main calls 1: g_puts
25func fs_rd(a: *u8, o: i64) -> i64 { var v: i64=0; var i: i64=0; while i<8 { v=v|((a[o+i] as i64)<<(i*8)); i=i+1 } return v }
26func fs_wr(a: *u8, o: i64, v: i64) -> i64 { var i: i64=0; while i<8 { a[o+i]=((v>>(i*8))&255) as u8; i=i+1 } return 0 }
called by 2: fs_formatfs_create
27func ino_off(i: i64) -> i64 { return (1+i)*BS }
29func fs_format(a: *u8) -> i64
called by 1: main calls 2: fs_wrino_off
35func fs_setname(a: *u8, boff: i64, name: *u8) -> i64 { var i: i64=0; while i<31 { if name[i]==(0 as u8) { a[boff+32+i]=0 as u8; i=31 } else { a[boff+32+i]=name[i]; i=i+1 } } a[boff+32+31]=0 as u8; return 0 }
called by 1: fs_create
36func fs_namematch(a: *u8, boff: i64, name: *u8) -> i64 { var i: i64=0; while i<32 { let cn: i64 = name[i] as i64; let cb: i64 = a[boff+32+i] as i64; if cn != cb { return 0 } if cn==0 { return 1 } i=i+1 } return 1 }
called by 1: fs_find
37func fs_sum(a: *u8, off: i64, n: i64) -> i64 { var s: i64=0; var i: i64=0; while i<n { s=s+(a[off+i] as i64); i=i+1 } return s }
called by 2: fs_createfs_verify
38func fs_find(a: *u8, name: *u8) -> i64 { var i: i64=0; while i<NI { let bo: i64=ino_off(i); if fs_rd(a,bo)==1 { if fs_namematch(a,bo,name)==1 { return i } } i=i+1 } return 0-1 }
39func fs_create(a: *u8, name: *u8, data: *u8, len: i64) -> i64
51func fs_read(a: *u8, name: *u8, out: *u8) -> i64
called by 1: main calls 3: fs_findino_offfs_rd
57func fs_verify(a: *u8, name: *u8) -> i64
called by 1: main calls 4: fs_findino_offfs_rdfs_sum
62func fs_count(a: *u8) -> i64 { var c: i64=0; var i: i64=0; while i<NI { if fs_rd(a,ino_off(i))==1 { c=c+1 } i=i+1 } return c }
called by 1: main calls 2: fs_rdino_off
63func fs_save(a: *u8, path: *u8) -> i64 { let fd: i64=sys_openat_wr(path,0x1a4); if fd<0 { return 0-1 } sys_write(fd,a,NB*BS); sys_close(fd); return 0 }
64func fs_load(a: *u8, path: *u8) -> i64 { let fd: i64=sys_openat_rd(path); if fd<0 { return 0-1 } var t: i64=0; var go: i64=1; while go==1 { let k: i64=sys_read(fd,a+t as i64,NB*BS-t); if k<=0 { go=0 } else { t=t+k } } sys_close(fd); return t }
called by 1: main calls 3: sys_openat_rdsys_readsys_close
65func streq_n(a: *u8, b: *u8, n: i64) -> i64 { var i: i64=0; while i<n { if a[i]!=b[i] { return 0 } i=i+1 } return 1 }
called by 1: main
67func main() -> i64