@waffle-os/runtime 0.0.156 → 0.0.157
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.
- package/browser/filesystem-backend.ts +11 -1
- package/browser/preview-protocol.ts +2 -0
- package/browser/preview.ts +128 -18
- package/browser/runtime-terminals.ts +65 -24
- package/browser/shared-fs.ts +141 -14
- package/browser/worker.ts +73 -6
- package/core/descriptors.ts +19 -2
- package/core/devices.ts +237 -2
- package/core/fd-reopen.ts +105 -20
- package/core/filesystem.ts +71 -0
- package/core/index.ts +4 -0
- package/core/open-file.ts +212 -18
- package/core/wasi.ts +397 -46
- package/dist/browser/filesystem-backend.js +4 -2
- package/dist/browser/preview.js +120 -17
- package/dist/browser/runtime-terminals.js +53 -10
- package/dist/browser/shared-fs.js +124 -11
- package/dist/browser/worker.js +59 -6
- package/dist/core/descriptors.js +9 -1
- package/dist/core/devices.js +211 -1
- package/dist/core/fd-reopen.js +79 -18
- package/dist/core/filesystem.js +13 -0
- package/dist/core/open-file.js +166 -13
- package/dist/core/wasi.js +353 -27
- package/dist/fs/backend.js +29 -2
- package/dist/fs/client.js +199 -6
- package/dist/fs/index.js +21 -1
- package/dist/fs/indexeddb.js +30 -2
- package/dist/fs/locks.js +1112 -0
- package/dist/fs/memory.js +109 -1
- package/dist/fs/multitab-backend.js +315 -195
- package/dist/fs/multitab-protocol.js +1 -0
- package/dist/fs/persistent.js +13 -6
- package/dist/fs/protocol.js +9 -3
- package/dist/fs/service.js +386 -22
- package/dist/fs/shared.js +54 -1
- package/dist/fs/storage-geometry.js +2 -0
- package/dist/interrupt/rewriter-internal.js +4 -1
- package/dist/proc/abi.js +80 -6
- package/dist/proc/errors.js +1 -0
- package/dist/proc/filesystem-codec.js +40 -9
- package/dist/proc/index.js +10 -1
- package/dist/proc/pty.js +193 -0
- package/dist/proc/worker-client.js +11 -2
- package/dist/proc/worker-pipes.js +51 -0
- package/dist/runtime.js +11 -2
- package/dist/search/engine.js +53 -0
- package/dist/tooling/program/program-transformer.json +1 -1
- package/fs/backend.ts +33 -1
- package/fs/client.ts +225 -6
- package/fs/index.ts +22 -1
- package/fs/indexeddb.ts +36 -2
- package/fs/locks.ts +1406 -0
- package/fs/memory.ts +114 -1
- package/fs/multitab-backend.ts +561 -303
- package/fs/multitab-protocol.ts +1 -0
- package/fs/persistent.ts +14 -3
- package/fs/protocol.ts +17 -5
- package/fs/service.ts +468 -23
- package/fs/shared.ts +60 -2
- package/fs/storage-geometry.ts +3 -0
- package/index.ts +2 -0
- package/interrupt/rewriter-internal.ts +4 -1
- package/package.json +2 -2
- package/proc/abi.ts +79 -6
- package/proc/errors.ts +1 -0
- package/proc/filesystem-codec.ts +39 -9
- package/proc/index.ts +11 -0
- package/proc/pty.ts +227 -0
- package/proc/worker-client.ts +28 -6
- package/proc/worker-pipes.ts +57 -0
- package/runtime.ts +12 -2
- package/search/engine.ts +49 -0
- package/testing/indexeddb-storage-browser.ts +173 -2
- package/tooling/program/program-transformer.json +1 -1
package/dist/fs/memory.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { validateMachineId } from "../core/devices.js";
|
|
1
2
|
import { DirectoryPages, checkDirectoryPage } from "./directory-pages.js";
|
|
3
|
+
import { LockTable } from "./locks.js";
|
|
2
4
|
import { utf8ByteLength } from "./utf8-size.js";
|
|
3
5
|
import {
|
|
4
6
|
permissionsFor,
|
|
@@ -256,6 +258,31 @@ export class MemFS {
|
|
|
256
258
|
nodeHandles = new WeakMap;
|
|
257
259
|
nextHandle = 0;
|
|
258
260
|
references = new Map;
|
|
261
|
+
lockTable;
|
|
262
|
+
lockAdapter;
|
|
263
|
+
get locks() {
|
|
264
|
+
if (this.lockAdapter)
|
|
265
|
+
return this.lockAdapter;
|
|
266
|
+
const table = this.lockTable ??= new LockTable;
|
|
267
|
+
const inoOf = (handle) => this.nodeForHandle(handle).ino;
|
|
268
|
+
this.lockAdapter = {
|
|
269
|
+
flock: (handle, ofdId, operation) => table.flock(inoOf(handle), ofdId, 0, operation, false, handle, false).errno,
|
|
270
|
+
setRangeLock: (handle, ofdId, pid, range, blocking) => table.setRangeLock(inoOf(handle), ofdId, 0, pid, range, blocking, false, handle, pid, false).errno,
|
|
271
|
+
getRangeLock: (handle, ofdId, range, pid = 1) => table.getRangeLock(inoOf(handle), ofdId, 0, range, pid),
|
|
272
|
+
releaseOfd: (handle, ofdId) => {
|
|
273
|
+
const node = this.handles.get(handle);
|
|
274
|
+
if (node)
|
|
275
|
+
table.releaseOfd(node.ino, ofdId, 0);
|
|
276
|
+
},
|
|
277
|
+
releasePosix: (handle, pid = 1) => {
|
|
278
|
+
const node = this.handles.get(handle);
|
|
279
|
+
if (node)
|
|
280
|
+
table.releasePosix(node.ino, pid);
|
|
281
|
+
},
|
|
282
|
+
hasActivePosixLocks: () => table.hasActivePosixLocks()
|
|
283
|
+
};
|
|
284
|
+
return this.lockAdapter;
|
|
285
|
+
}
|
|
259
286
|
directoryParents = new WeakMap;
|
|
260
287
|
removedDirectories = new WeakSet;
|
|
261
288
|
rootedCache;
|
|
@@ -489,9 +516,88 @@ export class MemFS {
|
|
|
489
516
|
const resolved = this.walkNodes(start, path, false, true, undefined, rooted);
|
|
490
517
|
if (typeof resolved !== "number" && resolved.node?.kind === wanted)
|
|
491
518
|
return index;
|
|
519
|
+
if (wanted === "file" && this.matchesVirtualMachineId(start, path, resolved, rooted))
|
|
520
|
+
return index;
|
|
492
521
|
}
|
|
493
522
|
return -1;
|
|
494
523
|
}
|
|
524
|
+
matchesVirtualMachineId(start, path, resolved, rooted) {
|
|
525
|
+
if (typeof resolved !== "number") {
|
|
526
|
+
if (resolved.node !== undefined || resolved.trailingSlash || resolved.name !== "machine-id")
|
|
527
|
+
return false;
|
|
528
|
+
const etc = this.walkNodes(this.root, "etc", false, true, undefined, true);
|
|
529
|
+
return typeof etc !== "number" && etc.node?.kind === "dir" && resolved.parent === etc.node;
|
|
530
|
+
}
|
|
531
|
+
if (resolved !== 44)
|
|
532
|
+
return false;
|
|
533
|
+
return this.walkSyntheticMachineId(start, path, rooted);
|
|
534
|
+
}
|
|
535
|
+
walkSyntheticMachineId(start, path, rooted) {
|
|
536
|
+
if (path.endsWith("/"))
|
|
537
|
+
return false;
|
|
538
|
+
let current = start;
|
|
539
|
+
let pending = path.split("/");
|
|
540
|
+
let offset = 0;
|
|
541
|
+
let expansions = 0;
|
|
542
|
+
while (offset < pending.length) {
|
|
543
|
+
const part = pending[offset++];
|
|
544
|
+
if (!part || part === ".")
|
|
545
|
+
continue;
|
|
546
|
+
if (!(current.mode & 64))
|
|
547
|
+
return false;
|
|
548
|
+
if (part === "..") {
|
|
549
|
+
const parent = this.stepParentForProbe(current, start, rooted);
|
|
550
|
+
if (!parent)
|
|
551
|
+
return false;
|
|
552
|
+
current = parent;
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
const child = current.children.get(part);
|
|
556
|
+
if (!child)
|
|
557
|
+
return this.isSyntheticMachineIdTail(current, part, pending, offset);
|
|
558
|
+
if (child.kind === "dir") {
|
|
559
|
+
this.directoryParents.set(child, current);
|
|
560
|
+
current = child;
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
if (child.kind !== "symlink" || ++expansions > 40 || !child.target)
|
|
564
|
+
return false;
|
|
565
|
+
if (child.target.startsWith("/")) {
|
|
566
|
+
if (!rooted)
|
|
567
|
+
return false;
|
|
568
|
+
current = this.root;
|
|
569
|
+
}
|
|
570
|
+
pending = child.target.split("/").concat(pending.slice(offset));
|
|
571
|
+
offset = 0;
|
|
572
|
+
}
|
|
573
|
+
return false;
|
|
574
|
+
}
|
|
575
|
+
stepParentForProbe(current, start, rooted) {
|
|
576
|
+
if (current === this.root)
|
|
577
|
+
return rooted ? this.root : null;
|
|
578
|
+
if (!rooted && current === start)
|
|
579
|
+
return null;
|
|
580
|
+
const parent = this.liveParent(current);
|
|
581
|
+
return typeof parent === "number" ? null : parent;
|
|
582
|
+
}
|
|
583
|
+
isSyntheticMachineIdTail(current, part, pending, offset) {
|
|
584
|
+
if (current !== this.root || part !== "etc")
|
|
585
|
+
return false;
|
|
586
|
+
let sawMachineId = false;
|
|
587
|
+
for (let i = offset;i < pending.length; i++) {
|
|
588
|
+
const next = pending[i];
|
|
589
|
+
if (sawMachineId)
|
|
590
|
+
return false;
|
|
591
|
+
if (!next || next === ".")
|
|
592
|
+
continue;
|
|
593
|
+
if (next === "machine-id") {
|
|
594
|
+
sawMachineId = true;
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
return sawMachineId;
|
|
600
|
+
}
|
|
495
601
|
pathOf(dir) {
|
|
496
602
|
const names = [];
|
|
497
603
|
for (let at = dir;at !== this.root; ) {
|
|
@@ -1128,8 +1234,10 @@ export class MemFS {
|
|
|
1128
1234
|
pending.push(child);
|
|
1129
1235
|
}
|
|
1130
1236
|
}
|
|
1131
|
-
|
|
1237
|
+
machineId;
|
|
1238
|
+
constructor(root = newDir(), machineId) {
|
|
1132
1239
|
this.root = root;
|
|
1240
|
+
this.machineId = machineId !== undefined ? validateMachineId(machineId) : validateMachineId(crypto.randomUUID().replaceAll("-", "").toLowerCase());
|
|
1133
1241
|
adoptInodes(root);
|
|
1134
1242
|
this.changeLinkCount(root, 1);
|
|
1135
1243
|
const pending = [root];
|