@ai-ecoverse/slicc-kernel 1.16.0 → 1.16.1

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.
@@ -3529,7 +3529,8 @@ function statJson(s) {
3529
3529
  atimeMs: s.atime.getTime(),
3530
3530
  ctimeMs: s.ctime.getTime(),
3531
3531
  ino: s.ino,
3532
- ...s.dev !== void 0 ? { dev: s.dev } : {}
3532
+ ...s.dev !== void 0 ? { dev: s.dev } : {},
3533
+ ...s.readonly ? { readonly: true } : {}
3533
3534
  };
3534
3535
  }
3535
3536
  async function readdirStat(fs, dir) {
@@ -5091,6 +5092,20 @@ var VfsNodes = class {
5091
5092
  }
5092
5093
  }
5093
5094
  };
5095
+ async function refuseReadonly(fs, path, flags, opts = {}) {
5096
+ const writes = (flags & O_ACCMODE) !== 0 || opts.truncate === true;
5097
+ if (!writes && !opts.create || !fs.stat) return;
5098
+ const stat = (p) => fs.stat?.(p).catch((err) => {
5099
+ const code = err?.code;
5100
+ if (isMissing(err) || typeof code !== "string") return void 0;
5101
+ throw err;
5102
+ });
5103
+ const parent = path.slice(0, path.lastIndexOf("/")) || "/";
5104
+ const own = await stat(path);
5105
+ if (own && !writes) return;
5106
+ const st = own ?? await stat(parent);
5107
+ if (st?.readonly) throw new KernelError("EROFS");
5108
+ }
5094
5109
  function vfsFile(fs, opts, nodes) {
5095
5110
  const access = opts.flags & O_ACCMODE;
5096
5111
  const readable = access !== O_WRONLY;
@@ -5361,6 +5376,10 @@ var WasmProcess = class {
5361
5376
  if (e instanceof KernelError || e instanceof SpawnError) {
5362
5377
  return { ok: false, errno: e.code, message: e.code };
5363
5378
  }
5379
+ const code = e?.code;
5380
+ if (typeof code === "string" && /^E[A-Z]+$/.test(code)) {
5381
+ return { ok: false, errno: code, message: code };
5382
+ }
5364
5383
  throw e;
5365
5384
  }
5366
5385
  }
@@ -5433,6 +5452,7 @@ var WasmProcess = class {
5433
5452
  case "fd-poll":
5434
5453
  return { ok: true, kind: "json", json: pollFile(this.fds.get(req.fd).file) };
5435
5454
  case "fd-open-vfs":
5455
+ await refuseReadonly(this.options.fs, req.path, req.flags, req);
5436
5456
  return { ok: true, kind: "json", json: this.fds.install(this.openVfsFile(req), 3) };
5437
5457
  case "fd-info":
5438
5458
  return { ok: true, kind: "json", json: this.fdInfo(req.fd) };
@@ -6602,14 +6622,14 @@ function invalidation(event) {
6602
6622
  return event.paths ?? true;
6603
6623
  }
6604
6624
  async function openHostfs(spec, hook, fetch2, timing = {}) {
6605
- const readonly = spec.options?.ro !== void 0;
6625
+ const readonly2 = spec.options?.ro !== void 0;
6606
6626
  const { port1, port2 } = new MessageChannel();
6607
6627
  const slot = mediumSlot(
6608
6628
  async (err) => unreachable(err),
6609
6629
  () => watching.kick()
6610
6630
  );
6611
6631
  const stop = new AbortController();
6612
- const grant = () => hook(spec.source, { readonly });
6632
+ const grant = () => hook(spec.source, { readonly: readonly2 });
6613
6633
  let active;
6614
6634
  const handlers = hostfsHandlers(() => active);
6615
6635
  const served = serveFilesystem(port2, slot.handlers, {
@@ -6617,7 +6637,7 @@ async function openHostfs(spec, hook, fetch2, timing = {}) {
6617
6637
  chmod: true,
6618
6638
  listingStats: true,
6619
6639
  maxIo: HOSTFS_IO,
6620
- ...readonly ? { readonly: true } : {}
6640
+ ...readonly2 ? { readonly: true } : {}
6621
6641
  });
6622
6642
  const watching = keepWatching(
6623
6643
  {
@@ -6757,7 +6777,8 @@ function heldUnder(held, target) {
6757
6777
  return false;
6758
6778
  }
6759
6779
  var parentOf4 = (path) => path.slice(0, path.lastIndexOf("/")) || "/";
6760
- function statOf(attr, path, dev) {
6780
+ var readonly = (mount) => mount.caps.readonly === true;
6781
+ function statOf(attr, path, mount) {
6761
6782
  const mtime = new Date(attr.mtime);
6762
6783
  const fallback = attr.kind === "directory" ? 16877 : attr.kind === "symlink" ? 41471 : 33188;
6763
6784
  return {
@@ -6770,7 +6791,8 @@ function statOf(attr, path, dev) {
6770
6791
  atime: mtime,
6771
6792
  ctime: mtime,
6772
6793
  ino: attr.ino ?? inodeOf(path),
6773
- dev
6794
+ dev: mount.dev,
6795
+ ...readonly(mount) ? { readonly: true } : {}
6774
6796
  };
6775
6797
  }
6776
6798
  function concat4(chunks, total) {
@@ -6956,7 +6978,7 @@ var MountFs = class {
6956
6978
  return this.table.locate(normalizePath(path));
6957
6979
  }
6958
6980
  writable(mount, path) {
6959
- if (mount.caps.readonly) throw errnoError("EROFS", path);
6981
+ if (readonly(mount)) throw errnoError("EROFS", path);
6960
6982
  }
6961
6983
  async follow(path, hops = 0, create = false) {
6962
6984
  const found = this.at(path);
@@ -7085,7 +7107,7 @@ var MountFs = class {
7085
7107
  const found = this.at(path);
7086
7108
  if (!found) return this.base.lstat(path);
7087
7109
  const real = normalizePath(path);
7088
- return statOf(await this.table.getattr(found.mount, real, found.rel), real, found.mount.dev);
7110
+ return statOf(await this.table.getattr(found.mount, real, found.rel), real, found.mount);
7089
7111
  }
7090
7112
  async stat(path) {
7091
7113
  const real = await this.follow(path);
@@ -7112,7 +7134,7 @@ var MountFs = class {
7112
7134
  list.map(async (entry) => {
7113
7135
  const child = normalizePath(`${real}/${entry.name}`);
7114
7136
  if (entry.attr && mount.caps.listingStats) {
7115
- return [entry.name, statOf(entry.attr, child, mount.dev)];
7137
+ return [entry.name, statOf(entry.attr, child, mount)];
7116
7138
  }
7117
7139
  return [entry.name, await this.lstat(child).catch(() => null)];
7118
7140
  })