@ai-ecoverse/slicc-kernel 1.8.11 → 1.8.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -265,7 +265,7 @@ function createNodeOps(h) {
265
265
  mtime,
266
266
  ctime: new Date(st.ctimeMs ?? mtime.getTime()),
267
267
  blksize: 4096,
268
- blocks: Math.ceil(size / 4096)
268
+ blocks: Math.ceil(size / 4096) * 8
269
269
  };
270
270
  },
271
271
  setattr(node, attr) {
@@ -524,6 +524,7 @@ function mountLiveVfsDirs(Fs, bridge, dirs, warn) {
524
524
  }
525
525
  const plugin = Fs.filesystems.SLICC_LIVE_FS ?? createLiveVfsPlugin(Fs);
526
526
  Fs.filesystems.SLICC_LIVE_FS = plugin;
527
+ guardStatfs(Fs);
527
528
  const mounted = [];
528
529
  for (const dir of outermostDirs(dirs)) {
529
530
  if (dir === "/") continue;
@@ -546,6 +547,7 @@ function liveRoot(Fs, bridge) {
546
547
  plugin.mounts.add(root.mount);
547
548
  invalidateLiveVfs(Fs, plugin);
548
549
  guardRenames(Fs);
550
+ guardStatfs(Fs);
549
551
  const memfs = root.memfs ?? root.node_ops;
550
552
  const live = plugin.node_ops;
551
553
  root.memfs = memfs;
@@ -577,6 +579,30 @@ function crosses(Fs, from, to) {
577
579
  return false;
578
580
  }
579
581
  }
582
+ function guardStatfs(Fs) {
583
+ const statfsNode = Fs.statfsNode?.bind(Fs);
584
+ if (!statfsNode || Fs.sliccStatfs) return;
585
+ Fs.sliccStatfs = true;
586
+ Fs.statfsNode = (node) => {
587
+ const defaults = statfsNode(node);
588
+ let usage;
589
+ try {
590
+ usage = node.live ? node.mount?.opts?.bridge?.statfs?.() : void 0;
591
+ } catch {
592
+ return defaults;
593
+ }
594
+ if (!usage) return defaults;
595
+ const free = Math.max(0, Math.floor((usage.quota - usage.usage) / 4096));
596
+ return {
597
+ ...defaults,
598
+ bsize: 4096,
599
+ frsize: 4096,
600
+ blocks: Math.ceil(usage.quota / 4096),
601
+ bfree: free,
602
+ bavail: free
603
+ };
604
+ };
605
+ }
580
606
  function guardRenames(Fs) {
581
607
  const rename = Fs.rename?.bind(Fs);
582
608
  if (!rename || Fs.sliccRename) return;
@@ -670,6 +696,11 @@ var init_emscripten_vfs_hook = __esm({
670
696
  });
671
697
 
672
698
  // src/realm/sync-fs-wire.ts
699
+ function parseSyncFsUsage(json) {
700
+ const u = json;
701
+ if (!u || typeof u.quota !== "number" || typeof u.usage !== "number") return null;
702
+ return { quota: u.quota, usage: u.usage };
703
+ }
673
704
  function syncError(code2, label) {
674
705
  return Object.assign(new Error(`${code2}: ${label}`), { code: code2 });
675
706
  }
@@ -911,7 +942,8 @@ function createSyncFsSabBridge(transport, opts = {}) {
911
942
  },
912
943
  utimes: (path, atimeMs, mtimeMs) => {
913
944
  run({ op: "utimes", path, atimeMs, mtimeMs }, path);
914
- }
945
+ },
946
+ statfs: () => parseSyncFsUsage(json({ op: "statfs", path: "/" }, "/"))
915
947
  };
916
948
  }
