code wiki / (root) / nx_tmpstore_reap.nx

nx_tmpstore_reap.nx

buildroot/runtime/nx_tmpstore_reap.nx

17471 B372 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_tmpstore_reap.nx -- GUARDED reaper for orphaned scratch seg-store families in a temp dir (2026-08-12, debt 1786544135 item 4). /tmp measured at 68,730 files, dominated by one-shot organs' scratch stores: <prefix>-<num>-seg-<num>.{docs,idx,pos,imp} + -manifest.txt + -slock. capsearch proved NO incumbent covers this class (nx_orphan_reap=processes, nx_toolreg_reap=registry rows, nx_eqtmp_reap=the legacy equiv-gate temps only, measured already_clean=19/19). SAFETY BY CONSTRUCTION (this deletes, so every rule is load-bearing): (1) FAMILY-scoped: only names matching the three store shapes are ever considered; everything else is counted as other and NEVER touched. (2) AGE-bounded: a family is reapable only if its NEWEST member mtime is older than minage. (3) WRITER-aware: if the family has a -slock, a non-blocking flock EX probe must SUCCEED (no writer holds it); a held lock -> the family is KEPT. Probe lock released immediately. (4) DRY BY DEFAULT: reap deletes only when argv literally says apply. (5) NO SILENT CAPS: more than MAX_FAM families -> REFUSE (exit 3), never a partial sweep published as a total. (6) The partition is printed AND summed: families == reaped + young + held. verbs: scan <dir> | reap <dir> <minage_secs> [apply] | selftest license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_gate_verdict.nx nx_tmpstore_reap.nx

imports: nx_syscalls.nxnx_gate_verdict.nx

imported by: nobody (leaf or entry point)

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

main tr_selftest gv_ctr sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ gv_head gv_puts sys_write ↻ sys_mkdir tr_mkfile sys_openat_wr sys_write ↻ tr_len sys_close tr_age sys_mmap ↻ sys_now_realtime_sec sys_mmap ↻ sys_clock_gettime_real sys_utimensat sys_openat_rd sys_flock tr_run tr_init sys_mmap ↻ sys_mmap ↻ tr_census

structs

none

consts

20const TR_MAGIC_2166136261: i64 = 2166136261
21const TR_MAGIC_16777619: i64 = 16777619
22const TR_MAGIC_65536: i64 = 65536
23const TR_MAGIC_4096: i64 = 4096
24const TR_MAGIC_7200: i64 = 7200
25const TR_MAGIC_3600: i64 = 3600
27const TR_MAX_FAM: i64 = 16384
28const TR_NAME_CAP: i64 = 96
29const TR_HT_SLOTS: i64 = 32768
30const TR_MODE_644: i64 = 420

functions

32func tr_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
33func tr_p(s: *u8) -> i64 { sys_write(1, s, tr_len(s)); return 0 }
called by 3: tr_reporttr_runmain calls 2: sys_writetr_len
34func tr_pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); let t: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} 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); sys_munmap(b,28); sys_munmap(t,28); return 0 }
35func tr_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; while s[i]!=(0 as u8){ let c: i64=s[i] as i64; if c<48 {return v} if c>57 {return v} v=v*10+(c-48); i=i+1 } return v }
called by 1: main
36func tr_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64=0; var p: i64=o; while s[i]!=(0 as u8){d[p]=s[i];p=p+1;i=i+1} d[p]=0 as u8; return p }
37func tr_catb(d: *u8, o: i64, s: *u8, n: i64) -> i64 { var i: i64=0; var p: i64=o; while i<n {d[p]=s[i];p=p+1;i=i+1} d[p]=0 as u8; return p }
called by 2: tr_censustr_sweep
40func tr_ends(name: *u8, n: i64, suf: *u8) -> i64
called by 2: tr_keylentr_census calls 1: tr_len
48func tr_find(name: *u8, n: i64, needle: *u8) -> i64
called by 1: tr_keylen calls 1: tr_len
62func tr_keylen(name: *u8, n: i64) -> i64
called by 2: tr_censustr_sweep calls 2: tr_findtr_ends
73func tr_fnv(s: *u8, n: i64) -> i64
called by 1: tr_fam
80func tr_getdents(fd: i64, buf: *u8, count: i64) -> i64 { return __syscall(217, fd, buf, count, 0, 0, 0) }
called by 2: tr_censustr_sweep
91func tr_init() -> i64
called by 1: tr_run calls 1: sys_mmap
104func tr_fam(key: *u8, kl: i64) -> i64
called by 2: tr_censustr_sweep calls 1: tr_fnv
139func tr_census(dir: *u8, obox: *i64) -> i64
185func tr_judge(dir: *u8, minage: i64, rbox: *i64) -> i64
216func tr_sweep(dir: *u8) -> i64
249func tr_report(matched: i64, other: i64, rbox: *i64, gone: i64, applied: i64) -> i64
called by 1: tr_run calls 2: tr_ptr_pn
263func tr_run(dir: *u8, minage: i64, apply: i64) -> i64
280func tr_mkfile(path: *u8, content: *u8) -> i64
287func tr_age(path: *u8, secs_ago: i64) -> i64
293func tr_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
called by 1: tr_selftest calls 2: sys_openat_rdsys_close
295func tr_selftest() -> i64
340func main(argc: i64, argv: *i64) -> i64