code wiki / _hdl_build / nx_datacurator.nx
nx_datacurator.nx
buildroot/runtime/_hdl_build/nx_datacurator.nx
about
nx_datacurator.nx -- SOVEREIGN storage curator (WizTree / TreeSize / ncdu-class, on the NAS). Recursively walks a
target dir, stats every file (one fstatat = mode+size), classifies by MEDIA TYPE, and reports size+count per type
+ the biggest N files -- so the operator can SEE where the space is by media type and decide what to delete.
READ-ONLY: stat only; it NEVER writes or deletes (deletion is the separate soft+confirmed `del` mode). Composes the
recursive getdents walk from nx_dr_tree, but is LEAK-SAFE at scale: the per-dir getdents buffer is munmap'd on
return (nx_dr_tree leaks it -- fine for one archive, fatal walking 142 TB), and NOTHING is mmap'd per FILE (one
reused statbuf threaded down). Bounded memory regardless of file count.
Run: nx_datacurator <dir> [topN] (topN default 30, max 64)
license_tier: ORIGINAL
dependencies 1 imports · 0 importers
imports: nx_syscalls.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 DC_MAGIC_1099511627776: i64 = 1099511627776 |
| 14 | const DC_MAGIC_1073741824: i64 = 1073741824 |
| 15 | const DC_MAGIC_1048576: i64 = 1048576 |
| 16 | const DC_MAGIC_3900: i64 = 3900 |
| 17 | const DC_MAGIC_131072: i64 = 131072 |
| 18 | const DC_MAGIC_61440: i64 = 61440 |
| 19 | const DC_MAGIC_16384: i64 = 16384 |
| 20 | const DC_MAGIC_32768: i64 = 32768 |
| 21 | const DC_MAGIC_4096: i64 = 4096 |
| 22 | const DC_MAGIC_2048: i64 = 2048 |
| 23 | const DC_MAGIC_60000: i64 = 60000 |
| 24 | const DC_MAGIC_65536: i64 = 65536 |
| 26 | const DC_PATHW: i64 = 400 // bytes per stored biggest-file path |
| 27 | const DC_TOPMAX: i64 = 64 |
| 28 | const DC_NCAT: i64 = 6 // 0=video 1=image 2=audio 3=doc 4=archive 5=other |
functions
| 30 | func dc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 31 | func dc_w(s: *u8) -> i64 { sys_write(1, s, dc_slen(s)); return 0 } |
| 32 | func dc_bcat(dst: *u8, o: i64, s: *u8) -> i64 { var x: i64 = o; var i: i64 = 0; while s[i] != (0 as u8) { dst[x] = s[i]; x = x + 1; i = i + 1 } return x } |
| 33 | func dc_bcatn(dst: *u8, o: i64, v: i64) -> i64 |
| 43 | func dc_human(dst: *u8, o: i64, bytes: i64) -> i64 |
| 53 | func dc_flush(buf: *u8, n: i64) -> i64 { sys_write(1, buf, n); return 0 } |
| 56 | func dc_join(buf: *u8, base_n: i64, name: *u8) -> i64 |
| 61 | func dc_isdotdot(nm: *u8) -> i64 |
| 65 | func dc_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c } called by 1: dc_in_ci |
| 67 | func dc_in_ci(word: *u8, list: *u8) -> i64 |
| 87 | func dc_classify(nm: *u8) -> i64 |
| 100 | func dc_topn(bs: *i64, bp: *u8, nkeep: i64, path: *u8, pn: i64, sz: i64) -> i64 called by 1: dc_walk |
| 114 | func dc_walk(path: *u8, pn: i64, sb: *u8, cb: *i64, cc: *i64, bs: *i64, bp: *u8, nkeep: i64, tot: *i64) -> i64 called by 2: dc_walkmain calls 13: sys_openat_rdsys_mmapsys_getdents64dirent_namedc_isdotdotdc_join+7 |
| 158 | func dc_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 } |
| 159 | func dc_startswith(s: *u8, p: *u8) -> i64 { var i: i64 = 0; while p[i] != (0 as u8) { if s[i] != p[i] { return 0 } i = i + 1 } return 1 } called by 1: dc_pathguard |
| 160 | func dc_contains(hay: *u8, needle: *u8) -> i64 |
| 167 | func dc_pathguard(path: *u8) -> i64 |
| 182 | func dc_rm_contents(path: *u8, pn: i64, exec: i64, st: *i64, sb: *u8) -> i64 called by 2: dc_rm_contentsdc_del_main calls 11: sys_openat_rdsys_mmapsys_getdents64dirent_namedc_isdotdotdc_join+5 |
| 222 | func dc_del_main(argc: i64, argv: *i64) -> i64 |
| 261 | func dc_ext(nm: *u8) -> *u8 called by 1: dc_channel |
| 271 | func dc_channel(nm: *u8, path: *u8) -> i64 |
| 285 | func dc_chname(ch: i64) -> *u8 called by 1: dc_catalog_walk |
| 294 | func dc_catalog_walk(path: *u8, pn: i64, sb: *u8, fd: i64, wbuf: *u8, wo: *i64, chb: *i64, chc: *i64, tot: *i64) -> i64 called by 2: dc_catalog_walkdc_catalog_main calls 16: sys_openat_rdsys_mmapsys_getdents64dirent_namedc_isdotdotdc_join+10 |
| 343 | func dc_catalog_main(argc: i64, argv: *i64) -> i64 |
| 374 | func main(argc: i64, argv: *i64) -> i64 |