917
949
  var init_sync_sab_bridge = __esm({
@@ -1878,7 +1910,34 @@ function useDevFd(Fs) {
1878
1910
  return fstat.call(Fs, fd);
1879
1911
  };
1880
1912
  }
1881
- var O_CLOEXEC, FD_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, tracked, IMPORT_NAMES, EBADF, DIR_MODE, LINK_MODE;
1913
+ function mountTable() {
1914
+ const root = globalThis.navigator?.storage ? "opfs" : "memory";
1915
+ return [`${root} / ${root} rw 0 0`, "devfs /dev devfs rw 0 0", "proc /proc proc rw 0 0", ""].join(
1916
+ "\n"
1917
+ );
1918
+ }
1919
+ function useMounts(Fs) {
1920
+ const { writeFile } = Fs;
1921
+ if (typeof Fs.open !== "function" || typeof writeFile !== "function") return;
1922
+ try {
1923
+ writeFile.call(Fs, "/proc/mounts", mountTable());
1924
+ } catch {
1925
+ return;
1926
+ }
1927
+ const open = Fs.open.bind(Fs);
1928
+ Fs.open = (path, flags, mode) => {
1929
+ if (path !== "/etc/mtab" || (flags & (O_ACCMODE | O_CREAT2)) !== 0) {
1930
+ return open(path, flags, mode);
1931
+ }
1932
+ try {
1933
+ return open(path, flags, mode);
1934
+ } catch (e) {
1935
+ if (e?.errno !== wasiErrno("ENOENT")) throw e;
1936
+ return open("/proc/mounts", flags, mode);
1937
+ }
1938
+ };
1939
+ }
1940
+ var O_CLOEXEC, FD_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, tracked, IMPORT_NAMES, EBADF, DIR_MODE, LINK_MODE, O_ACCMODE, O_CREAT2;
1882
1941
  var init_process_fds = __esm({
1883
1942
  "src/process/process-fds.ts"() {
1884
1943
  "use strict";
@@ -1904,6 +1963,8 @@ var init_process_fds = __esm({
1904
1963
  EBADF = 8;
1905
1964
  DIR_MODE = 16749;
1906
1965
  LINK_MODE = 41408;
1966
+ O_ACCMODE = 3;
1967
+ O_CREAT2 = 64;
1907
1968
  }
1908
1969
  });
1909
1970
 
@@ -1986,7 +2047,7 @@ function inheritedSlot(fd, stream) {
1986
2047
  if (stream.sliccKernelFd === void 0) {
1987
2048
  const device = stream.path === void 0 ? void 0 : DEVICES[stream.path];
1988
2049
  if (!device) return void 0;
1989
- const access = ACCESS[stream.flags & O_ACCMODE];
2050
+ const access = ACCESS[stream.flags & O_ACCMODE2];
1990
2051
  return { fd, device, ...access ? { access } : {} };
1991
2052
  }
1992
2053
  const flags = stream.sliccKernelSocket ? { flags: stream.flags } : {};
@@ -2003,7 +2064,7 @@ function placeholder(Fs, streams, entry) {
2003
2064
  if (entry.kind === "tty") return Fs.open("/dev/tty", O_RDWR);
2004
2065
  if (entry.kind === "stream") return Fs.open("/dev/null", O_RDWR);
2005
2066
  Fs.mkdirTree(PLACEHOLDER_DIR);
2006
- return Fs.open(`${PLACEHOLDER_DIR}/${entry.fd}`, O_RDWR | O_CREAT2);
2067
+ return Fs.open(`${PLACEHOLDER_DIR}/${entry.fd}`, O_RDWR | O_CREAT3);
2007
2068
  }
2008
2069
  function asFifo(stream, streams, identity) {
2009
2070
  const inos = streamInos.get(streams) ?? /* @__PURE__ */ new Map();
@@ -2037,7 +2098,7 @@ function restoreForkedStreams(Fs, streams, table) {
2037
2098
  } else {
2038
2099
  const placed = place(
2039
2100
  Fs,
2040
- Fs.open(entry.path, entry.flags & ~(O_CREAT2 | O_EXCL2 | O_TRUNC2)),
2101
+ Fs.open(entry.path, entry.flags & ~(O_CREAT3 | O_EXCL2 | O_TRUNC2)),
2041
2102
  entry.fd
2042
2103
  );
2043
2104
  setCloseOnExec(placed, (entry.flags & O_CLOEXEC) !== 0);
@@ -2046,14 +2107,14 @@ function restoreForkedStreams(Fs, streams, table) {
2046
2107
  }
2047
2108
  }
2048
2109
  }
2049
- var O_RDWR, O_ACCMODE, O_CREAT2, O_EXCL2, O_TRUNC2, PLACEHOLDER_DIR, ACCESS, DEVICES, FIFO_MODE, nextStreamIno, streamInos;
2110
+ var O_RDWR, O_ACCMODE2, O_CREAT3, O_EXCL2, O_TRUNC2, PLACEHOLDER_DIR, ACCESS, DEVICES, FIFO_MODE, nextStreamIno, streamInos;
2050
2111
  var init_process_fork = __esm({
2051
2112
  "src/process/process-fork.ts"() {
2052
2113
  "use strict";
2053
2114
  init_process_fds();
2054
2115
  O_RDWR = 2;
2055
- O_ACCMODE = 3;
2056
- O_CREAT2 = 64;
2116
+ O_ACCMODE2 = 3;
2117
+ O_CREAT3 = 64;
2057
2118
  O_EXCL2 = 128;
2058
2119
  O_TRUNC2 = 512;
2059
2120
  PLACEHOLDER_DIR = "/dev/slicc-fd";
@@ -2197,7 +2258,7 @@ function socketNode(Fs, addr) {
2197
2258
  const fs = Fs;
2198
2259
  let stream;
2199
2260
  try {
2200
- stream = Fs.open(addr.path, O_WRONLY | O_CREAT3 | O_EXCL3, 493);
2261
+ stream = Fs.open(addr.path, O_WRONLY | O_CREAT4 | O_EXCL3, 493);
2201
2262
  } catch (e) {
2202
2263
  if (e?.errno === wasiErrno("EEXIST")) {
2203
2264
  throw new SyscallError("EADDRINUSE");
@@ -2328,7 +2389,7 @@ function createSocketKernel(deps) {
2328
2389
  })
2329
2390
  };
2330
2391
  }
2331
- var O_RDWR2, KILLED_BY_SIGPIPE2, O_WRONLY, O_CREAT3, O_EXCL3;
2392
+ var O_RDWR2, KILLED_BY_SIGPIPE2, O_WRONLY, O_CREAT4, O_EXCL3;
2332
2393
  var init_process_sockets = __esm({
2333
2394
  "src/process/process-sockets.ts"() {
2334
2395
  "use strict";
@@ -2339,7 +2400,7 @@ var init_process_sockets = __esm({
2339
2400
  O_RDWR2 = 2;
2340
2401
  KILLED_BY_SIGPIPE2 = 128 + 13;
2341
2402
  O_WRONLY = 1;
2342
- O_CREAT3 = 64;
2403
+ O_CREAT4 = 64;
2343
2404
  O_EXCL3 = 128;
2344
2405
  }
2345
2406
  });
@@ -2618,6 +2679,7 @@ async function runWasmProcess(init, port, deps = {}) {
2618
2679
  if (pipefs) streams.usePipes(pipefs);
2619
2680
  streams.useControllingTerminal();
2620
2681
  useDevFd(running.FS);
2682
+ useMounts(running.FS);
2621
2683
  ownByRealmUser(running.FS);
2622
2684
  const livePath = (s) => liveNodePath(s.node);
2623
2685
  running.sliccKernel = createProcessKernel({