@k13engineering/linux-fuse 0.0.1 → 0.0.2
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/lib/abi.d.ts +331 -0
- package/dist/lib/abi.js +1019 -0
- package/dist/lib/constants.d.ts +225 -0
- package/dist/lib/constants.js +272 -0
- package/dist/lib/convenience.d.ts +63 -0
- package/dist/lib/convenience.js +463 -0
- package/dist/lib/fuse-lowlevel.d.ts +42 -0
- package/dist/lib/fuse-lowlevel.js +133 -0
- package/dist/lib/index.d.ts +40 -0
- package/dist/lib/index.js +313 -0
- package/dist/lib/linux.d.ts +12 -0
- package/dist/lib/linux.js +32 -0
- package/dist/lib/message.d.ts +50 -0
- package/dist/lib/message.js +177 -0
- package/dist/lib/mount.d.ts +33 -0
- package/dist/lib/mount.js +149 -0
- package/dist/lib/protocol.d.ts +756 -0
- package/dist/lib/protocol.js +3783 -0
- package/dist/lib/server.d.ts +18 -0
- package/dist/lib/server.js +73 -0
- package/dist/lib/syscalls.d.ts +73 -0
- package/dist/lib/syscalls.js +275 -0
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type TFuseRequest, type TFuseResponse } from "./protocol.js";
|
|
2
|
+
type TRequestHandler = {
|
|
3
|
+
handleRequest: (args: {
|
|
4
|
+
request: TFuseRequest;
|
|
5
|
+
}) => Promise<TFuseResponse | undefined>;
|
|
6
|
+
};
|
|
7
|
+
declare const createFuseServer: ({ requestHandler, sendMessageToKernel, }: {
|
|
8
|
+
requestHandler: TRequestHandler;
|
|
9
|
+
sendMessageToKernel: ({ rawMessageToKernel }: {
|
|
10
|
+
rawMessageToKernel: Uint8Array;
|
|
11
|
+
}) => void;
|
|
12
|
+
}) => {
|
|
13
|
+
processRequest: ({ rawIncomingRequest }: {
|
|
14
|
+
rawIncomingRequest: Uint8Array;
|
|
15
|
+
}) => void;
|
|
16
|
+
};
|
|
17
|
+
export { createFuseServer };
|
|
18
|
+
export type { TRequestHandler, };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMessageFromKernelParser,
|
|
3
|
+
createMessageToKernelParser,
|
|
4
|
+
/*type TParsedMessageToKernel
|
|
5
|
+
*/} from "./message.js";
|
|
6
|
+
import {
|
|
7
|
+
createMessageFromKernelInterpreter,
|
|
8
|
+
createMessageToKernelInterpreter,
|
|
9
|
+
/*type TFuseRequest,
|
|
10
|
+
*//*type TFuseResponse
|
|
11
|
+
*/} from "./protocol.js";
|
|
12
|
+
|
|
13
|
+
/*type TRequestHandler = {
|
|
14
|
+
handleRequest: (args: { request: TFuseRequest }) => Promise<TFuseResponse | undefined>;
|
|
15
|
+
};*/
|
|
16
|
+
|
|
17
|
+
const createFuseServer = ({
|
|
18
|
+
requestHandler,
|
|
19
|
+
sendMessageToKernel,
|
|
20
|
+
}/*: {
|
|
21
|
+
requestHandler: TRequestHandler;
|
|
22
|
+
sendMessageToKernel: ({ rawMessageToKernel }: { rawMessageToKernel: Uint8Array }) => void;
|
|
23
|
+
}*/) => {
|
|
24
|
+
const messageFromKernelInterpreter = createMessageFromKernelInterpreter();
|
|
25
|
+
const messageToKernelInterpreter = createMessageToKernelInterpreter();
|
|
26
|
+
|
|
27
|
+
const messageFromKernelParser = createMessageFromKernelParser();
|
|
28
|
+
const messageToKernelParser = createMessageToKernelParser();
|
|
29
|
+
|
|
30
|
+
const processRequest = ({ rawIncomingRequest }/*: { rawIncomingRequest: Uint8Array }*/) => {
|
|
31
|
+
|
|
32
|
+
const { error: parseError, parsedMessageFromKernel } = messageFromKernelParser.parseMessageFromKernel({ data: rawIncomingRequest });
|
|
33
|
+
if (parseError !== undefined) {
|
|
34
|
+
throw Error("not implemented yet", { cause: parseError });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { error: interpretError, interpreted } = messageFromKernelInterpreter.interpretMessageFromKernel({ parsedMessageFromKernel });
|
|
38
|
+
if (interpretError !== undefined) {
|
|
39
|
+
throw Error("not implemented yet", { cause: interpretError });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
requestHandler.handleRequest({ request: interpreted }).then((response) => {
|
|
43
|
+
if (response !== undefined) {
|
|
44
|
+
|
|
45
|
+
let encoded/*: TParsedMessageToKernel*/;
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
encoded = messageToKernelInterpreter.encodeMessageToKernel({ response });
|
|
49
|
+
} catch (ex) {
|
|
50
|
+
throw Error(`failed to encode response for opcode ${response.forOpcode}, unique ${response.unique}`, { cause: ex });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const rawMessageToKernel = messageToKernelParser.formatMessageToKernel({ parsedMessageToKernel: encoded });
|
|
54
|
+
|
|
55
|
+
sendMessageToKernel({
|
|
56
|
+
rawMessageToKernel
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
processRequest
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
createFuseServer
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/*export type {
|
|
72
|
+
TRequestHandler,
|
|
73
|
+
};*/
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
declare const read: ({ fd, buffer }: {
|
|
2
|
+
fd: number;
|
|
3
|
+
buffer: Uint8Array;
|
|
4
|
+
}) => any;
|
|
5
|
+
declare const write: ({ fd, buffer }: {
|
|
6
|
+
fd: number;
|
|
7
|
+
buffer: Uint8Array;
|
|
8
|
+
}) => any;
|
|
9
|
+
type TFsopenResult = {
|
|
10
|
+
errno: number;
|
|
11
|
+
fsfd: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
errno: undefined;
|
|
14
|
+
fsfd: number;
|
|
15
|
+
};
|
|
16
|
+
declare const fsopen: ({ fileSystemName, flags, }: {
|
|
17
|
+
fileSystemName: string;
|
|
18
|
+
flags: bigint;
|
|
19
|
+
}) => TFsopenResult;
|
|
20
|
+
type TFsConfigResult = {
|
|
21
|
+
errno: number;
|
|
22
|
+
} | {
|
|
23
|
+
errno: undefined;
|
|
24
|
+
};
|
|
25
|
+
declare const fsconfig: ({ fd, command, key, value, auxiliaryValue, }: {
|
|
26
|
+
fd: number;
|
|
27
|
+
command: bigint;
|
|
28
|
+
key: string | undefined;
|
|
29
|
+
value: string | Uint8Array | undefined;
|
|
30
|
+
auxiliaryValue: number;
|
|
31
|
+
}) => TFsConfigResult;
|
|
32
|
+
type TFsMountResult = {
|
|
33
|
+
errno: number;
|
|
34
|
+
mountFd: undefined;
|
|
35
|
+
} | {
|
|
36
|
+
errno: undefined;
|
|
37
|
+
mountFd: number;
|
|
38
|
+
};
|
|
39
|
+
declare const fsmount: ({ fd, flags, mountAttributesBitmask, }: {
|
|
40
|
+
fd: number;
|
|
41
|
+
flags: bigint;
|
|
42
|
+
mountAttributesBitmask: bigint;
|
|
43
|
+
}) => TFsMountResult;
|
|
44
|
+
type TMoveMountResult = {
|
|
45
|
+
errno: number;
|
|
46
|
+
} | {
|
|
47
|
+
errno: undefined;
|
|
48
|
+
};
|
|
49
|
+
type TFchdirResult = {
|
|
50
|
+
errno: number;
|
|
51
|
+
} | {
|
|
52
|
+
errno: undefined;
|
|
53
|
+
};
|
|
54
|
+
declare const move_mount: ({ fromFd, fromPath, toFd, toPath, flags, }: {
|
|
55
|
+
fromFd: number;
|
|
56
|
+
fromPath?: string;
|
|
57
|
+
toFd: number;
|
|
58
|
+
toPath: string | undefined;
|
|
59
|
+
flags: bigint;
|
|
60
|
+
}) => TMoveMountResult;
|
|
61
|
+
type TUmountResult = {
|
|
62
|
+
errno: number;
|
|
63
|
+
} | {
|
|
64
|
+
errno: undefined;
|
|
65
|
+
};
|
|
66
|
+
declare const umount: ({ target, flags, }: {
|
|
67
|
+
target: string;
|
|
68
|
+
flags: bigint;
|
|
69
|
+
}) => TUmountResult;
|
|
70
|
+
declare const fchdir: ({ fd, }: {
|
|
71
|
+
fd: number;
|
|
72
|
+
}) => TFchdirResult;
|
|
73
|
+
export { read, write, fsopen, fsconfig, fsmount, move_mount, fchdir, umount };
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { syscall, syscallNumbers } from "syscall-napi";
|
|
2
|
+
import { toCString } from "./abi.js";
|
|
3
|
+
|
|
4
|
+
const read = ({
|
|
5
|
+
fd,
|
|
6
|
+
buffer
|
|
7
|
+
}/*: {
|
|
8
|
+
fd: number;
|
|
9
|
+
buffer: Uint8Array;
|
|
10
|
+
}*/) => {
|
|
11
|
+
|
|
12
|
+
return syscall({
|
|
13
|
+
syscallNumber: syscallNumbers.read,
|
|
14
|
+
args: [BigInt(fd), buffer, BigInt(buffer.length)]
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const write = ({
|
|
19
|
+
fd,
|
|
20
|
+
buffer
|
|
21
|
+
}/*: {
|
|
22
|
+
fd: number;
|
|
23
|
+
buffer: Uint8Array;
|
|
24
|
+
}*/) => {
|
|
25
|
+
|
|
26
|
+
return syscall({
|
|
27
|
+
syscallNumber: syscallNumbers.write,
|
|
28
|
+
args: [BigInt(fd), buffer, BigInt(buffer.length)]
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const toOptionalCStringArg = ({ value }/*: { value: string | undefined }*/) => {
|
|
33
|
+
if (value === undefined) {
|
|
34
|
+
return 0n;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return toCString(value);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const toOptionalPointerArg = ({ value } /*: { value: string | Uint8Array | undefined }*/) => {
|
|
41
|
+
if (value === undefined) {
|
|
42
|
+
return 0n;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (typeof value === "string") {
|
|
46
|
+
return toCString(value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return value;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/*type TFsopenResult = {
|
|
53
|
+
errno: number;
|
|
54
|
+
fsfd: undefined;
|
|
55
|
+
} | {
|
|
56
|
+
errno: undefined;
|
|
57
|
+
fsfd: number;
|
|
58
|
+
};*/
|
|
59
|
+
|
|
60
|
+
const fsopen = ({
|
|
61
|
+
fileSystemName,
|
|
62
|
+
flags,
|
|
63
|
+
}/*: {
|
|
64
|
+
fileSystemName: string;
|
|
65
|
+
flags: bigint;
|
|
66
|
+
}*/)/*: TFsopenResult*/ => {
|
|
67
|
+
const { errno, ret } = syscall({
|
|
68
|
+
syscallNumber: syscallNumbers.fsopen,
|
|
69
|
+
args: [
|
|
70
|
+
toCString(fileSystemName),
|
|
71
|
+
flags,
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (errno !== undefined) {
|
|
76
|
+
return {
|
|
77
|
+
errno,
|
|
78
|
+
fsfd: undefined,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
errno: undefined,
|
|
84
|
+
fsfd: Number(ret),
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/*type TFsConfigResult = {
|
|
89
|
+
errno: number;
|
|
90
|
+
} | {
|
|
91
|
+
errno: undefined;
|
|
92
|
+
};*/
|
|
93
|
+
|
|
94
|
+
const fsconfig = ({
|
|
95
|
+
fd,
|
|
96
|
+
command,
|
|
97
|
+
key,
|
|
98
|
+
value,
|
|
99
|
+
auxiliaryValue,
|
|
100
|
+
}/*: {
|
|
101
|
+
fd: number;
|
|
102
|
+
command: bigint;
|
|
103
|
+
key: string | undefined;
|
|
104
|
+
value: string | Uint8Array | undefined;
|
|
105
|
+
auxiliaryValue: number;
|
|
106
|
+
}*/)/*: TFsConfigResult*/ => {
|
|
107
|
+
const { errno } = syscall({
|
|
108
|
+
syscallNumber: syscallNumbers.fsconfig,
|
|
109
|
+
args: [
|
|
110
|
+
BigInt(fd),
|
|
111
|
+
command,
|
|
112
|
+
toOptionalCStringArg({ value: key }),
|
|
113
|
+
toOptionalPointerArg({ value }),
|
|
114
|
+
BigInt(auxiliaryValue),
|
|
115
|
+
],
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
if (errno !== undefined) {
|
|
119
|
+
throw Error(`fsconfig syscall failed with errno ${errno}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
errno: undefined,
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/*type TFsMountResult = {
|
|
128
|
+
errno: number;
|
|
129
|
+
mountFd: undefined;
|
|
130
|
+
} | {
|
|
131
|
+
errno: undefined;
|
|
132
|
+
mountFd: number;
|
|
133
|
+
};*/
|
|
134
|
+
|
|
135
|
+
const fsmount = ({
|
|
136
|
+
fd,
|
|
137
|
+
flags,
|
|
138
|
+
mountAttributesBitmask,
|
|
139
|
+
}/*: {
|
|
140
|
+
fd: number;
|
|
141
|
+
flags: bigint;
|
|
142
|
+
mountAttributesBitmask: bigint;
|
|
143
|
+
}*/)/*: TFsMountResult*/ => {
|
|
144
|
+
const { errno, ret } = syscall({
|
|
145
|
+
syscallNumber: syscallNumbers.fsmount,
|
|
146
|
+
args: [
|
|
147
|
+
BigInt(fd),
|
|
148
|
+
flags,
|
|
149
|
+
mountAttributesBitmask,
|
|
150
|
+
],
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
if (errno !== undefined) {
|
|
154
|
+
return {
|
|
155
|
+
errno,
|
|
156
|
+
mountFd: undefined,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
errno: undefined,
|
|
162
|
+
mountFd: Number(ret),
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/*type TMoveMountResult = {
|
|
167
|
+
errno: number;
|
|
168
|
+
} | {
|
|
169
|
+
errno: undefined;
|
|
170
|
+
};*/
|
|
171
|
+
|
|
172
|
+
/*type TFchdirResult = {
|
|
173
|
+
errno: number;
|
|
174
|
+
} | {
|
|
175
|
+
errno: undefined;
|
|
176
|
+
};*/
|
|
177
|
+
|
|
178
|
+
const move_mount = ({
|
|
179
|
+
fromFd,
|
|
180
|
+
fromPath,
|
|
181
|
+
toFd,
|
|
182
|
+
toPath,
|
|
183
|
+
flags,
|
|
184
|
+
}/*: {
|
|
185
|
+
fromFd: number;
|
|
186
|
+
fromPath?: string;
|
|
187
|
+
toFd: number;
|
|
188
|
+
toPath: string | undefined;
|
|
189
|
+
flags: bigint;
|
|
190
|
+
}*/)/*: TMoveMountResult*/ => {
|
|
191
|
+
const { errno } = syscall({
|
|
192
|
+
syscallNumber: syscallNumbers.move_mount,
|
|
193
|
+
args: [
|
|
194
|
+
BigInt(fromFd),
|
|
195
|
+
toOptionalCStringArg({ value: fromPath }),
|
|
196
|
+
BigInt(toFd),
|
|
197
|
+
toOptionalCStringArg({ value: toPath }),
|
|
198
|
+
flags,
|
|
199
|
+
],
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
if (errno !== undefined) {
|
|
203
|
+
return {
|
|
204
|
+
errno,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
errno: undefined,
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/*type TUmountResult = {
|
|
214
|
+
errno: number;
|
|
215
|
+
} | {
|
|
216
|
+
errno: undefined;
|
|
217
|
+
};*/
|
|
218
|
+
|
|
219
|
+
const umount = ({
|
|
220
|
+
target,
|
|
221
|
+
flags,
|
|
222
|
+
}/*: {
|
|
223
|
+
target: string;
|
|
224
|
+
flags: bigint;
|
|
225
|
+
}*/)/*: TUmountResult*/ => {
|
|
226
|
+
const { errno } = syscall({
|
|
227
|
+
syscallNumber: syscallNumbers.umount2,
|
|
228
|
+
args: [
|
|
229
|
+
toCString(target),
|
|
230
|
+
flags,
|
|
231
|
+
],
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
if (errno !== undefined) {
|
|
235
|
+
return {
|
|
236
|
+
errno,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
errno: undefined,
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const fchdir = ({
|
|
246
|
+
fd,
|
|
247
|
+
}/*: {
|
|
248
|
+
fd: number;
|
|
249
|
+
}*/)/*: TFchdirResult*/ => {
|
|
250
|
+
const { errno } = syscall({
|
|
251
|
+
syscallNumber: syscallNumbers.fchdir,
|
|
252
|
+
args: [BigInt(fd)],
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
if (errno !== undefined) {
|
|
256
|
+
return {
|
|
257
|
+
errno,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
errno: undefined,
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
export {
|
|
267
|
+
read,
|
|
268
|
+
write,
|
|
269
|
+
fsopen,
|
|
270
|
+
fsconfig,
|
|
271
|
+
fsmount,
|
|
272
|
+
move_mount,
|
|
273
|
+
fchdir,
|
|
274
|
+
umount
|
|
275
|
+
};
|
package/package.json
CHANGED