@amalgm/shell 0.1.164-main.41474889901 → 0.1.164-main.41526666971

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.
Files changed (74) hide show
  1. package/dist/cli.js +34 -41
  2. package/dist/cli.js.map +1 -1
  3. package/dist/drive/fuse.d.ts +13 -116
  4. package/dist/drive/fuse.js +36 -145
  5. package/dist/drive/fuse.js.map +1 -1
  6. package/dist/drive/kernel.d.ts +17 -0
  7. package/dist/drive/kernel.js +32 -0
  8. package/dist/drive/kernel.js.map +1 -0
  9. package/dist/drive/layout.d.ts +2 -0
  10. package/dist/drive/layout.js +8 -4
  11. package/dist/drive/layout.js.map +1 -1
  12. package/dist/drive/mount.d.ts +16 -6
  13. package/dist/drive/mount.js +50 -24
  14. package/dist/drive/mount.js.map +1 -1
  15. package/dist/drive/mountpoint.d.ts +14 -0
  16. package/dist/drive/mountpoint.js +51 -0
  17. package/dist/drive/mountpoint.js.map +1 -0
  18. package/dist/drive/nfs/apple-double.d.ts +6 -0
  19. package/dist/drive/nfs/apple-double.js +140 -0
  20. package/dist/drive/nfs/apple-double.js.map +1 -0
  21. package/dist/drive/nfs/attributes.d.ts +64 -0
  22. package/dist/drive/nfs/attributes.js +97 -0
  23. package/dist/drive/nfs/attributes.js.map +1 -0
  24. package/dist/drive/nfs/handles.d.ts +44 -0
  25. package/dist/drive/nfs/handles.js +209 -0
  26. package/dist/drive/nfs/handles.js.map +1 -0
  27. package/dist/drive/nfs/mount3.d.ts +16 -0
  28. package/dist/drive/nfs/mount3.js +38 -0
  29. package/dist/drive/nfs/mount3.js.map +1 -0
  30. package/dist/drive/nfs/nfs3.d.ts +27 -0
  31. package/dist/drive/nfs/nfs3.js +458 -0
  32. package/dist/drive/nfs/nfs3.js.map +1 -0
  33. package/dist/drive/nfs/rpc.d.ts +66 -0
  34. package/dist/drive/nfs/rpc.js +122 -0
  35. package/dist/drive/nfs/rpc.js.map +1 -0
  36. package/dist/drive/nfs/server.d.ts +30 -0
  37. package/dist/drive/nfs/server.js +109 -0
  38. package/dist/drive/nfs/server.js.map +1 -0
  39. package/dist/drive/nfs/xdr.d.ts +44 -0
  40. package/dist/drive/nfs/xdr.js +111 -0
  41. package/dist/drive/nfs/xdr.js.map +1 -0
  42. package/dist/drive/nfs.d.ts +60 -0
  43. package/dist/drive/nfs.js +181 -0
  44. package/dist/drive/nfs.js.map +1 -0
  45. package/dist/drive/operations.d.ts +125 -0
  46. package/dist/drive/operations.js +141 -0
  47. package/dist/drive/operations.js.map +1 -0
  48. package/dist/error-facts.d.ts +24 -0
  49. package/dist/error-facts.js +35 -0
  50. package/dist/error-facts.js.map +1 -0
  51. package/dist/files-program/client.d.ts +122 -0
  52. package/dist/files-program/client.js +430 -0
  53. package/dist/files-program/client.js.map +1 -0
  54. package/dist/files-program/journeys.d.ts +15 -0
  55. package/dist/files-program/journeys.js +79 -0
  56. package/dist/files-program/journeys.js.map +1 -0
  57. package/dist/files-program/program.d.ts +1 -0
  58. package/dist/files-program/program.js +255 -0
  59. package/dist/files-program/program.js.map +1 -0
  60. package/dist/files-program/protocol.d.ts +154 -0
  61. package/dist/files-program/protocol.js +7 -0
  62. package/dist/files-program/protocol.js.map +1 -0
  63. package/dist/machine-host.d.ts +35 -32
  64. package/dist/machine-host.js +124 -195
  65. package/dist/machine-host.js.map +1 -1
  66. package/dist/runtime-node-flags.d.ts +6 -6
  67. package/dist/runtime-node-flags.js +6 -6
  68. package/dist/sharing-host.d.ts +6 -11
  69. package/dist/sharing-host.js +6 -10
  70. package/dist/sharing-host.js.map +1 -1
  71. package/dist/sync-cli.js +1 -1
  72. package/dist/sync-cli.js.map +1 -1
  73. package/npm-shrinkwrap.json +2 -2
  74. package/package.json +4 -4
