code wiki / _hdl_build / nx_blockfs.nx
nx_blockfs.nx
buildroot/runtime/_hdl_build/nx_blockfs.nx
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
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
structs
| none |
consts
| 19 | const BS: i64 = 256 |
| 20 | const NB: i64 = 256 |
| 21 | const NI: i64 = 16 |
| 22 | const DATA0: i64 = 17 |
| 23 | const MAGIC: i64 = 0x4E534653 |
functions
| 16 | func g_pn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 17 | func 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 } |
| 25 | func 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 } |
| 26 | func 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 } |
| 27 | func ino_off(i: i64) -> i64 { return (1+i)*BS } |
| 29 | func fs_format(a: *u8) -> i64 |
| 35 | func 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 |
| 36 | func 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 |
| 37 | func 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 } |
| 38 | func 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 } |
| 39 | func fs_create(a: *u8, name: *u8, data: *u8, len: i64) -> i64 |
| 51 | func fs_read(a: *u8, name: *u8, out: *u8) -> i64 |
| 57 | func fs_verify(a: *u8, name: *u8) -> i64 |
| 62 | func 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 } |
| 63 | func 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 } |
| 64 | func 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 } |
| 65 | func 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 |
| 67 | func main() -> i64 |