code wiki / (root) / nx_lease_lib.nx

nx_lease_lib.nx

buildroot/runtime/nx_lease_lib.nx

25315 B492 linesdepth 6pulls 6 transitivereach 23 importersview sourcekind library
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_srcfresh.nx nx_lease_lib.nx nx_bright_rewrite_lib.nx nx_heavyio_lib.nx nx_lease.nx nx_lease_wedge_gate.nx

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

12const LS_MAGIC_3600: i64 = 3600
14const LS_STDERR: i64 = 2
15const LS_PATHCAP: i64 = 256
16const LS_STAMPCAP: i64 = 512
17const LS_MODE: i64 = 0x1a4
18const LS_DMODE: i64 = 0x1ed
19const LS_MKDIRAT: i64 = 258
20const LS_ATFDCWD: i64 = 0 - 100
21const LS_GETPID: i64 = 172
22const LS_TAB: i64 = 9
23const LS_NL: i64 = 10
24const LS_D0: i64 = 48
25const LS_D9: i64 = 57
26const LS_B10: i64 = 10
27const LS_NUMB: i64 = 24
28const LS_EXIT_USAGE: i64 = 2
29const LS_EXIT_BUSY: i64 = 3
30const LS_EXIT_IO: i64 = 4
31const LS_EXIT_SELF: i64 = 5
32const LS_V_A: i64 = 97
33const LS_V_R: i64 = 114
34const LS_V_C: i64 = 99
35const LS_V_S: i64 = 115
36const LS_NONCE_MOD: i64 = 1000000
102const LS_OPENAT: i64 = 257
103const LS_O_EXCL_WR: i64 = 0xc1
118const LS_DEFAULT_ROOT: *u8 = "knowledge/lease/"
267const LS_ORPHAN_MIN_S: i64 = 30
268const LS_UNLINKAT: i64 = 263
269const LS_AT_REMOVEDIR: i64 = 512

functions

38func 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
39func ls_werr(s: *u8) -> i64 { sys_write(LS_STDERR, s, ls_slen(s)); return 0 }
40func ls_wn(v: i64) -> i64
called by 1: main calls 2: sys_writesys_mmap
53func ls_cat(d: *u8, off: i64, s: *u8) -> i64
59func ls_catn(d: *u8, off: i64, v: i64) -> i64
71func ls_eq(a: *u8, b: *u8) -> i64
called by 1: ls_release_root
78func ls_name_ok(s: *u8) -> i64
called by 1: main
104func 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
108func ls_mkdir(p: *u8) -> i64 { return __syscall(LS_MKDIRAT, LS_ATFDCWD, p as i64, LS_DMODE, 0, 0, 0) }
111func ls_dirpath_root(root: *u8, name: *u8, out: *u8) -> i64
119func ls_dirpath(name: *u8, out: *u8) -> i64 { return ls_dirpath_root(LS_DEFAULT_ROOT, name, out) }
calls 1: ls_dirpath_root
120func ls_read(path: *u8, buf: *u8, cap: i64) -> i64
140func ls_parse2(buf: *u8, n: i64, ob: *u8, obcap: i64) -> i64
189func ls_claim(dir: *u8, owner: *u8, ttl: i64, gen: i64, gate: i64) -> i64
270func ls_rmdir(p: *u8) -> i64 { return __syscall(LS_UNLINKAT, LS_ATFDCWD, p as i64, LS_AT_REMOVEDIR, 0, 0, 0) }
271func ls_orphan_age_s(ttl: i64) -> i64 { if ttl > LS_ORPHAN_MIN_S { return ttl } return LS_ORPHAN_MIN_S }
called by 2: ls_claimmain
273func ls_path_age_s(p: *u8) -> i64
280func ls_claim_takeover(dir: *u8, sp: *u8, sb: *u8, so: i64, gen: i64, gate: i64, orphan_age_s: i64) -> i64
311func ls_claim_x(dir: *u8, owner: *u8, ttl: i64, gen: i64, gate: i64, orphan_age_s: i64) -> i64
334func ls_stamp_path(dir: *u8, out: *u8) -> i64
341func ls_unclaim(dir: *u8, owner: *u8, nonce: i64) -> i64
372func ls_pid() -> i64 { return __syscall(LS_GETPID, 0, 0, 0, 0, 0, 0) }
374func ls_acquire_root(root: *u8, name: *u8, owner: *u8, ttl: i64, hb: *u8) -> i64
452func ls_release_root(root: *u8, name: *u8, owner: *u8) -> i64
474func ls_acquire(name: *u8, owner: *u8, ttl: i64, hb: *u8) -> i64
called by 2: mainmain calls 2: ls_mkdirls_acquire_root
478func ls_release(name: *u8, owner: *u8) -> i64 { return ls_release_root(LS_DEFAULT_ROOT, name, owner) }
called by 2: mainmain calls 1: ls_release_root
482func ls_holder_of(root: *u8, name: *u8, hb: *u8) -> i64