code wiki / _hdl_build / nx_nishifs_mount.nx

nx_nishifs_mount.nx

buildroot/runtime/_hdl_build/nx_nishifs_mount.nx

13290 B229 linesdepth 5pulls 5 transitivereach 0 importersview sourcekind tooltopic nishifs
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_sha256.nx nx_nishifs_mount.nx

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

main ui_puts sys_write ui_slen sys_mmap format_disk wr_u32_le sys_mmap ↻ put_obj 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 sha256_final blk_set_byte ↻ sha256_compress ↻ wr_u32_le ↻ sha_slice sha256_digest ↻ sys_openat_wr sys_exit sys_write ↻ sys_close ui_read sys_openat_rd sys_read sys_close ↻ ui_num sys_mmap ↻ sys_write ↻ mount_read rd_u32_le sys_mmap ↻

structs

none

consts

24const DISK_SZ: i64 = 4096 // 8 sectors
25const PBYTE: i64 = 512 // partition starts at LBA 1
26const OBJSTART_REL: i64 = 512 // object region starts right after the 512B superblock
27const PART_TYPE_NISHI: i64 = 0x9E
28const MNT_OK: i64 = 0
29const MNT_BADMAGIC: i64 = 1
30const MNT_ROOT_MISMATCH: i64 = 2
31const MNT_NOTFOUND: i64 = 3
32const MNT_INTEGRITY: i64 = 4

functions

34func 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
35func 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 }
called by 1: main calls 2: sys_mmapsys_write
36func ui_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 1: main
37func 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
38func 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 2: put_objformat_disk
39func 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) }
41func sha_slice(d: *u8, off: i64, len: i64, out: *u8) -> i64 { sha256_digest(((d as i64)+off) as *u8, len, out); return 0 }
called by 2: format_diskmount_read calls 1: sha256_digest
44func put_obj(d: *u8, cursor: i64, blob: *u8, n: i64, cidout: *u8) -> i64
called by 1: format_disk calls 2: sha256_digestwr_u32_le
52func find_obj(d: *u8, start: i64, endb: i64, cid: *u8, outlen: *i64) -> i64
called by 1: mount_read calls 1: rd_u32_le
65func dir_find(d: *u8, base: i64, len: i64, name: *u8, cidout: *u8) -> i64
called by 1: mount_read
85func format_disk(d: *u8, nameA: *u8, A: *u8, nA: i64, nameB: *u8, B: *u8, nB: i64) -> i64
122func mount_read(d: *u8, name: *u8, out: *u8, cap: i64, lenout: *i64) -> i64
162func ui_read(path: *u8, out: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
171func main() -> i64