nx_lease_lib.nx
buildroot/runtime/nx_lease_lib.nx
about
nx_lease_lib.nx -- THE SOVEREIGN LEASE PRIMITIVE as a LIBRARY (extracted VERBATIM from the NAS nx_lease.nx,
sha c9eaf727, 2026-09-03, so organs can COMPOSE it instead of forking nx_lease.elf per acquire). Semantics unchanged:
first claim by O_CREAT|O_EXCL after an atomic mkdir; takeover of a stale/released lease arbitrated by mkdir on a
MONOTONIC GENERATION (stamp field 5 -- never a nonce, see the reverted 2026-08-08 wedge in ls_claim); RELEASE flips
the stamp to released and NEVER unlinks (lock dirs are additive). Stamp = one line:
held|released<TAB>owner<TAB>epoch<TAB>ttl<TAB>generation
NEW here: *_root variants so a caller pins ONE lease root regardless of its CWD, and ls_holder_of for pools that
reclaim a dead holder by the OWNER it wrote. nx_lease.nx = this + its CLI main (incl. the forked-racer tooth 8).
license_tier: ORIGINAL No hw writes (Rule 26).
dependencies 2 imports · 4 importers
imports: nx_syscalls.nxnx_srcfresh.nx
imported by: nx_bright_rewrite_lib.nxnx_heavyio_lib.nxnx_lease.nxnx_lease_wedge_gate.nx
structs
| none |
consts
| 12 | const LS_MAGIC_3600: i64 = 3600 |
| 14 | const LS_STDERR: i64 = 2 |
| 15 | const LS_PATHCAP: i64 = 256 |
| 16 | const LS_STAMPCAP: i64 = 512 |
| 17 | const LS_MODE: i64 = 0x1a4 |
| 18 | const LS_DMODE: i64 = 0x1ed |
| 19 | const LS_MKDIRAT: i64 = 258 |
| 20 | const LS_ATFDCWD: i64 = 0 - 100 |
| 21 | const LS_GETPID: i64 = 172 |
| 22 | const LS_TAB: i64 = 9 |
| 23 | const LS_NL: i64 = 10 |
| 24 | const LS_D0: i64 = 48 |
| 25 | const LS_D9: i64 = 57 |
| 26 | const LS_B10: i64 = 10 |
| 27 | const LS_NUMB: i64 = 24 |
| 28 | const LS_EXIT_USAGE: i64 = 2 |
| 29 | const LS_EXIT_BUSY: i64 = 3 |
| 30 | const LS_EXIT_IO: i64 = 4 |
| 31 | const LS_EXIT_SELF: i64 = 5 |
| 32 | const LS_V_A: i64 = 97 |
| 33 | const LS_V_R: i64 = 114 |
| 34 | const LS_V_C: i64 = 99 |
| 35 | const LS_V_S: i64 = 115 |
| 36 | const LS_NONCE_MOD: i64 = 1000000 |
| 102 | const LS_OPENAT: i64 = 257 |
| 103 | const LS_O_EXCL_WR: i64 = 0xc1 |
| 118 | const LS_DEFAULT_ROOT: *u8 = "knowledge/lease/" |
| 267 | const LS_ORPHAN_MIN_S: i64 = 30 |
| 268 | const LS_UNLINKAT: i64 = 263 |
| 269 | const LS_AT_REMOVEDIR: i64 = 512 |
functions
| 38 | func ls_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } called by 1: ls_werr |
| 39 | func ls_werr(s: *u8) -> i64 { sys_write(LS_STDERR, s, ls_slen(s)); return 0 } |
| 40 | func ls_wn(v: i64) -> i64 |
| 53 | func ls_cat(d: *u8, off: i64, s: *u8) -> i64 |
| 59 | func ls_catn(d: *u8, off: i64, v: i64) -> i64 |
| 71 | func ls_eq(a: *u8, b: *u8) -> i64 called by 1: ls_release_root |
| 78 | func ls_name_ok(s: *u8) -> i64 called by 1: main |
| 104 | func ls_open_excl(p: *u8) -> i64 { return __syscall(LS_OPENAT, LS_ATFDCWD, p as i64, LS_O_EXCL_WR, LS_MODE, 0, 0) } called by 1: ls_claim |
| 108 | func ls_mkdir(p: *u8) -> i64 { return __syscall(LS_MKDIRAT, LS_ATFDCWD, p as i64, LS_DMODE, 0, 0, 0) } |
| 111 | func ls_dirpath_root(root: *u8, name: *u8, out: *u8) -> i64 |
| 119 | func ls_dirpath(name: *u8, out: *u8) -> i64 { return ls_dirpath_root(LS_DEFAULT_ROOT, name, out) } calls 1: ls_dirpath_root |
| 120 | func ls_read(path: *u8, buf: *u8, cap: i64) -> i64 called by 4: ls_probe_rootsls_acquire_rootls_release_rootls_holder_of calls 3: sys_openat_rdsys_readsys_close |
| 140 | func ls_parse2(buf: *u8, n: i64, ob: *u8, obcap: i64) -> i64 |
| 189 | func ls_claim(dir: *u8, owner: *u8, ttl: i64, gen: i64, gate: i64) -> i64 called by 1: ls_acquire_root calls 9: sys_mmapls_catls_catnsys_now_realtime_secls_open_exclsys_write+3 |
| 270 | func ls_rmdir(p: *u8) -> i64 { return __syscall(LS_UNLINKAT, LS_ATFDCWD, p as i64, LS_AT_REMOVEDIR, 0, 0, 0) } |
| 271 | func ls_orphan_age_s(ttl: i64) -> i64 { if ttl > LS_ORPHAN_MIN_S { return ttl } return LS_ORPHAN_MIN_S } |
| 273 | func ls_path_age_s(p: *u8) -> i64 |
| 280 | func ls_claim_takeover(dir: *u8, sp: *u8, sb: *u8, so: i64, gen: i64, gate: i64, orphan_age_s: i64) -> i64 |
| 311 | func ls_claim_x(dir: *u8, owner: *u8, ttl: i64, gen: i64, gate: i64, orphan_age_s: i64) -> i64 |
| 334 | func ls_stamp_path(dir: *u8, out: *u8) -> i64 |
| 341 | func ls_unclaim(dir: *u8, owner: *u8, nonce: i64) -> i64 called by 1: ls_release_root calls 9: sys_mmapls_stamp_pathls_catls_catnsys_now_realtime_secsys_openat_wr+3 |
| 372 | func ls_pid() -> i64 { return __syscall(LS_GETPID, 0, 0, 0, 0, 0, 0) } |
| 374 | func ls_acquire_root(root: *u8, name: *u8, owner: *u8, ttl: i64, hb: *u8) -> i64 |
| 452 | func ls_release_root(root: *u8, name: *u8, owner: *u8) -> i64 |
| 474 | func ls_acquire(name: *u8, owner: *u8, ttl: i64, hb: *u8) -> i64 |
| 478 | func ls_release(name: *u8, owner: *u8) -> i64 { return ls_release_root(LS_DEFAULT_ROOT, name, owner) } |
| 482 | func ls_holder_of(root: *u8, name: *u8, hb: *u8) -> i64 |