code wiki / _hdl_build / nx_treepack.nx

nx_treepack.nx

buildroot/runtime/_hdl_build/nx_treepack.nx

21559 B349 linesdepth 4pulls 4 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_treepack.nx -- SOVEREIGN single-blob tree archive. Packs a directory tree into ONE .pack file (and unpacks it) so a whole source tree (runtime/ = ~14,765 files / 72.6 MB) moves in ONE /api/upload instead of ~14,765 per-file SSH pushes (hours). THE keystone primitive for build-over-API + source-search-API (both need the source tree on the NAS). Format (streaming, length-prefixed): "NXPK1\n" then repeat { u32 LE pathlen | path (forward-slash, relative to pack root) | u64 LE size | size bytes }. Dirs are implicit (mkdir -p on unpack). Additive-safe: pack reads only; unpack writes only under dest. Reuses nx_dr_tree's getdents walk pattern. Buffers hoisted (shared cbuf/hbuf passed down; per-dir dbuf) -- no mmap in the per-file inner loops. nx_treepack pack <src-dir> <out.pack> nx_treepack unpack <in.pack> <dest-dir> license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_symdrop.nx nx_treepack.nx

imports: nx_syscalls.nxnx_symdrop.nx

imported by: nobody (leaf or entry point)

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

main tp_w sys_write sys_exit sys_mmap sys_openat_wr sys_write ↻ tp_pack_walk sys_openat_rd sys_mmap ↻ sys_getdents64 dirent_type dirent_name tp_isdotdot tp_join tp_pack_walk ↻ tp_size sys_openat_rd ↻ sys_lseek sys_close tp_put32 sys_write ↻ tp_put64 sys_read sys_close ↻ dirent_reclen sys_close ↻ tp_wn sys_write ↻ sys_mmap ↻ sys_openat_rd ↻ sys_mkdir tp_fd_mtime sys_mmap ↻ tp_unpack tp_sym_init sys_mmap ↻ tp_readn sys_read ↻ tp_w ↻

structs

none

consts

13const K_MAGIC_3900: i64 = 3900
14const K_MAGIC_131072: i64 = 131072
15const K_MAGIC_1048576: i64 = 1048576
16const K_MAGIC_4000: i64 = 4000
17const K_MAGIC_4096: i64 = 4096
115const TP_SYMBUF: i64 = 4194304 // largest .nx source compared whole (nx_hostctl.nx ~281KB; 14x headroom)
116const TP_SYMCAP: i64 = 1048576 // symbol csv per side
117const TP_DOT: i64 = 46
118const TP_NAMEMAX: i64 = 256
162const TP_SYS_FSTAT: i64 = 5
163const TP_SYS_NEWFSTATAT: i64 = 262
164const TP_AT_FDCWD: i64 = 0 - 100
165const TP_STATBUF: i64 = 256
166const TP_OFF_MTIME: i64 = 88

functions

19func tp_w(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 2: tp_unpackmain calls 1: sys_write
20func tp_wn(v: i64) -> i64 { var t:i64=v; if t<0{sys_write(1,"-" as *u8,1);t=0-t} let tm:*u8=sys_mmap(24); var k:i64=0; if t==0{tm[0]=48 as u8;k=1} while t>0{tm[k]=(48+(t%10)) as u8;t=t/10;k=k+1} let b:*u8=sys_mmap(24); var j:i64=0; while j<k{b[j]=tm[k-1-j];j=j+1} sys_write(1,b,k); return 0 }
called by 1: main calls 2: sys_writesys_mmap
23func tp_readn(fd: i64, buf: *u8, n: i64) -> i64
called by 1: tp_unpack calls 1: sys_read
28func tp_put32(b: *u8, v: i64) -> i64 { b[0]=(v&0xff) as u8; b[1]=((v>>8)&0xff) as u8; b[2]=((v>>16)&0xff) as u8; b[3]=((v>>24)&0xff) as u8; return 0 }
called by 1: tp_pack_walk
29func tp_put64(b: *u8, v: i64) -> i64 { var i:i64=0; while i<8 { b[i]=((v>>(i*8))&0xff) as u8; i=i+1 } return 0 }
called by 1: tp_pack_walk
30func tp_get32(b: *u8) -> i64 { return (b[0] as i64) | ((b[1] as i64)<<8) | ((b[2] as i64)<<16) | ((b[3] as i64)<<24) }
called by 1: tp_unpack
31func tp_get64(b: *u8) -> i64 { var v:i64=0; var i:i64=0; while i<8 { v = v | ((b[i] as i64)<<(i*8)); i=i+1 } return v }
called by 1: tp_unpack
33func tp_isdotdot(nm: *u8) -> i64 { if nm[0]==(46 as u8){ if nm[1]==(0 as u8){return 1} if nm[1]==(46 as u8){ if nm[2]==(0 as u8){return 1} } } return 0 }
called by 1: tp_pack_walk
36func tp_join(buf: *u8, base_n: i64, name: *u8) -> i64 { buf[base_n]=47 as u8; var o:i64=base_n+1; var i:i64=0; while name[i]!=(0 as u8){buf[o]=name[i];o=o+1;i=i+1} return o }
called by 1: tp_pack_walk
37func tp_size(path: *u8) -> i64 { let fd:i64=sys_openat_rd(path); if fd<0 {return 0-1} let s:i64=sys_lseek(fd,0,2); sys_close(fd); return s }
42func tp_pack_walk(src: *u8, src_n: i64, rootlen: i64, packfd: i64, hbuf: *u8, cbuf: *u8, st: *i64) -> i64
91func tp_mkparents(fpath: *u8, dest_n: i64) -> i64
called by 1: tp_unpack calls 1: sys_mkdir
126func tp_sym_init() -> i64
called by 1: tp_unpack calls 1: sys_mmap
138func tp_is_nx(p: *u8) -> i64
called by 1: tp_unpack
148func tp_read_file(path: *u8, b: *u8, cap: i64) -> i64
170func tp_fd_mtime(fd: i64) -> i64
called by 1: main calls 1: sys_mmap
177func tp_path_mtime(path: *u8) -> i64
called by 1: tp_unpack calls 1: sys_mmap
185func tp_unpack(packfd: i64, fpath: *u8, dest_n: i64, hbuf: *u8, cbuf: *u8, st: *i64, packmt: i64, force: i64) -> i64
299func main(argc: i64, argv: *i64) -> i64