@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.
- package/dist/cli.js +34 -41
- package/dist/cli.js.map +1 -1
- package/dist/drive/fuse.d.ts +13 -116
- package/dist/drive/fuse.js +36 -145
- package/dist/drive/fuse.js.map +1 -1
- package/dist/drive/kernel.d.ts +17 -0
- package/dist/drive/kernel.js +32 -0
- package/dist/drive/kernel.js.map +1 -0
- package/dist/drive/layout.d.ts +2 -0
- package/dist/drive/layout.js +8 -4
- package/dist/drive/layout.js.map +1 -1
- package/dist/drive/mount.d.ts +16 -6
- package/dist/drive/mount.js +50 -24
- package/dist/drive/mount.js.map +1 -1
- package/dist/drive/mountpoint.d.ts +14 -0
- package/dist/drive/mountpoint.js +51 -0
- package/dist/drive/mountpoint.js.map +1 -0
- package/dist/drive/nfs/apple-double.d.ts +6 -0
- package/dist/drive/nfs/apple-double.js +140 -0
- package/dist/drive/nfs/apple-double.js.map +1 -0
- package/dist/drive/nfs/attributes.d.ts +64 -0
- package/dist/drive/nfs/attributes.js +97 -0
- package/dist/drive/nfs/attributes.js.map +1 -0
- package/dist/drive/nfs/handles.d.ts +44 -0
- package/dist/drive/nfs/handles.js +209 -0
- package/dist/drive/nfs/handles.js.map +1 -0
- package/dist/drive/nfs/mount3.d.ts +16 -0
- package/dist/drive/nfs/mount3.js +38 -0
- package/dist/drive/nfs/mount3.js.map +1 -0
- package/dist/drive/nfs/nfs3.d.ts +27 -0
- package/dist/drive/nfs/nfs3.js +458 -0
- package/dist/drive/nfs/nfs3.js.map +1 -0
- package/dist/drive/nfs/rpc.d.ts +66 -0
- package/dist/drive/nfs/rpc.js +122 -0
- package/dist/drive/nfs/rpc.js.map +1 -0
- package/dist/drive/nfs/server.d.ts +30 -0
- package/dist/drive/nfs/server.js +109 -0
- package/dist/drive/nfs/server.js.map +1 -0
- package/dist/drive/nfs/xdr.d.ts +44 -0
- package/dist/drive/nfs/xdr.js +111 -0
- package/dist/drive/nfs/xdr.js.map +1 -0
- package/dist/drive/nfs.d.ts +60 -0
- package/dist/drive/nfs.js +181 -0
- package/dist/drive/nfs.js.map +1 -0
- package/dist/drive/operations.d.ts +125 -0
- package/dist/drive/operations.js +141 -0
- package/dist/drive/operations.js.map +1 -0
- package/dist/error-facts.d.ts +24 -0
- package/dist/error-facts.js +35 -0
- package/dist/error-facts.js.map +1 -0
- package/dist/files-program/client.d.ts +122 -0
- package/dist/files-program/client.js +430 -0
- package/dist/files-program/client.js.map +1 -0
- package/dist/files-program/journeys.d.ts +15 -0
- package/dist/files-program/journeys.js +79 -0
- package/dist/files-program/journeys.js.map +1 -0
- package/dist/files-program/program.d.ts +1 -0
- package/dist/files-program/program.js +255 -0
- package/dist/files-program/program.js.map +1 -0
- package/dist/files-program/protocol.d.ts +154 -0
- package/dist/files-program/protocol.js +7 -0
- package/dist/files-program/protocol.js.map +1 -0
- package/dist/machine-host.d.ts +35 -32
- package/dist/machine-host.js +124 -195
- package/dist/machine-host.js.map +1 -1
- package/dist/runtime-node-flags.d.ts +6 -6
- package/dist/runtime-node-flags.js +6 -6
- package/dist/sharing-host.d.ts +6 -11
- package/dist/sharing-host.js +6 -10
- package/dist/sharing-host.js.map +1 -1
- package/dist/sync-cli.js +1 -1
- package/dist/sync-cli.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -4
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONC RPC version 2 (RFC 5531) over TCP, as the drive's NFS server speaks it:
|
|
3
|
+
* records split into fragments (record marking), calls read with their
|
|
4
|
+
* AUTH_SYS credential, replies written accepted or denied. Nothing here knows
|
|
5
|
+
* a program; `server.ts` dispatches each call to MOUNT or NFS.
|
|
6
|
+
*/
|
|
7
|
+
import { XdrReader, XdrWriter } from "./xdr.js";
|
|
8
|
+
const CALL = 0;
|
|
9
|
+
const REPLY = 1;
|
|
10
|
+
const RPC_VERSION = 2;
|
|
11
|
+
const MSG_ACCEPTED = 0;
|
|
12
|
+
const MSG_DENIED = 1;
|
|
13
|
+
const AUTH_NONE = 0;
|
|
14
|
+
const AUTH_SYS = 1;
|
|
15
|
+
const LAST_FRAGMENT = 0x80000000;
|
|
16
|
+
/** Why an accepted call did not run. */
|
|
17
|
+
export const ACCEPT = { SUCCESS: 0, PROG_UNAVAIL: 1, PROG_MISMATCH: 2, PROC_UNAVAIL: 3, GARBAGE_ARGS: 4, SYSTEM_ERR: 5 };
|
|
18
|
+
/** Why a credential was refused. */
|
|
19
|
+
export const AUTH = { BADCRED: 1, REJECTEDCRED: 2, TOOWEAK: 5 };
|
|
20
|
+
/** A record's call, or the reply that refuses it before any program sees
|
|
21
|
+
* it; null for a record that is not a call at all, which gets no reply. */
|
|
22
|
+
export function readCall(record) {
|
|
23
|
+
const reader = new XdrReader(record);
|
|
24
|
+
const xid = reader.uint();
|
|
25
|
+
if (reader.uint() !== CALL)
|
|
26
|
+
return null;
|
|
27
|
+
if (reader.uint() !== RPC_VERSION)
|
|
28
|
+
return { refused: denied(xid, (w) => w.uint(0).uint(RPC_VERSION).uint(RPC_VERSION)) };
|
|
29
|
+
const program = reader.uint();
|
|
30
|
+
const version = reader.uint();
|
|
31
|
+
const procedure = reader.uint();
|
|
32
|
+
const flavor = reader.uint();
|
|
33
|
+
const body = reader.opaque(400);
|
|
34
|
+
reader.uint();
|
|
35
|
+
reader.opaque(400);
|
|
36
|
+
let credential = { flavor, uid: null, gid: null };
|
|
37
|
+
if (flavor === AUTH_SYS) {
|
|
38
|
+
const sys = new XdrReader(body);
|
|
39
|
+
sys.uint();
|
|
40
|
+
sys.string(255);
|
|
41
|
+
credential = { flavor, uid: sys.uint(), gid: sys.uint() };
|
|
42
|
+
}
|
|
43
|
+
return { xid, program, version, procedure, credential, args: reader };
|
|
44
|
+
}
|
|
45
|
+
/** An accepted reply: SUCCESS with the procedure's results, or another
|
|
46
|
+
* accept status with its own body. */
|
|
47
|
+
export function accepted(xid, status, results) {
|
|
48
|
+
const w = new XdrWriter().uint(xid).uint(REPLY).uint(MSG_ACCEPTED).uint(AUTH_NONE).uint(0).uint(status);
|
|
49
|
+
results?.(w);
|
|
50
|
+
return w.bytesWritten();
|
|
51
|
+
}
|
|
52
|
+
/** A PROG_MISMATCH reply naming the versions this server speaks. */
|
|
53
|
+
export function mismatched(xid, low, high) {
|
|
54
|
+
return accepted(xid, ACCEPT.PROG_MISMATCH, (w) => w.uint(low).uint(high));
|
|
55
|
+
}
|
|
56
|
+
/** An AUTH_ERROR reply: the credential is refused. */
|
|
57
|
+
export function refusedCredential(xid, why) {
|
|
58
|
+
return denied(xid, (w) => w.uint(1).uint(why));
|
|
59
|
+
}
|
|
60
|
+
function denied(xid, body) {
|
|
61
|
+
const w = new XdrWriter().uint(xid).uint(REPLY).uint(MSG_DENIED);
|
|
62
|
+
body(w);
|
|
63
|
+
return w.bytesWritten();
|
|
64
|
+
}
|
|
65
|
+
/** One reply's record-marking header: a single, last fragment. */
|
|
66
|
+
export function fragmentHeader(length) {
|
|
67
|
+
const header = Buffer.allocUnsafe(4);
|
|
68
|
+
header.writeUInt32BE((LAST_FRAGMENT | length) >>> 0);
|
|
69
|
+
return header;
|
|
70
|
+
}
|
|
71
|
+
/** Joins a TCP stream's fragments into whole records, refusing any record
|
|
72
|
+
* longer than `max` so a peer cannot make the server hold unbounded bytes. */
|
|
73
|
+
export class Records {
|
|
74
|
+
max;
|
|
75
|
+
pending = [];
|
|
76
|
+
pendingLength = 0;
|
|
77
|
+
fragments = [];
|
|
78
|
+
recordLength = 0;
|
|
79
|
+
constructor(max) {
|
|
80
|
+
this.max = max;
|
|
81
|
+
}
|
|
82
|
+
/** The records the stream completes with this chunk. */
|
|
83
|
+
push(chunk) {
|
|
84
|
+
this.pending.push(chunk);
|
|
85
|
+
this.pendingLength += chunk.length;
|
|
86
|
+
const records = [];
|
|
87
|
+
for (;;) {
|
|
88
|
+
if (this.pendingLength < 4)
|
|
89
|
+
return records;
|
|
90
|
+
const head = this.peek(4).readUInt32BE(0);
|
|
91
|
+
const length = head & ~LAST_FRAGMENT;
|
|
92
|
+
if (this.recordLength + length > this.max)
|
|
93
|
+
throw new Error(`a record longer than ${this.max} bytes`);
|
|
94
|
+
if (this.pendingLength < 4 + length)
|
|
95
|
+
return records;
|
|
96
|
+
this.take(4);
|
|
97
|
+
this.fragments.push(this.take(length));
|
|
98
|
+
this.recordLength += length;
|
|
99
|
+
if ((head & LAST_FRAGMENT) === 0)
|
|
100
|
+
continue;
|
|
101
|
+
records.push(this.fragments.length === 1 ? this.fragments[0] : Buffer.concat(this.fragments));
|
|
102
|
+
this.fragments = [];
|
|
103
|
+
this.recordLength = 0;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
peek(length) {
|
|
107
|
+
if (this.pending[0].length < length)
|
|
108
|
+
this.pending = [Buffer.concat(this.pending)];
|
|
109
|
+
return this.pending[0];
|
|
110
|
+
}
|
|
111
|
+
take(length) {
|
|
112
|
+
const joined = this.peek(length);
|
|
113
|
+
const taken = joined.subarray(0, length);
|
|
114
|
+
if (joined.length === length)
|
|
115
|
+
this.pending.shift();
|
|
116
|
+
else
|
|
117
|
+
this.pending[0] = joined.subarray(length);
|
|
118
|
+
this.pendingLength -= length;
|
|
119
|
+
return taken;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=rpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../src/drive/nfs/rpc.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEhD,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,KAAK,GAAG,CAAC,CAAC;AAChB,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,UAAU,G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AC,CAAE,CAAC;IAC1B,CAAC;IAEO,IAAI,CAAC,MAAc;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACzC,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM;YAAE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;;YAC9C,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,aAAa,IAAI,MAAM,CAAC;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Call, type Credential } from "./rpc.js";
|
|
2
|
+
import { type XdrWriter } from "./xdr.js";
|
|
3
|
+
/** A procedure's results, written after the reply's accept status. */
|
|
4
|
+
export type Results = (w: XdrWriter) => void;
|
|
5
|
+
export interface Program {
|
|
6
|
+
readonly number: number;
|
|
7
|
+
readonly version: number;
|
|
8
|
+
/** Procedures a retry must not run again: it gets the first answer. */
|
|
9
|
+
readonly once?: ReadonlySet<number>;
|
|
10
|
+
/** Whether a credential may call this program. */
|
|
11
|
+
admits(credential: Credential): boolean;
|
|
12
|
+
/** A call's results, or null for a procedure this program does not have.
|
|
13
|
+
* An `XdrError` means the arguments could not be read. */
|
|
14
|
+
answer(call: Call): Promise<Results | null>;
|
|
15
|
+
}
|
|
16
|
+
export interface RpcServerInput {
|
|
17
|
+
/** The port to listen on; 0 for any free one. */
|
|
18
|
+
readonly port: number;
|
|
19
|
+
readonly programs: readonly Program[];
|
|
20
|
+
/** The largest record a client may send. */
|
|
21
|
+
readonly max: number;
|
|
22
|
+
/** A call that failed for a reason no program names: answered SYSTEM_ERR. */
|
|
23
|
+
readonly onFault?: (error: unknown, call: Call) => void;
|
|
24
|
+
}
|
|
25
|
+
export interface RpcServer {
|
|
26
|
+
readonly port: number;
|
|
27
|
+
/** Stops listening and closes every connection. */
|
|
28
|
+
close(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export declare function serveRpc({ port, programs, max, onFault }: RpcServerInput): Promise<RpcServer>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The drive's ONC RPC server: TCP on the loopback address, each record one
|
|
3
|
+
* call, dispatched to the program it names (MOUNT or NFS). Calls on one
|
|
4
|
+
* connection are answered as each finishes, not in turn, so a slow placement
|
|
5
|
+
* never holds a stat behind it; a reply names its call by xid.
|
|
6
|
+
*
|
|
7
|
+
* A client that heard no answer sends the same call again, maybe on a new
|
|
8
|
+
* connection. A retry of a procedure that must not run twice (a creation, a
|
|
9
|
+
* removal, a rename) gets the first answer instead, as the server's
|
|
10
|
+
* duplicate-request cache.
|
|
11
|
+
*/
|
|
12
|
+
import { createServer } from "node:net";
|
|
13
|
+
import { ACCEPT, accepted, AUTH, fragmentHeader, mismatched, readCall, Records, refusedCredential } from "./rpc.js";
|
|
14
|
+
import { XdrError } from "./xdr.js";
|
|
15
|
+
/** How many answers to `once` procedures a retry can still find. */
|
|
16
|
+
const REMEMBERED = 1024;
|
|
17
|
+
export async function serveRpc({ port, programs, max, onFault }) {
|
|
18
|
+
const byNumber = new Map(programs.map((program) => [program.number, program]));
|
|
19
|
+
const remembered = new Map();
|
|
20
|
+
const sockets = new Set();
|
|
21
|
+
async function answer(program, call) {
|
|
22
|
+
try {
|
|
23
|
+
const results = await program.answer(call);
|
|
24
|
+
return results ? accepted(call.xid, ACCEPT.SUCCESS, results) : accepted(call.xid, ACCEPT.PROC_UNAVAIL);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error instanceof XdrError)
|
|
28
|
+
return accepted(call.xid, ACCEPT.GARBAGE_ARGS);
|
|
29
|
+
onFault?.(error, call);
|
|
30
|
+
return accepted(call.xid, ACCEPT.SYSTEM_ERR);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** A record's reply; null for a record that is not a call. */
|
|
34
|
+
function reply(record) {
|
|
35
|
+
let call;
|
|
36
|
+
try {
|
|
37
|
+
call = readCall(record);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (call === null)
|
|
43
|
+
return null;
|
|
44
|
+
if ("refused" in call)
|
|
45
|
+
return call.refused;
|
|
46
|
+
const program = byNumber.get(call.program);
|
|
47
|
+
if (!program)
|
|
48
|
+
return accepted(call.xid, ACCEPT.PROG_UNAVAIL);
|
|
49
|
+
if (call.version !== program.version)
|
|
50
|
+
return mismatched(call.xid, program.version, program.version);
|
|
51
|
+
if (!program.admits(call.credential))
|
|
52
|
+
return refusedCredential(call.xid, AUTH.TOOWEAK);
|
|
53
|
+
if (!program.once?.has(call.procedure))
|
|
54
|
+
return answer(program, call);
|
|
55
|
+
const key = `${call.xid}:${call.program}:${call.procedure}`;
|
|
56
|
+
const first = remembered.get(key);
|
|
57
|
+
if (first)
|
|
58
|
+
return first;
|
|
59
|
+
const answered = answer(program, call);
|
|
60
|
+
remembered.set(key, answered);
|
|
61
|
+
if (remembered.size > REMEMBERED)
|
|
62
|
+
remembered.delete(remembered.keys().next().value);
|
|
63
|
+
return answered;
|
|
64
|
+
}
|
|
65
|
+
const server = createServer((socket) => {
|
|
66
|
+
sockets.add(socket);
|
|
67
|
+
socket.setNoDelay(true);
|
|
68
|
+
const records = new Records(max);
|
|
69
|
+
socket.on("data", (chunk) => {
|
|
70
|
+
let complete;
|
|
71
|
+
try {
|
|
72
|
+
complete = records.push(chunk);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
socket.destroy();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
for (const record of complete) {
|
|
79
|
+
void Promise.resolve(reply(record)).then((bytes) => {
|
|
80
|
+
if (!bytes || socket.destroyed)
|
|
81
|
+
return;
|
|
82
|
+
socket.cork();
|
|
83
|
+
socket.write(fragmentHeader(bytes.length));
|
|
84
|
+
socket.write(bytes);
|
|
85
|
+
socket.uncork();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
socket.on("error", () => socket.destroy());
|
|
90
|
+
socket.on("close", () => sockets.delete(socket));
|
|
91
|
+
});
|
|
92
|
+
await new Promise((resolve, reject) => {
|
|
93
|
+
server.once("error", reject);
|
|
94
|
+
server.listen(port, "127.0.0.1", () => {
|
|
95
|
+
server.off("error", reject);
|
|
96
|
+
resolve();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
const address = server.address();
|
|
100
|
+
return {
|
|
101
|
+
port: typeof address === "object" && address ? address.port : port,
|
|
102
|
+
close: () => new Promise((resolve) => {
|
|
103
|
+
for (const socket of sockets)
|
|
104
|
+
socket.destroy();
|
|
105
|
+
server.close(() => resolve());
|
|
106
|
+
}),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/drive/nfs/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,EAA8B,MAAM,UAAU,CAAC;AAChJ,OAAO,EAAE,QAAQ,EAAkB,MAAM,UAAU,CAAC;AAiCpD,oEAAoE;AACpE,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAkB;IAC7E,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC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AAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC5B,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IACjC,OAAO;QACL,IAAI,EAAE,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;QAClE,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YACzC,KAAK,MAAM,MAAM,IAAI,OAAO;gBAAE,MAAM,CAAC,OAAO,EAAE,CAAC;YAC/C,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAChC,CAAC,CAAC;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XDR (RFC 4506), the encoding every ONC RPC message is written in: big-endian
|
|
3
|
+
* 4-byte units, variable-length data padded to a multiple of four. Only what
|
|
4
|
+
* RPC, MOUNT and NFSv3 use is here.
|
|
5
|
+
*/
|
|
6
|
+
/** A message being read; reading past its end throws `XdrError`, which the
|
|
7
|
+
* server answers as GARBAGE_ARGS. */
|
|
8
|
+
export declare class XdrReader {
|
|
9
|
+
private readonly bytes;
|
|
10
|
+
private offset;
|
|
11
|
+
constructor(bytes: Buffer);
|
|
12
|
+
uint(): number;
|
|
13
|
+
hyper(): bigint;
|
|
14
|
+
bool(): boolean;
|
|
15
|
+
/** Fixed-length opaque data, `length` bytes and its padding. */
|
|
16
|
+
fixed(length: number): Buffer;
|
|
17
|
+
/** Variable-length opaque data no longer than `max`. */
|
|
18
|
+
opaque(max: number): Buffer;
|
|
19
|
+
string(max: number): string;
|
|
20
|
+
/** Whether every byte was read. */
|
|
21
|
+
done(): boolean;
|
|
22
|
+
private need;
|
|
23
|
+
}
|
|
24
|
+
/** A message being written, grown as it is written. */
|
|
25
|
+
export declare class XdrWriter {
|
|
26
|
+
private bytes;
|
|
27
|
+
private offset;
|
|
28
|
+
uint(value: number): this;
|
|
29
|
+
hyper(value: bigint | number): this;
|
|
30
|
+
bool(value: boolean): this;
|
|
31
|
+
fixed(value: Uint8Array): this;
|
|
32
|
+
opaque(value: Uint8Array): this;
|
|
33
|
+
string(value: string): this;
|
|
34
|
+
/** How many bytes are written. */
|
|
35
|
+
get length(): number;
|
|
36
|
+
/** The bytes written, without copying them. */
|
|
37
|
+
bytesWritten(): Buffer;
|
|
38
|
+
private room;
|
|
39
|
+
}
|
|
40
|
+
export declare class XdrError extends Error {
|
|
41
|
+
readonly name = "XdrError";
|
|
42
|
+
}
|
|
43
|
+
/** A length rounded up to whole 4-byte units. */
|
|
44
|
+
export declare function pad(length: number): number;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XDR (RFC 4506), the encoding every ONC RPC message is written in: big-endian
|
|
3
|
+
* 4-byte units, variable-length data padded to a multiple of four. Only what
|
|
4
|
+
* RPC, MOUNT and NFSv3 use is here.
|
|
5
|
+
*/
|
|
6
|
+
/** A message being read; reading past its end throws `XdrError`, which the
|
|
7
|
+
* server answers as GARBAGE_ARGS. */
|
|
8
|
+
export class XdrReader {
|
|
9
|
+
bytes;
|
|
10
|
+
offset = 0;
|
|
11
|
+
constructor(bytes) {
|
|
12
|
+
this.bytes = bytes;
|
|
13
|
+
}
|
|
14
|
+
uint() {
|
|
15
|
+
this.need(4);
|
|
16
|
+
const value = this.bytes.readUInt32BE(this.offset);
|
|
17
|
+
this.offset += 4;
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
hyper() {
|
|
21
|
+
this.need(8);
|
|
22
|
+
const value = this.bytes.readBigUInt64BE(this.offset);
|
|
23
|
+
this.offset += 8;
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
bool() {
|
|
27
|
+
return this.uint() !== 0;
|
|
28
|
+
}
|
|
29
|
+
/** Fixed-length opaque data, `length` bytes and its padding. */
|
|
30
|
+
fixed(length) {
|
|
31
|
+
this.need(pad(length));
|
|
32
|
+
const value = this.bytes.subarray(this.offset, this.offset + length);
|
|
33
|
+
this.offset += pad(length);
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
/** Variable-length opaque data no longer than `max`. */
|
|
37
|
+
opaque(max) {
|
|
38
|
+
const length = this.uint();
|
|
39
|
+
if (length > max)
|
|
40
|
+
throw new XdrError(`opaque of ${length} bytes is longer than ${max}`);
|
|
41
|
+
return this.fixed(length);
|
|
42
|
+
}
|
|
43
|
+
string(max) {
|
|
44
|
+
return this.opaque(max).toString("utf8");
|
|
45
|
+
}
|
|
46
|
+
/** Whether every byte was read. */
|
|
47
|
+
done() {
|
|
48
|
+
return this.offset === this.bytes.length;
|
|
49
|
+
}
|
|
50
|
+
need(length) {
|
|
51
|
+
if (this.offset + length > this.bytes.length)
|
|
52
|
+
throw new XdrError("the message ends early");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** A message being written, grown as it is written. */
|
|
56
|
+
export class XdrWriter {
|
|
57
|
+
bytes = Buffer.allocUnsafe(512);
|
|
58
|
+
offset = 0;
|
|
59
|
+
uint(value) {
|
|
60
|
+
this.room(4);
|
|
61
|
+
this.bytes.writeUInt32BE(value >>> 0, this.offset);
|
|
62
|
+
this.offset += 4;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
hyper(value) {
|
|
66
|
+
this.room(8);
|
|
67
|
+
this.bytes.writeBigUInt64BE(BigInt.asUintN(64, BigInt(value)), this.offset);
|
|
68
|
+
this.offset += 8;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
bool(value) {
|
|
72
|
+
return this.uint(value ? 1 : 0);
|
|
73
|
+
}
|
|
74
|
+
fixed(value) {
|
|
75
|
+
const length = pad(value.length);
|
|
76
|
+
this.room(length);
|
|
77
|
+
this.bytes.set(value, this.offset);
|
|
78
|
+
this.bytes.fill(0, this.offset + value.length, this.offset + length);
|
|
79
|
+
this.offset += length;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
opaque(value) {
|
|
83
|
+
return this.uint(value.length).fixed(value);
|
|
84
|
+
}
|
|
85
|
+
string(value) {
|
|
86
|
+
return this.opaque(Buffer.from(value, "utf8"));
|
|
87
|
+
}
|
|
88
|
+
/** How many bytes are written. */
|
|
89
|
+
get length() {
|
|
90
|
+
return this.offset;
|
|
91
|
+
}
|
|
92
|
+
/** The bytes written, without copying them. */
|
|
93
|
+
bytesWritten() {
|
|
94
|
+
return this.bytes.subarray(0, this.offset);
|
|
95
|
+
}
|
|
96
|
+
room(length) {
|
|
97
|
+
if (this.offset + length <= this.bytes.length)
|
|
98
|
+
return;
|
|
99
|
+
const grown = Buffer.allocUnsafe(Math.max(this.bytes.length * 2, this.offset + length));
|
|
100
|
+
this.bytes.copy(grown, 0, 0, this.offset);
|
|
101
|
+
this.bytes = grown;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export class XdrError extends Error {
|
|
105
|
+
name = "XdrError";
|
|
106
|
+
}
|
|
107
|
+
/** A length rounded up to whole 4-byte units. */
|
|
108
|
+
export function pad(length) {
|
|
109
|
+
return (length + 3) & ~3;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=xdr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xdr.js","sourceRoot":"","sources":["../../../src/drive/nfs/xdr.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;qCACqC;AACrC,MAAM,OAAO,SAAS;IAGS;IAFrB,MAAM,GAAG,CAAC,CAAC;IAEnB,YAA6B,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAE9C,IAAI;QACF,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACb,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,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AU,GAAG,CAAC,MAAc;IAChC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Handles } from "./nfs/handles.js";
|
|
2
|
+
import { type NfsTrace } from "./nfs/nfs3.js";
|
|
3
|
+
import { type RpcServer } from "./nfs/server.js";
|
|
4
|
+
import { type DriveOperations, type MountedDrive, type ServingDrive } from "./operations.js";
|
|
5
|
+
/** The client's options besides where the server listens: TCP, waiting for
|
|
6
|
+
* a server that stopped rather than failing (`hard`, `intr`), locks kept on
|
|
7
|
+
* this computer (there is no lock server), no cache of missing names, so a
|
|
8
|
+
* file another computer adds shows at once, attributes cached one second,
|
|
9
|
+
* whole-megabyte transfers, plain READDIR listings, and no volume icon: the
|
|
10
|
+
* drive is the person's home folder, not a disk.
|
|
11
|
+
*
|
|
12
|
+
* Listings are plain READDIR, never READDIRPLUS, the Mac's default. With
|
|
13
|
+
* READDIRPLUS the Mac answers a `._` name from a folder listing it holds
|
|
14
|
+
* whole, never asking the server, as missing even when it is creating that
|
|
15
|
+
* name; so a file's first extended attribute in a folder already listed is
|
|
16
|
+
* refused until the folder changes. */
|
|
17
|
+
export declare const MOUNT_OPTIONS: readonly string[];
|
|
18
|
+
export interface MountNfsInput extends ServingDrive {
|
|
19
|
+
readonly mountpoint: string;
|
|
20
|
+
/** A private folder for what the mount needs across Files programs: its
|
|
21
|
+
* handles, its port, and the Mac's AppleDouble sidecars. */
|
|
22
|
+
readonly state: string;
|
|
23
|
+
/** Whether the mount table shows a mount standing at the mountpoint
|
|
24
|
+
* (`nfsStanding`): served again, never mounted twice. */
|
|
25
|
+
readonly standing: boolean;
|
|
26
|
+
readonly uid?: number;
|
|
27
|
+
readonly gid?: number;
|
|
28
|
+
/** In place of MOUNT_OPTIONS; the port is always added. */
|
|
29
|
+
readonly options?: readonly string[];
|
|
30
|
+
readonly trace?: (event: NfsTrace) => void;
|
|
31
|
+
/** A call that failed for a reason no NFS status names. */
|
|
32
|
+
readonly onFault?: (error: unknown) => void;
|
|
33
|
+
}
|
|
34
|
+
/** Serves the drive at `mountpoint` through macOS's NFS client. Resolves once
|
|
35
|
+
* the kernel serves it; it stays mounted until `unmount()`, which is for the
|
|
36
|
+
* whole runtime's stop. */
|
|
37
|
+
export declare function mountNfs(input: MountNfsInput): Promise<MountedDrive>;
|
|
38
|
+
export interface DriveServerInput {
|
|
39
|
+
/** The port to listen on; 0 for any free one. */
|
|
40
|
+
readonly port: number;
|
|
41
|
+
readonly handles: Handles;
|
|
42
|
+
/** The operations serving now: over the ground that converged last, or at rest. */
|
|
43
|
+
readonly operations: () => DriveOperations;
|
|
44
|
+
/** The person whose drive this is. */
|
|
45
|
+
readonly uid: number;
|
|
46
|
+
/** The one path MOUNT answers now, or null while none may mount. */
|
|
47
|
+
readonly exportPath: () => string | null;
|
|
48
|
+
readonly trace?: (event: NfsTrace) => void;
|
|
49
|
+
readonly onFault?: (error: unknown) => void;
|
|
50
|
+
}
|
|
51
|
+
/** The drive's RPC server: MOUNT, which hands out the root's handle, and
|
|
52
|
+
* NFS, which answers each procedure by the drive's operations, over one
|
|
53
|
+
* table of handles. It serves AUTH_SYS calls as the person or as root, as
|
|
54
|
+
* the kernel calls for programs root runs; any other user, and a call that
|
|
55
|
+
* names no user, is refused. */
|
|
56
|
+
export declare function driveServer(input: DriveServerInput): Promise<RpcServer>;
|
|
57
|
+
/** Whether an NFS mount stands at `mountpoint`, from the mount table. The
|
|
58
|
+
* folder itself is never looked at: with no server answering, a look waits
|
|
59
|
+
* for one. */
|
|
60
|
+
export declare function nfsStanding(mountpoint: string): Promise<boolean>;
|