nx_tmpstore_reap.nx
buildroot/runtime/nx_tmpstore_reap.nx
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
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
structs
| none |
consts
| 20 | const TR_MAGIC_2166136261: i64 = 2166136261 |
| 21 | const TR_MAGIC_16777619: i64 = 16777619 |
| 22 | const TR_MAGIC_65536: i64 = 65536 |
| 23 | const TR_MAGIC_4096: i64 = 4096 |
| 24 | const TR_MAGIC_7200: i64 = 7200 |
| 25 | const TR_MAGIC_3600: i64 = 3600 |
| 27 | const TR_MAX_FAM: i64 = 16384 |
| 28 | const TR_NAME_CAP: i64 = 96 |
| 29 | const TR_HT_SLOTS: i64 = 32768 |
| 30 | const TR_MODE_644: i64 = 420 |
functions
| 32 | func tr_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 33 | func tr_p(s: *u8) -> i64 { sys_write(1, s, tr_len(s)); return 0 } |
| 34 | func 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 } |
| 35 | func 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 |
| 36 | func 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 } |
| 37 | func 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 } |
| 40 | func tr_ends(name: *u8, n: i64, suf: *u8) -> i64 |
| 48 | func tr_find(name: *u8, n: i64, needle: *u8) -> i64 |
| 62 | func tr_keylen(name: *u8, n: i64) -> i64 |
| 73 | func tr_fnv(s: *u8, n: i64) -> i64 called by 1: tr_fam |
| 80 | func tr_getdents(fd: i64, buf: *u8, count: i64) -> i64 { return __syscall(217, fd, buf, count, 0, 0, 0) } |
| 91 | func tr_init() -> i64 |
| 104 | func tr_fam(key: *u8, kl: i64) -> i64 |
| 139 | func tr_census(dir: *u8, obox: *i64) -> i64 |
| 185 | func tr_judge(dir: *u8, minage: i64, rbox: *i64) -> i64 |
| 216 | func tr_sweep(dir: *u8) -> i64 |
| 249 | func tr_report(matched: i64, other: i64, rbox: *i64, gone: i64, applied: i64) -> i64 |
| 263 | func tr_run(dir: *u8, minage: i64, apply: i64) -> i64 |
| 280 | func tr_mkfile(path: *u8, content: *u8) -> i64 |
| 287 | func tr_age(path: *u8, secs_ago: i64) -> i64 |
| 293 | func tr_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } |
| 295 | func tr_selftest() -> i64 |
| 340 | func main(argc: i64, argv: *i64) -> i64 |