code wiki / _hdl_build / nx_nishifs_mount.nx
nx_nishifs_mount.nx
buildroot/runtime/_hdl_build/nx_nishifs_mount.nx
about
nx_nishifs_mount.nx -- ladder C4 (installer/disk INTEGRATION): FORMAT + MOUNT NishiFS on a C1 partition.
Unifies C1 (MBR partition table) + C2 (content-addressed CID/Merkle store) into ONE formatted, mountable
disk image -- the brick the installer (C3) lays onto a target. Layout of the disk FILE:
sector 0 : MBR -- partition table @446, one bootable(0x80) Nishi(0x9E) partition @ LBA 1, sig 0x55AA
partition (LBA 1+) : [superblock 512B] [object region] [directory]
superblock : magic "NISHIFS1" | root_CID(32) | obj_count | objstart_rel | dir_off_rel | dir_len
object region : packed records [CID(32)][len(u32 LE)][bytes] (content-addressed: located BY CID)
directory : packed entries [name\0][childCID(32)] ; its sha256 == the superblock root_CID
MOUNT executes the REAL parse path (off the persisted, re-read bytes, like the C1/C3 boot proofs):
parse MBR partition table -> find the Nishi partition -> read superblock magic -> recompute the directory
CID and require it == the stored root_CID (WHOLE-FS integrity) -> look up a file by name -> get its CID ->
find the object by CID -> require the object bytes re-hash to that CID (INTEGRITY-ON-READ) -> return bytes.
KAT 6/6: T1 format+mount round-trip (read a file back through the full chain); T2 partition parsed from the
C1 table (0x80/0x9E, not hardcoded); T3 superblock magic + root_CID present; T4 liar-kill: tamper an OBJECT
-> MNT_INTEGRITY; T5 liar-kill: tamper the DIRECTORY -> MNT_ROOT_MISMATCH (whole-FS tamper-evident);
T6 it all runs off the PERSISTED + re-read disk file.
composes nx_sha256 (CID) + nx_syscalls; reuses the C1 partition-entry format + the C2 CID/Merkle model.
NEVER-BRICK (Rule 26): writes a FILE (/tmp/nishi_fs_disk.img), no /dev. expect_exit: 0 license_tier: ORIGINAL
dependencies 2 imports · 0 importers
imports: nx_syscalls.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
| 24 | const DISK_SZ: i64 = 4096 // 8 sectors |
| 25 | const PBYTE: i64 = 512 // partition starts at LBA 1 |
| 26 | const OBJSTART_REL: i64 = 512 // object region starts right after the 512B superblock |
| 27 | const PART_TYPE_NISHI: i64 = 0x9E |
| 28 | const MNT_OK: i64 = 0 |
| 29 | const MNT_BADMAGIC: i64 = 1 |
| 30 | const MNT_ROOT_MISMATCH: i64 = 2 |
| 31 | const MNT_NOTFOUND: i64 = 3 |
| 32 | const MNT_INTEGRITY: i64 = 4 |
functions
| 34 | 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 } |
| 35 | func ui_num(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } |
| 36 | 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 |
| 37 | 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 } called by 1: mount_read |
| 38 | 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 } |
| 39 | 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) } |
| 41 | func sha_slice(d: *u8, off: i64, len: i64, out: *u8) -> i64 { sha256_digest(((d as i64)+off) as *u8, len, out); return 0 } |
| 44 | func put_obj(d: *u8, cursor: i64, blob: *u8, n: i64, cidout: *u8) -> i64 |
| 52 | func find_obj(d: *u8, start: i64, endb: i64, cid: *u8, outlen: *i64) -> i64 |
| 65 | func dir_find(d: *u8, base: i64, len: i64, name: *u8, cidout: *u8) -> i64 called by 1: mount_read |
| 85 | func format_disk(d: *u8, nameA: *u8, A: *u8, nA: i64, nameB: *u8, B: *u8, nB: i64) -> i64 |
| 122 | func mount_read(d: *u8, name: *u8, out: *u8, cap: i64, lenout: *i64) -> i64 |
| 162 | func ui_read(path: *u8, out: *u8, cap: i64) -> i64 |
| 171 | func main() -> i64 |