code wiki / _hdl_build / nx_treepack.nx
nx_treepack.nx
buildroot/runtime/_hdl_build/nx_treepack.nx
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
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
structs
| none |
consts
| 13 | const K_MAGIC_3900: i64 = 3900 |
| 14 | const K_MAGIC_131072: i64 = 131072 |
| 15 | const K_MAGIC_1048576: i64 = 1048576 |
| 16 | const K_MAGIC_4000: i64 = 4000 |
| 17 | const K_MAGIC_4096: i64 = 4096 |
| 115 | const TP_SYMBUF: i64 = 4194304 // largest .nx source compared whole (nx_hostctl.nx ~281KB; 14x headroom) |
| 116 | const TP_SYMCAP: i64 = 1048576 // symbol csv per side |
| 117 | const TP_DOT: i64 = 46 |
| 118 | const TP_NAMEMAX: i64 = 256 |
| 162 | const TP_SYS_FSTAT: i64 = 5 |
| 163 | const TP_SYS_NEWFSTATAT: i64 = 262 |
| 164 | const TP_AT_FDCWD: i64 = 0 - 100 |
| 165 | const TP_STATBUF: i64 = 256 |
| 166 | const TP_OFF_MTIME: i64 = 88 |
functions
| 19 | func 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 } |
| 20 | func 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 } |
| 23 | func tp_readn(fd: i64, buf: *u8, n: i64) -> i64 |
| 28 | func 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 |
| 29 | func 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 |
| 30 | func 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 |
| 31 | func 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 |
| 33 | func 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 |
| 35 | func tp_unlink(path: *u8) -> i64 { return sys_unlinkat(path) } |
| 36 | func 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 |
| 37 | func 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 } |
| 42 | func tp_pack_walk(src: *u8, src_n: i64, rootlen: i64, packfd: i64, hbuf: *u8, cbuf: *u8, st: *i64) -> i64 called by 2: tp_pack_walkmain calls 15: sys_openat_rdsys_mmapsys_getdents64dirent_typedirent_nametp_isdotdot+9 |
| 91 | func tp_mkparents(fpath: *u8, dest_n: i64) -> i64 |
| 126 | func tp_sym_init() -> i64 |
| 138 | func tp_is_nx(p: *u8) -> i64 called by 1: tp_unpack |
| 148 | func tp_read_file(path: *u8, b: *u8, cap: i64) -> i64 |
| 170 | func tp_fd_mtime(fd: i64) -> i64 |
| 177 | func tp_path_mtime(path: *u8) -> i64 |
| 185 | func tp_unpack(packfd: i64, fpath: *u8, dest_n: i64, hbuf: *u8, cbuf: *u8, st: *i64, packmt: i64, force: i64) -> i64 |
| 299 | func main(argc: i64, argv: *i64) -> i64 |