@@ -0,0 +1,97 @@
1
+ /** nfsstat3: what a failed procedure tells the client. */
2
+ export const STATUS = {
3
+ OK: 0, PERM: 1, NOENT: 2, IO: 5, ACCES: 13, EXIST: 17, XDEV: 18, NOTDIR: 20, ISDIR: 21, INVAL: 22, FBIG: 27,
4
+ NOSPC: 28, ROFS: 30, MLINK: 31, NAMETOOLONG: 63, NOTEMPTY: 66, DQUOT: 69, STALE: 70, BADHANDLE: 10001,
5
+ NOT_SYNC: 10002, NOTSUPP: 10004, TOOSMALL: 10005, SERVERFAULT: 10006,
6
+ };
7
+ const BY_ERRNO = {
8
+ EPERM: STATUS.PERM, ENOENT: STATUS.NOENT, EACCES: STATUS.ACCES, EEXIST: STATUS.EXIST, EXDEV: STATUS.XDEV,
9
+ ENOTDIR: STATUS.NOTDIR, EISDIR: STATUS.ISDIR, EINVAL: STATUS.INVAL, EFBIG: STATUS.FBIG, ENOSPC: STATUS.NOSPC,
10
+ EROFS: STATUS.ROFS, EMLINK: STATUS.MLINK, ENAMETOOLONG: STATUS.NAMETOOLONG, ENOTEMPTY: STATUS.NOTEMPTY,
11
+ EDQUOT: STATUS.DQUOT, ESTALE: STATUS.STALE, ENOTSUP: STATUS.NOTSUPP, EOPNOTSUPP: STATUS.NOTSUPP,
12
+ };
13
+ /** The status for an operation's failure: a known errno by name; a placement
14
+ * that could not finish (a `DriveError`), a drive at rest (ENOTCONN) or
15
+ * anything else is IO, so missing bytes are an error, never zeros. */
16
+ export function statusOf(error) {
17
+ const named = typeof error === "object" && error !== null ? error : null;
18
+ if (named?.name === "DriveError")
19
+ return STATUS.IO;
20
+ return typeof named?.code === "string" ? BY_ERRNO[named.code] ?? STATUS.IO : STATUS.IO;
21
+ }
22
+ /** ftype3 for each `S_IFMT`. */
23
+ const TYPES = new Map([
24
+ [0o100000, 1], [0o040000, 2], [0o060000, 3], [0o020000, 4], [0o120000, 5], [0o140000, 6], [0o010000, 7],
25
+ ]);
26
+ /** The drive's one filesystem, as every file's attributes name it. */
27
+ const FSID = 1n;
28
+ export function writeFattr(w, { attributes: a, fileid }) {
29
+ const blocks = "blocks" in a ? a.blocks * 512 : a.size;
30
+ w.uint(TYPES.get(a.mode & 0o170000) ?? 1).uint(a.mode & 0o7777).uint(a.nlink).uint(a.uid).uint(a.gid)
31
+ .hyper(a.size).hyper(blocks).uint(0).uint(0).hyper(FSID).hyper(fileid);
32
+ writeTime(w, milliseconds(a, "atime"));
33
+ writeTime(w, milliseconds(a, "mtime"));
34
+ writeTime(w, milliseconds(a, "ctime"));
35
+ }
36
+ /** post_op_attr: the attributes when the server has them. */
37
+ export function writePostOpAttr(w, described) {
38
+ w.bool(described !== null);
39
+ if (described)
40
+ writeFattr(w, described);
41
+ }
42
+ /** wcc_data with no attributes before and the ones after, when known. */
43
+ export function writeWcc(w, after) {
44
+ w.bool(false);
45
+ writePostOpAttr(w, after);
46
+ }
47
+ export function readSattr(r, now) {
48
+ const out = {};
49
+ if (r.bool())
50
+ out.mode = r.uint();
51
+ if (r.bool())
52
+ out.uid = r.uint();
53
+ if (r.bool())
54
+ out.gid = r.uint();
55
+ if (r.bool())
56
+ out.size = Number(r.hyper());
57
+ const atime = readSetTime(r, now);
58
+ if (atime !== undefined)
59
+ out.atime = atime;
60
+ const mtime = readSetTime(r, now);
61
+ if (mtime !== undefined)
62
+ out.mtime = mtime;
63
+ return out;
64
+ }
65
+ /** set_atime / set_mtime: unchanged, the server's time, or the client's. */
66
+ function readSetTime(r, now) {
67
+ switch (r.uint()) {
68
+ case 1: return now;
69
+ case 2: return readTime(r);
70
+ default: return undefined;
71
+ }
72
+ }
73
+ export function readTime(r) {
74
+ const seconds = r.uint();
75
+ const nanoseconds = r.uint();
76
+ return seconds * 1000 + nanoseconds / 1e6;
77
+ }
78
+ /** Whether two times in milliseconds are the same `nfstime3`. */
79
+ export function sameTime(a, b) {
80
+ const [as, an] = split(a);
81
+ const [bs, bn] = split(b);
82
+ return as === bs && an === bn;
83
+ }
84
+ function writeTime(w, ms) {
85
+ const [seconds, nanoseconds] = split(ms);
86
+ w.uint(seconds).uint(nanoseconds);
87
+ }
88
+ function split(ms) {
89
+ const seconds = Math.floor(ms / 1000);
90
+ return [seconds, Math.min(999_999_999, Math.round((ms - seconds * 1000) * 1e6))];
91
+ }
92
+ /** A time in milliseconds, with the fraction a `Stats` keeps. */
93
+ export function milliseconds(a, field) {
94
+ const precise = a[`${field}Ms`];
95
+ return typeof precise === "number" ? precise : a[field].getTime();
96
+ }
97
+ //# sourceMappingURL=attributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../../src/drive/nfs/attributes.ts"],"names":[],"mappings":"AAWA,0DAA0D;AAC1D,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE;IAC3G,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK;IACrG,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK;CAC5D,CAAC;AAEX,MAAM,QAAQ,GAAqC;IACjD,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI;IACxG,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI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;
3
+ private readonly secret;
4
+ /** The drive's root, the export the client mounts. */
5
+ readonly root = 1n;
6
+ private readonly nodes;
7
+ private readonly children;
8
+ private next;
9
+ private journal;
10
+ private constructor();
11
+ /** The table journaled at `path`, made when none stands there. Replaying
12
+ * rewrites the journal whole, so it never holds more than the live nodes
13
+ * and the changes since this program started. A torn last line, from a
14
+ * program that stopped while writing it, ends the replay. */
15
+ static open(path: string): Handles;
16
+ /** The handle the client holds for a node. */
17
+ handle(id: bigint): Buffer;
18
+ /** The node a handle names, or null for a handle this table never handed
19
+ * out or has forgotten. */
20
+ id(handle: Buffer): bigint | null;
21
+ /** The node's kernel path, `/` for the root. */
22
+ path(id: bigint): string;
23
+ /** The node's parent; the root is its own. */
24
+ parent(id: bigint): bigint;
25
+ /** The node of a name in a folder's node, made the first time. */
26
+ child(parent: bigint, name: string): bigint;
27
+ /** A rename through the mount: the node moves, and whatever the new name
28
+ * held before is forgotten. */
29
+ moved(fromParent: bigint, fromName: string, toParent: bigint, toName: string): void;
30
+ /** A removal through the mount: the name's node and everything beneath it. */
31
+ forget(parent: bigint, name: string): void;
32
+ /** Writes the changes since the last flush, in one write. */
33
+ flush(): void;
34
+ private mac;
35
+ private link;
36
+ private unlink;
37
+ private drop;
38
+ /** One journal line applied; false for a line that is torn or unknown. */
39
+ private replay;
40
+ /** The journal written afresh: its secret and the next number, so a
41
+ * forgotten node's number is never handed out again, then every live node,
42
+ * parents first, in place of the old one. */
43
+ private rewrite;
44
+ }
@@ -0,0 +1,209 @@
1
+ /**
2
+ * The drive's NFS file handles. NFS names every file by a handle the server
3
+ * hands out, and a client keeps it: in a terminal's working folder, in an
4
+ * open file, across a restart of the Files program. So a handle is a number
5
+ * per address the client has seen, the node, kept here with the name it has
6
+ * in its parent's node. A rename through the mount moves the node, so the
7
+ * handle follows the file as a local disk's inode would; a removal forgets
8
+ * it. The table is journaled beside the drive, one line per change, so the
9
+ * next Files program answers the same handles: a client never sees a stale
10
+ * handle because the program restarted.
11
+ *
12
+ * A handle is the node's number and a MAC of it under the journal's secret,
13
+ * so a client cannot guess one it was never handed. Ground that changed on
14
+ * the shelf by other means (Apply) keeps its node's old address; the server
15
+ * then answers whatever stands there now, or STALE, as any NFS server whose
16
+ * disk changed under it.
17
+ */
18
+ import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
19
+ import { closeSync, existsSync, fsyncSync, openSync, readFileSync, renameSync, writeSync } from "node:fs";
20
+ const ROOT = 1n;
21
+ export class Handles {
22
+ file;
23
+ secret;
24
+ /** The drive's root, the export the client mounts. */
25
+ root = ROOT;
26
+ nodes = new Map();
27
+ children = new Map();
28
+ next = ROOT + 1n;
29
+ journal = [];
30
+ constructor(file, secret) {
31
+ this.file = file;
32
+ this.secret = secret;
33
+ }
34
+ /** The table journaled at `path`, made when none stands there. Replaying
35
+ * rewrites the journal whole, so it never holds more than the live nodes
36
+ * and the changes since this program started. A torn last line, from a
37
+ * program that stopped while writing it, ends the replay. */
38
+ static open(path) {
39
+ const lines = existsSync(path) ? readFileSync(path, "utf8").split("\n") : [];
40
+ const header = /^amalgm-nfs-handles 1 ([0-9a-f]{64}) (\d+)$/.exec(lines[0] ?? "");
41
+ const handles = new Handles(path, header ? Buffer.from(header[1], "hex") : randomBytes(32));
42
+ if (header) {
43
+ handles.next = BigInt(header[2]);
44
+ for (const line of lines.slice(1))
45
+ if (!handles.replay(line))
46
+ break;
47
+ }
48
+ handles.rewrite();
49
+ return handles;
50
+ }
51
+ /** The handle the client holds for a node. */
52
+ handle(id) {
53
+ const out = Buffer.allocUnsafe(16);
54
+ out.writeBigUInt64BE(id, 0);
55
+ this.mac(id).copy(out, 8);
56
+ return out;
57
+ }
58
+ /** The node a handle names, or null for a handle this table never handed
59
+ * out or has forgotten. */
60
+ id(handle) {
61
+ if (handle.length !== 16)
62
+ return null;
63
+ const id = handle.readBigUInt64BE(0);
64
+ if (!timingSafeEqual(handle.subarray(8), this.mac(id)))
65
+ return null;
66
+ return id === ROOT || this.nodes.has(id) ? id : null;
67
+ }
68
+ /** The node's kernel path, `/` for the root. */
69
+ path(id) {
70
+ const names = [];
71
+ for (let at = id; at !== ROOT;) {
72
+ const node = this.nodes.get(at);
73
+ names.push(node.name);
74
+ at = node.parent;
75
+ }
76
+ return "/" + names.reverse().join("/");
77
+ }
78
+ /** The node's parent; the root is its own. */
79
+ parent(id) {
80
+ return this.nodes.get(id)?.parent ?? ROOT;
81
+ }
82
+ /** The node of a name in a folder's node, made the first time. */
83
+ child(parent, name) {
84
+ const known = this.children.get(parent)?.get(name);
85
+ if (known !== undefined)
86
+ return known;
87
+ const id = this.next;
88
+ this.link(id, { parent, name });
89
+ this.journal.push(`m ${id} ${parent} ${JSON.stringify(name)}`);
90
+ return id;
91
+ }
92
+ /** A rename through the mount: the node moves, and whatever the new name
93
+ * held before is forgotten. */
94
+ moved(fromParent, fromName, toParent, toName) {
95
+ const id = this.children.get(fromParent)?.get(fromName);
96
+ if (id === undefined) {
97
+ this.forget(toParent, toName);
98
+ return;
99
+ }
100
+ if (fromParent === toParent && fromName === toName)
101
+ return;
102
+ this.forget(toParent, toName);
103
+ this.unlink(id);
104
+ this.link(id, { parent: toParent, name: toName });
105
+ this.journal.push(`v ${id} ${toParent} ${JSON.stringify(toName)}`);
106
+ }
107
+ /** A removal through the mount: the name's node and everything beneath it. */
108
+ forget(parent, name) {
109
+ const id = this.children.get(parent)?.get(name);
110
+ if (id === undefined)
111
+ return;
112
+ this.drop(id);
113
+ this.journal.push(`f ${id}`);
114
+ }
115
+ /** Writes the changes since the last flush, in one write. */
116
+ flush() {
117
+ if (this.journal.length === 0)
118
+ return;
119
+ const fd = openSync(this.file, "a");
120
+ try {
121
+ writeSync(fd, this.journal.join("\n") + "\n");
122
+ }
123
+ finally {
124
+ closeSync(fd);
125
+ }
126
+ this.journal = [];
127
+ }
128
+ mac(id) {
129
+ const bytes = Buffer.allocUnsafe(8);
130
+ bytes.writeBigUInt64BE(id);
131
+ return createHmac("sha256", this.secret).update(bytes).digest().subarray(0, 8);
132
+ }
133
+ link(id, node) {
134
+ this.nodes.set(id, node);
135
+ let names = this.children.get(node.parent);
136
+ if (!names)
137
+ this.children.set(node.parent, names = new Map());
138
+ names.set(node.name, id);
139
+ if (id >= this.next)
140
+ this.next = id + 1n;
141
+ }
142
+ unlink(id) {
143
+ const node = this.nodes.get(id);
144
+ this.children.get(node.parent)?.delete(node.name);
145
+ this.nodes.delete(id);
146
+ }
147
+ drop(id) {
148
+ for (const child of this.children.get(id)?.values() ?? [])
149
+ this.drop(child);
150
+ this.children.delete(id);
151
+ this.unlink(id);
152
+ }
153
+ /** One journal line applied; false for a line that is torn or unknown. */
154
+ replay(line) {
155
+ const match = /^(m|v) (\d+) (\d+) (".*")$|^f (\d+)$/.exec(line);
156
+ if (!match)
157
+ return false;
158
+ if (match[5] !== undefined) {
159
+ const id = BigInt(match[5]);
160
+ if (this.nodes.has(id))
161
+ this.drop(id);
162
+ return true;
163
+ }
164
+ let name;
165
+ try {
166
+ name = JSON.parse(match[4]);
167
+ }
168
+ catch {
169
+ return false;
170
+ }
171
+ if (typeof name !== "string")
172
+ return false;
173
+ const id = BigInt(match[2]);
174
+ const parent = BigInt(match[3]);
175
+ if (parent !== ROOT && !this.nodes.has(parent))
176
+ return false;
177
+ if (this.nodes.has(id))
178
+ this.unlink(id);
179
+ const held = this.children.get(parent)?.get(name);
180
+ if (held !== undefined)
181
+ this.drop(held);
182
+ this.link(id, { parent, name });
183
+ return true;
184
+ }
185
+ /** The journal written afresh: its secret and the next number, so a
186
+ * forgotten node's number is never handed out again, then every live node,
187
+ * parents first, in place of the old one. */
188
+ rewrite() {
189
+ const lines = [`amalgm-nfs-handles 1 ${this.secret.toString("hex")} ${this.next}`];
190
+ const queue = [ROOT];
191
+ for (let i = 0; i < queue.length; i++) {
192
+ for (const [name, id] of this.children.get(queue[i]) ?? []) {
193
+ lines.push(`m ${id} ${queue[i]} ${JSON.stringify(name)}`);
194
+ queue.push(id);
195
+ }
196
+ }
197
+ const fresh = `${this.file}.${process.pid}.tmp`;
198
+ const fd = openSync(fresh, "w", 0o600);
199
+ try {
200
+ writeSync(fd, lines.join("\n") + "\n");
201
+ fsyncSync(fd);
202
+ }
203
+ finally {
204
+ closeSync(fd);
205
+ }
206
+ renameSync(fresh, this.file);
207
+ }
208
+ }
209
+ //# sourceMappingURL=handles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handles.js","sourceRoot":"","sources":["../../../src/drive/nfs/handles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE1G,MAAM,IAAI,GAAG,EAAE,CAAC;AAOhB,MAAM,OAAO,OAAO;IAQmB;IAA+B;IAPpE,sDAAsD;IAC7C,IAAI,GAAG,IAAI,CAAC;IACJ,KAAK,GAAG,IAAI,GAAG,EAAgB,CAAC;IAChC,QAAQ,GAAG,IAAI,GAAG,EAA+B,CAAC;IAC3D,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;IACjB,OAAO,GAAa,EAAE,CAAC;IAE/B,YAAqC,IAAY,EAAmB,MAAc;QAA7C,SAAI,GAAJ,IAAI,CAAQ;QAAmB,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAEtF;;;iEAG6D;IAC7D,MAAM,CAAC,IAAI,CAAC,IAAY;QACtB,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7E,MAAM,MAAM,GAAG,6CAA6C,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAA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;QAChD,MAAM,EAAE,GAAG,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QACvC,IAAI,CAAC;YACH,SAAS,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;YACvC,SAAS,CAAC,EAAE,CAAC,CAAC;QAChB,CAAC;gBAAS,CAAC;YACT,SAAS,CAAC,EAAE,CAAC,CAAC;QAChB,CAAC;QACD,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The MOUNT protocol, version 3 (RFC 1813, appendix I): how a client asks for
3
+ * the drive's root handle before it speaks NFS. The drive exports one path,
4
+ * and only while its own program mounts it (../nfs.ts): a mount of it gets
5
+ * the root's handle and AUTH_SYS as its flavor. Any caller may ask; the
6
+ * answer is the gate.
7
+ */
8
+ import type { Program } from "./server.js";
9
+ export declare const MOUNT_PROGRAM = 100005;
10
+ export interface MountProgramInput {
11
+ /** The one path a client may mount now, or null while none may. */
12
+ readonly exportPath: () => string | null;
13
+ /** The root's handle, as the NFS program knows it. */
14
+ readonly root: Buffer;
15
+ }
16
+ export declare function mountProgram({ exportPath, root }: MountProgramInput): Program;
@@ -0,0 +1,38 @@
1
+ export const MOUNT_PROGRAM = 100005;
2
+ const MNTPATHLEN = 1024;
3
+ const MNT3_OK = 0;
4
+ const MNT3ERR_ACCES = 13;
5
+ const AUTH_SYS = 1;
6
+ export function mountProgram({ exportPath, root }) {
7
+ return {
8
+ number: MOUNT_PROGRAM,
9
+ version: 3,
10
+ admits: () => true,
11
+ async answer({ procedure, args }) {
12
+ switch (procedure) {
13
+ case 0: return () => { };
14
+ case 1: {
15
+ const asked = args.string(MNTPATHLEN);
16
+ const open = exportPath();
17
+ if (open === null || asked !== open)
18
+ return (w) => w.uint(MNT3ERR_ACCES);
19
+ return (w) => w.uint(MNT3_OK).opaque(root).uint(1).uint(AUTH_SYS);
20
+ }
21
+ // DUMP: the server keeps no list of who mounted it.
22
+ case 2: return (w) => w.bool(false);
23
+ // UMNT and UMNTALL: nothing to forget, for the same reason.
24
+ case 3:
25
+ args.string(MNTPATHLEN);
26
+ return () => { };
27
+ case 4: return () => { };
28
+ // EXPORT: the path open now, if any, to every host that may connect.
29
+ case 5: {
30
+ const open = exportPath();
31
+ return (w) => (open === null ? w.bool(false) : w.bool(true).string(open).bool(false).bool(false));
32
+ }
33
+ default: return null;
34
+ }
35
+ },
36
+ };
37
+ }
38
+ //# sourceMappingURL=mount3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount3.js","sourceRoot":"","sources":["../../../src/drive/nfs/mount3.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AAEpC,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,OAAO,GAAG,CAAC,CAAC;AAClB,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,QAAQ,GAAG,CAAC,CAAC;AASnB,MAAM,UAAU,YAAY,CAAC,EAAE,UAAU,EAAE,IAAI,EAAqB;IAClE,OAAO;QACL,MAAM,EAAE,aAAa;QACrB,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI;QAClB,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE;YAC9B,QAAQ,SAAS,EAAE,CAAC;gBAClB,KAAK,CAAC,CAAC,CAAC,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;gBACxB,KAAK,CAAC,CAAC,CAAC,CAAC;oBACP,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;oBACtC,MAAM,IAAI,GAAG,UAAU,EAAE,CAAC;oBAC1B,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI;wBAAE,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;oBACzE,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACpE,CAAC;gBACD,oDAAoD;gBACpD,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACpC,4DAA4D;gBAC5D,KAAK,CAAC;oBAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;oBAAC,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;gBACjD,KAAK,CAAC,CAAC,CAAC,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;gBACxB,qEAAqE;gBACrE,KAAK,CAAC,CAAC,CAAC,CAAC;oBACP,MAAM,IAAI,GAAG,UAAU,EAAE,CAAC;oBAC1B,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;gBACpG,CAAC;gBACD,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC;YACvB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { DriveOperations } from "../operations.js";
2
+ import type { Handles } from "./handles.js";
3
+ import type { Credential } from "./rpc.js";
4
+ import type { Program } from "./server.js";
5
+ export declare const NFS_PROGRAM = 100003;
6
+ /** The largest READ or WRITE the drive answers, as FSINFO tells the client. */
7
+ export declare const TRANSFER_MAX: number;
8
+ /** One procedure answered. */
9
+ export interface NfsTrace {
10
+ readonly procedure: string;
11
+ /** The kernel path the procedure named first. */
12
+ readonly path: string;
13
+ readonly status: number;
14
+ readonly ms: number;
15
+ }
16
+ export interface NfsProgramInput {
17
+ /** The operations serving now: over the ground that converged last, or at rest. */
18
+ readonly operations: () => DriveOperations;
19
+ readonly handles: Handles;
20
+ /** This server's start, as WRITE and COMMIT name it: a client whose unstable
21
+ * writes an earlier start answered writes them again. */
22
+ readonly verifier: Buffer;
23
+ /** Who may call, by the credential the call carries. */
24
+ readonly admits: (credential: Credential) => boolean;
25
+ readonly trace?: (event: NfsTrace) => void;
26
+ }
27
+ export declare function nfsProgram(input: NfsProgramInput): Program;