@k13engineering/linux-fuse 0.0.1 → 0.0.3
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/dirent.d.ts +13 -0
- package/dist/lib/dirent.js +128 -0
- package/dist/lib/fuse-lowlevel.d.ts +42 -0
- package/dist/lib/fuse-lowlevel.js +133 -0
- package/dist/lib/index.d.ts +43 -0
- package/dist/lib/index.js +325 -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 +755 -0
- package/dist/lib/protocol.js +3797 -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 +2 -2
|
@@ -0,0 +1,3797 @@
|
|
|
1
|
+
/* eslint-disable max-statements, complexity */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
decodeCString,
|
|
5
|
+
decodeCStringPair,
|
|
6
|
+
fuseAccessInParser,
|
|
7
|
+
fuseAttrOutParser,
|
|
8
|
+
fuseBatchForgetInParser,
|
|
9
|
+
fuseBmapInParser,
|
|
10
|
+
fuseBmapOutParser,
|
|
11
|
+
fuseCreateInParser,
|
|
12
|
+
fuseEntryOutParser,
|
|
13
|
+
fuseFallocateInParser,
|
|
14
|
+
fuseFsyncInParser,
|
|
15
|
+
fuseFlushInParser,
|
|
16
|
+
fuseForgetInParser,
|
|
17
|
+
fuseForgetOneParser,
|
|
18
|
+
fuseGetattrInParser,
|
|
19
|
+
fuseGetxattrInParser,
|
|
20
|
+
fuseGetxattrOutParser,
|
|
21
|
+
fuseInitInParser,
|
|
22
|
+
fuseInitOutParser,
|
|
23
|
+
fuseInterruptInParser,
|
|
24
|
+
fuseIoctlInParser,
|
|
25
|
+
fuseIoctlOutParser,
|
|
26
|
+
fuseLinkInParser,
|
|
27
|
+
fuseLkInParser,
|
|
28
|
+
fuseLkOutParser,
|
|
29
|
+
fuseMkdirInParser,
|
|
30
|
+
fuseMknodInParser,
|
|
31
|
+
fuseOpenInParser,
|
|
32
|
+
fuseOpenOutParser,
|
|
33
|
+
fusePollInParser,
|
|
34
|
+
fusePollOutParser,
|
|
35
|
+
fuseReadInParser,
|
|
36
|
+
fuseReleaseInParser,
|
|
37
|
+
fuseRename2InParser,
|
|
38
|
+
fuseRenameInParser,
|
|
39
|
+
fuseSetattrInParser,
|
|
40
|
+
fuseSetxattrInParser,
|
|
41
|
+
fuseStatfsOutParser,
|
|
42
|
+
fuseWriteInParser,
|
|
43
|
+
fuseWriteOutParser,
|
|
44
|
+
} from "./abi.js";
|
|
45
|
+
import {
|
|
46
|
+
FATTR_ATIME,
|
|
47
|
+
FATTR_ATIME_NOW,
|
|
48
|
+
FATTR_FH,
|
|
49
|
+
FATTR_GID,
|
|
50
|
+
FATTR_MODE,
|
|
51
|
+
FATTR_MTIME,
|
|
52
|
+
FATTR_MTIME_NOW,
|
|
53
|
+
FATTR_SIZE,
|
|
54
|
+
FATTR_UID,
|
|
55
|
+
FOPEN_DIRECT_IO,
|
|
56
|
+
FOPEN_KEEP_CACHE,
|
|
57
|
+
FOPEN_NONSEEKABLE,
|
|
58
|
+
FUSE_GETATTR_FH,
|
|
59
|
+
opcode,
|
|
60
|
+
} from "./constants.js";
|
|
61
|
+
/*import type { TParsedMessageFromKernel, TParsedMessageToKernel } from "./message.ts";*/
|
|
62
|
+
|
|
63
|
+
/*type TRequesterInfo = {
|
|
64
|
+
uid: bigint;
|
|
65
|
+
gid: bigint;
|
|
66
|
+
pid: bigint;
|
|
67
|
+
};*/
|
|
68
|
+
|
|
69
|
+
/*type TOpenFlagsToKernel = {
|
|
70
|
+
directIo: boolean;
|
|
71
|
+
keepCache: boolean;
|
|
72
|
+
nonSeekable: boolean;
|
|
73
|
+
};*/
|
|
74
|
+
|
|
75
|
+
/*type TFuseAttr = {
|
|
76
|
+
ino: bigint;
|
|
77
|
+
mode: bigint;
|
|
78
|
+
nlink: bigint;
|
|
79
|
+
uid: bigint;
|
|
80
|
+
gid: bigint;
|
|
81
|
+
rdev: bigint;
|
|
82
|
+
size: bigint;
|
|
83
|
+
blksize: bigint;
|
|
84
|
+
blocks: bigint;
|
|
85
|
+
atimeNsec: bigint;
|
|
86
|
+
mtimeNsec: bigint;
|
|
87
|
+
ctimeNsec: bigint;
|
|
88
|
+
};*/
|
|
89
|
+
|
|
90
|
+
/*type TFuseEntry = {
|
|
91
|
+
nodeId: bigint;
|
|
92
|
+
generation: bigint;
|
|
93
|
+
entryValidNsec: bigint;
|
|
94
|
+
attrValidNsec: bigint;
|
|
95
|
+
attr: TFuseAttr;
|
|
96
|
+
};*/
|
|
97
|
+
|
|
98
|
+
/*type TFuseXAttrResult = {
|
|
99
|
+
data: Uint8Array;
|
|
100
|
+
} | {
|
|
101
|
+
size: bigint;
|
|
102
|
+
};*/
|
|
103
|
+
|
|
104
|
+
/*type TFuseRequest = {
|
|
105
|
+
unique: bigint;
|
|
106
|
+
requester: TRequesterInfo;
|
|
107
|
+
} & ({
|
|
108
|
+
opcode: "INIT";
|
|
109
|
+
major: bigint;
|
|
110
|
+
minor: bigint;
|
|
111
|
+
} | {
|
|
112
|
+
opcode: "FORGET";
|
|
113
|
+
nodeId: bigint;
|
|
114
|
+
lookupCount: bigint;
|
|
115
|
+
} | {
|
|
116
|
+
opcode: "BATCH_FORGET";
|
|
117
|
+
forgets: Array<{
|
|
118
|
+
nodeId: bigint;
|
|
119
|
+
lookupCount: bigint;
|
|
120
|
+
}>;
|
|
121
|
+
} | {
|
|
122
|
+
opcode: "GETATTR";
|
|
123
|
+
getattrMode: "node";
|
|
124
|
+
nodeId: bigint;
|
|
125
|
+
} | {
|
|
126
|
+
opcode: "GETATTR";
|
|
127
|
+
getattrMode: "fileHandle";
|
|
128
|
+
fh: bigint;
|
|
129
|
+
} | {
|
|
130
|
+
opcode: "LISTXATTR";
|
|
131
|
+
nodeId: bigint;
|
|
132
|
+
size: bigint;
|
|
133
|
+
} | {
|
|
134
|
+
opcode: "GETXATTR";
|
|
135
|
+
nodeId: bigint;
|
|
136
|
+
size: bigint;
|
|
137
|
+
name: string;
|
|
138
|
+
} | {
|
|
139
|
+
opcode: "SETATTR";
|
|
140
|
+
nodeId: bigint;
|
|
141
|
+
fh: bigint | undefined;
|
|
142
|
+
size: bigint | undefined;
|
|
143
|
+
lockOwner: bigint;
|
|
144
|
+
atimeNsec: bigint | "now" | undefined;
|
|
145
|
+
mtimeNsec: bigint | "now" | undefined;
|
|
146
|
+
ctimeNsec: bigint;
|
|
147
|
+
mode: bigint | undefined;
|
|
148
|
+
uid: bigint | undefined;
|
|
149
|
+
gid: bigint | undefined;
|
|
150
|
+
} | {
|
|
151
|
+
opcode: "READLINK";
|
|
152
|
+
nodeId: bigint;
|
|
153
|
+
} | {
|
|
154
|
+
opcode: "SYMLINK";
|
|
155
|
+
parentNodeId: bigint;
|
|
156
|
+
name: string;
|
|
157
|
+
target: string;
|
|
158
|
+
} | {
|
|
159
|
+
opcode: "MKNOD";
|
|
160
|
+
parentNodeId: bigint;
|
|
161
|
+
name: string;
|
|
162
|
+
mode: bigint;
|
|
163
|
+
rdev: bigint;
|
|
164
|
+
umask: bigint;
|
|
165
|
+
} | {
|
|
166
|
+
opcode: "MKDIR";
|
|
167
|
+
parentNodeId: bigint;
|
|
168
|
+
name: string;
|
|
169
|
+
mode: bigint;
|
|
170
|
+
umask: bigint;
|
|
171
|
+
} | {
|
|
172
|
+
opcode: "UNLINK";
|
|
173
|
+
parentNodeId: bigint;
|
|
174
|
+
name: string;
|
|
175
|
+
} | {
|
|
176
|
+
opcode: "RMDIR";
|
|
177
|
+
parentNodeId: bigint;
|
|
178
|
+
name: string;
|
|
179
|
+
} | {
|
|
180
|
+
opcode: "RENAME";
|
|
181
|
+
parentNodeId: bigint;
|
|
182
|
+
newParentNodeId: bigint;
|
|
183
|
+
oldName: string;
|
|
184
|
+
newName: string;
|
|
185
|
+
flags: bigint;
|
|
186
|
+
} | {
|
|
187
|
+
opcode: "LINK";
|
|
188
|
+
oldNodeId: bigint;
|
|
189
|
+
newParentNodeId: bigint;
|
|
190
|
+
name: string;
|
|
191
|
+
} | {
|
|
192
|
+
opcode: "OPENDIR";
|
|
193
|
+
nodeId: bigint;
|
|
194
|
+
flags: bigint;
|
|
195
|
+
} | {
|
|
196
|
+
opcode: "READDIR";
|
|
197
|
+
nodeId: bigint;
|
|
198
|
+
fh: bigint;
|
|
199
|
+
offset: bigint;
|
|
200
|
+
size: bigint;
|
|
201
|
+
readFlags: bigint;
|
|
202
|
+
lockOwner: bigint;
|
|
203
|
+
flags: bigint;
|
|
204
|
+
} | {
|
|
205
|
+
opcode: "RELEASE";
|
|
206
|
+
nodeId: bigint;
|
|
207
|
+
fh: bigint;
|
|
208
|
+
flags: bigint;
|
|
209
|
+
releaseFlags: bigint;
|
|
210
|
+
lockOwner: bigint;
|
|
211
|
+
} | {
|
|
212
|
+
opcode: "RELEASEDIR";
|
|
213
|
+
nodeId: bigint;
|
|
214
|
+
fh: bigint;
|
|
215
|
+
flags: bigint;
|
|
216
|
+
releaseFlags: bigint;
|
|
217
|
+
lockOwner: bigint;
|
|
218
|
+
} | {
|
|
219
|
+
opcode: "FSYNCDIR";
|
|
220
|
+
nodeId: bigint;
|
|
221
|
+
fh: bigint;
|
|
222
|
+
fsyncFlags: bigint;
|
|
223
|
+
} | {
|
|
224
|
+
opcode: "STATFS";
|
|
225
|
+
} | {
|
|
226
|
+
opcode: "LOOKUP";
|
|
227
|
+
parentNodeId: bigint;
|
|
228
|
+
name: string;
|
|
229
|
+
} | {
|
|
230
|
+
opcode: "OPEN",
|
|
231
|
+
nodeId: bigint;
|
|
232
|
+
flags: bigint;
|
|
233
|
+
} | {
|
|
234
|
+
opcode: "READ";
|
|
235
|
+
nodeId: bigint;
|
|
236
|
+
fh: bigint;
|
|
237
|
+
offset: bigint;
|
|
238
|
+
size: bigint;
|
|
239
|
+
readFlags: bigint;
|
|
240
|
+
lockOwner: bigint;
|
|
241
|
+
} | {
|
|
242
|
+
opcode: "WRITE";
|
|
243
|
+
nodeId: bigint;
|
|
244
|
+
fh: bigint;
|
|
245
|
+
offset: bigint;
|
|
246
|
+
data: Uint8Array;
|
|
247
|
+
writeFlags: bigint;
|
|
248
|
+
lockOwner: bigint;
|
|
249
|
+
} | {
|
|
250
|
+
opcode: "FLUSH";
|
|
251
|
+
nodeId: bigint;
|
|
252
|
+
fh: bigint;
|
|
253
|
+
lockOwner: bigint;
|
|
254
|
+
} | {
|
|
255
|
+
opcode: "FSYNC";
|
|
256
|
+
nodeId: bigint;
|
|
257
|
+
fh: bigint;
|
|
258
|
+
fsyncFlags: bigint;
|
|
259
|
+
} | {
|
|
260
|
+
opcode: "ACCESS";
|
|
261
|
+
nodeId: bigint;
|
|
262
|
+
mask: bigint;
|
|
263
|
+
} | {
|
|
264
|
+
opcode: "SETXATTR";
|
|
265
|
+
nodeId: bigint;
|
|
266
|
+
name: string;
|
|
267
|
+
data: Uint8Array;
|
|
268
|
+
flags: bigint;
|
|
269
|
+
setxattrFlags: bigint;
|
|
270
|
+
} | {
|
|
271
|
+
opcode: "REMOVEXATTR";
|
|
272
|
+
nodeId: bigint;
|
|
273
|
+
name: string;
|
|
274
|
+
} | {
|
|
275
|
+
opcode: "CREATE";
|
|
276
|
+
parentNodeId: bigint;
|
|
277
|
+
name: string;
|
|
278
|
+
flags: bigint;
|
|
279
|
+
mode: bigint;
|
|
280
|
+
umask: bigint;
|
|
281
|
+
} | {
|
|
282
|
+
opcode: "DESTROY";
|
|
283
|
+
} | {
|
|
284
|
+
opcode: "GETLK";
|
|
285
|
+
nodeId: bigint;
|
|
286
|
+
fh: bigint;
|
|
287
|
+
owner: bigint;
|
|
288
|
+
lockStart: bigint;
|
|
289
|
+
lockEnd: bigint;
|
|
290
|
+
lockType: bigint;
|
|
291
|
+
lockPid: bigint;
|
|
292
|
+
lkFlags: bigint;
|
|
293
|
+
} | {
|
|
294
|
+
opcode: "SETLK";
|
|
295
|
+
nodeId: bigint;
|
|
296
|
+
fh: bigint;
|
|
297
|
+
owner: bigint;
|
|
298
|
+
lockStart: bigint;
|
|
299
|
+
lockEnd: bigint;
|
|
300
|
+
lockType: bigint;
|
|
301
|
+
lockPid: bigint;
|
|
302
|
+
lkFlags: bigint;
|
|
303
|
+
} | {
|
|
304
|
+
opcode: "SETLKW";
|
|
305
|
+
nodeId: bigint;
|
|
306
|
+
fh: bigint;
|
|
307
|
+
owner: bigint;
|
|
308
|
+
lockStart: bigint;
|
|
309
|
+
lockEnd: bigint;
|
|
310
|
+
lockType: bigint;
|
|
311
|
+
lockPid: bigint;
|
|
312
|
+
lkFlags: bigint;
|
|
313
|
+
} | {
|
|
314
|
+
opcode: "INTERRUPT";
|
|
315
|
+
targetUnique: bigint;
|
|
316
|
+
} | {
|
|
317
|
+
opcode: "BMAP";
|
|
318
|
+
nodeId: bigint;
|
|
319
|
+
block: bigint;
|
|
320
|
+
blocksize: bigint;
|
|
321
|
+
} | {
|
|
322
|
+
opcode: "IOCTL";
|
|
323
|
+
nodeId: bigint;
|
|
324
|
+
fh: bigint;
|
|
325
|
+
flags: bigint;
|
|
326
|
+
cmd: bigint;
|
|
327
|
+
arg: bigint;
|
|
328
|
+
inData: Uint8Array;
|
|
329
|
+
outSize: bigint;
|
|
330
|
+
} | {
|
|
331
|
+
opcode: "POLL";
|
|
332
|
+
nodeId: bigint;
|
|
333
|
+
fh: bigint;
|
|
334
|
+
kh: bigint;
|
|
335
|
+
flags: bigint;
|
|
336
|
+
events: bigint;
|
|
337
|
+
} | {
|
|
338
|
+
opcode: "NOTIFY_REPLY";
|
|
339
|
+
data: Uint8Array;
|
|
340
|
+
} | {
|
|
341
|
+
opcode: "FALLOCATE";
|
|
342
|
+
nodeId: bigint;
|
|
343
|
+
fh: bigint;
|
|
344
|
+
offset: bigint;
|
|
345
|
+
length: bigint;
|
|
346
|
+
mode: bigint;
|
|
347
|
+
} | {
|
|
348
|
+
opcode: "READDIRPLUS";
|
|
349
|
+
nodeId: bigint;
|
|
350
|
+
fh: bigint;
|
|
351
|
+
offset: bigint;
|
|
352
|
+
size: bigint;
|
|
353
|
+
readFlags: bigint;
|
|
354
|
+
lockOwner: bigint;
|
|
355
|
+
flags: bigint;
|
|
356
|
+
});*/
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
/*type TFuseResponse = {
|
|
360
|
+
forOpcode: "INIT";
|
|
361
|
+
unique: bigint;
|
|
362
|
+
errorCode: number;
|
|
363
|
+
result: undefined;
|
|
364
|
+
} | {
|
|
365
|
+
forOpcode: "INIT";
|
|
366
|
+
unique: bigint;
|
|
367
|
+
errorCode: undefined;
|
|
368
|
+
result: {
|
|
369
|
+
major: bigint,
|
|
370
|
+
minor: bigint,
|
|
371
|
+
maxReadahead: bigint,
|
|
372
|
+
flags: bigint,
|
|
373
|
+
maxBackground: bigint,
|
|
374
|
+
congestionThreshold: bigint,
|
|
375
|
+
maxWrite: bigint,
|
|
376
|
+
timeGran: bigint,
|
|
377
|
+
maxPages: bigint,
|
|
378
|
+
mapAlignment: bigint,
|
|
379
|
+
flags2: bigint,
|
|
380
|
+
maxStackDepth: bigint,
|
|
381
|
+
requestTimeout: bigint,
|
|
382
|
+
};
|
|
383
|
+
} | {
|
|
384
|
+
forOpcode: "GETATTR";
|
|
385
|
+
unique: bigint;
|
|
386
|
+
errorCode: number;
|
|
387
|
+
result: undefined;
|
|
388
|
+
} | {
|
|
389
|
+
forOpcode: "GETATTR";
|
|
390
|
+
unique: bigint;
|
|
391
|
+
errorCode: undefined;
|
|
392
|
+
result: {
|
|
393
|
+
attrValidNsec: bigint;
|
|
394
|
+
attr: TFuseAttr
|
|
395
|
+
};
|
|
396
|
+
} | {
|
|
397
|
+
forOpcode: "SETATTR";
|
|
398
|
+
unique: bigint;
|
|
399
|
+
errorCode: number;
|
|
400
|
+
result: undefined;
|
|
401
|
+
} | {
|
|
402
|
+
forOpcode: "SETATTR";
|
|
403
|
+
unique: bigint;
|
|
404
|
+
errorCode: undefined;
|
|
405
|
+
result: {
|
|
406
|
+
attrValidNsec: bigint;
|
|
407
|
+
attr: TFuseAttr;
|
|
408
|
+
};
|
|
409
|
+
} | {
|
|
410
|
+
forOpcode: "LISTXATTR";
|
|
411
|
+
unique: bigint;
|
|
412
|
+
errorCode: number;
|
|
413
|
+
result: undefined;
|
|
414
|
+
} | {
|
|
415
|
+
forOpcode: "LISTXATTR";
|
|
416
|
+
unique: bigint;
|
|
417
|
+
errorCode: undefined;
|
|
418
|
+
result: TFuseXAttrResult;
|
|
419
|
+
} | {
|
|
420
|
+
forOpcode: "GETXATTR";
|
|
421
|
+
unique: bigint;
|
|
422
|
+
errorCode: number;
|
|
423
|
+
result: undefined;
|
|
424
|
+
} | {
|
|
425
|
+
forOpcode: "GETXATTR";
|
|
426
|
+
unique: bigint;
|
|
427
|
+
errorCode: undefined;
|
|
428
|
+
result: TFuseXAttrResult;
|
|
429
|
+
} | {
|
|
430
|
+
forOpcode: "READLINK";
|
|
431
|
+
unique: bigint;
|
|
432
|
+
errorCode: number;
|
|
433
|
+
result: undefined;
|
|
434
|
+
} | {
|
|
435
|
+
forOpcode: "READLINK";
|
|
436
|
+
unique: bigint;
|
|
437
|
+
errorCode: undefined;
|
|
438
|
+
result: {
|
|
439
|
+
target: string;
|
|
440
|
+
};
|
|
441
|
+
} | {
|
|
442
|
+
forOpcode: "MKNOD";
|
|
443
|
+
unique: bigint;
|
|
444
|
+
errorCode: number;
|
|
445
|
+
result: undefined;
|
|
446
|
+
} | {
|
|
447
|
+
forOpcode: "MKNOD";
|
|
448
|
+
unique: bigint;
|
|
449
|
+
errorCode: undefined;
|
|
450
|
+
result: TFuseEntry;
|
|
451
|
+
} | {
|
|
452
|
+
forOpcode: "OPENDIR";
|
|
453
|
+
unique: bigint;
|
|
454
|
+
errorCode: number;
|
|
455
|
+
result: undefined;
|
|
456
|
+
} | {
|
|
457
|
+
forOpcode: "OPENDIR";
|
|
458
|
+
unique: bigint;
|
|
459
|
+
errorCode: undefined;
|
|
460
|
+
result: {
|
|
461
|
+
fh: bigint;
|
|
462
|
+
openFlagsToKernel: TOpenFlagsToKernel;
|
|
463
|
+
};
|
|
464
|
+
} | {
|
|
465
|
+
forOpcode: "READDIR";
|
|
466
|
+
unique: bigint;
|
|
467
|
+
errorCode: number;
|
|
468
|
+
result: undefined;
|
|
469
|
+
} | {
|
|
470
|
+
forOpcode: "READDIR";
|
|
471
|
+
unique: bigint;
|
|
472
|
+
errorCode: undefined;
|
|
473
|
+
result: {
|
|
474
|
+
data: Uint8Array;
|
|
475
|
+
};
|
|
476
|
+
} | {
|
|
477
|
+
forOpcode: "RELEASEDIR";
|
|
478
|
+
unique: bigint;
|
|
479
|
+
errorCode: number;
|
|
480
|
+
result: undefined;
|
|
481
|
+
} | {
|
|
482
|
+
forOpcode: "RELEASEDIR";
|
|
483
|
+
unique: bigint;
|
|
484
|
+
errorCode: undefined;
|
|
485
|
+
result: Record<string, never>;
|
|
486
|
+
} | {
|
|
487
|
+
forOpcode: "FSYNCDIR";
|
|
488
|
+
unique: bigint;
|
|
489
|
+
errorCode: number;
|
|
490
|
+
result: undefined;
|
|
491
|
+
} | {
|
|
492
|
+
forOpcode: "FSYNCDIR";
|
|
493
|
+
unique: bigint;
|
|
494
|
+
errorCode: undefined;
|
|
495
|
+
result: Record<string, never>;
|
|
496
|
+
} | {
|
|
497
|
+
forOpcode: "RELEASE";
|
|
498
|
+
unique: bigint;
|
|
499
|
+
errorCode: number;
|
|
500
|
+
result: undefined;
|
|
501
|
+
} | {
|
|
502
|
+
forOpcode: "RELEASE";
|
|
503
|
+
unique: bigint;
|
|
504
|
+
errorCode: undefined;
|
|
505
|
+
result: Record<string, never>;
|
|
506
|
+
} | {
|
|
507
|
+
forOpcode: "STATFS";
|
|
508
|
+
unique: bigint;
|
|
509
|
+
errorCode: number;
|
|
510
|
+
result: undefined;
|
|
511
|
+
} | {
|
|
512
|
+
forOpcode: "STATFS";
|
|
513
|
+
unique: bigint;
|
|
514
|
+
errorCode: undefined;
|
|
515
|
+
result: {
|
|
516
|
+
blocks: bigint;
|
|
517
|
+
bfree: bigint;
|
|
518
|
+
bavail: bigint;
|
|
519
|
+
files: bigint;
|
|
520
|
+
ffree: bigint;
|
|
521
|
+
bsize: bigint;
|
|
522
|
+
namelen: bigint;
|
|
523
|
+
frsize: bigint;
|
|
524
|
+
}
|
|
525
|
+
} | {
|
|
526
|
+
forOpcode: "LOOKUP";
|
|
527
|
+
unique: bigint;
|
|
528
|
+
errorCode: number;
|
|
529
|
+
result: undefined;
|
|
530
|
+
} | {
|
|
531
|
+
forOpcode: "LOOKUP";
|
|
532
|
+
unique: bigint;
|
|
533
|
+
errorCode: undefined;
|
|
534
|
+
result: TFuseEntry;
|
|
535
|
+
} | {
|
|
536
|
+
forOpcode: "SYMLINK";
|
|
537
|
+
unique: bigint;
|
|
538
|
+
errorCode: number;
|
|
539
|
+
result: undefined;
|
|
540
|
+
} | {
|
|
541
|
+
forOpcode: "SYMLINK";
|
|
542
|
+
unique: bigint;
|
|
543
|
+
errorCode: undefined;
|
|
544
|
+
result: TFuseEntry;
|
|
545
|
+
} | {
|
|
546
|
+
forOpcode: "MKDIR";
|
|
547
|
+
unique: bigint;
|
|
548
|
+
errorCode: number;
|
|
549
|
+
result: undefined;
|
|
550
|
+
} | {
|
|
551
|
+
forOpcode: "MKDIR";
|
|
552
|
+
unique: bigint;
|
|
553
|
+
errorCode: undefined;
|
|
554
|
+
result: TFuseEntry;
|
|
555
|
+
} | {
|
|
556
|
+
forOpcode: "LINK";
|
|
557
|
+
unique: bigint;
|
|
558
|
+
errorCode: number;
|
|
559
|
+
result: undefined;
|
|
560
|
+
} | {
|
|
561
|
+
forOpcode: "LINK";
|
|
562
|
+
unique: bigint;
|
|
563
|
+
errorCode: undefined;
|
|
564
|
+
result: TFuseEntry;
|
|
565
|
+
} | {
|
|
566
|
+
forOpcode: "UNLINK";
|
|
567
|
+
unique: bigint;
|
|
568
|
+
errorCode: number;
|
|
569
|
+
result: undefined;
|
|
570
|
+
} | {
|
|
571
|
+
forOpcode: "UNLINK";
|
|
572
|
+
unique: bigint;
|
|
573
|
+
errorCode: undefined;
|
|
574
|
+
result: Record<string, never>;
|
|
575
|
+
} | {
|
|
576
|
+
forOpcode: "RMDIR";
|
|
577
|
+
unique: bigint;
|
|
578
|
+
errorCode: number;
|
|
579
|
+
result: undefined;
|
|
580
|
+
} | {
|
|
581
|
+
forOpcode: "RMDIR";
|
|
582
|
+
unique: bigint;
|
|
583
|
+
errorCode: undefined;
|
|
584
|
+
result: Record<string, never>;
|
|
585
|
+
} | {
|
|
586
|
+
forOpcode: "RENAME";
|
|
587
|
+
unique: bigint;
|
|
588
|
+
errorCode: number;
|
|
589
|
+
result: undefined;
|
|
590
|
+
} | {
|
|
591
|
+
forOpcode: "RENAME";
|
|
592
|
+
unique: bigint;
|
|
593
|
+
errorCode: undefined;
|
|
594
|
+
result: Record<string, never>;
|
|
595
|
+
} | {
|
|
596
|
+
forOpcode: "OPEN";
|
|
597
|
+
unique: bigint;
|
|
598
|
+
errorCode: number;
|
|
599
|
+
result: undefined;
|
|
600
|
+
} | {
|
|
601
|
+
forOpcode: "OPEN";
|
|
602
|
+
unique: bigint;
|
|
603
|
+
errorCode: undefined;
|
|
604
|
+
result: {
|
|
605
|
+
fh: bigint;
|
|
606
|
+
openFlagsToKernel: TOpenFlagsToKernel;
|
|
607
|
+
}
|
|
608
|
+
} | {
|
|
609
|
+
forOpcode: "READ";
|
|
610
|
+
unique: bigint;
|
|
611
|
+
errorCode: number;
|
|
612
|
+
result: undefined;
|
|
613
|
+
} | {
|
|
614
|
+
forOpcode: "READ";
|
|
615
|
+
unique: bigint;
|
|
616
|
+
errorCode: undefined;
|
|
617
|
+
result: {
|
|
618
|
+
data: Uint8Array;
|
|
619
|
+
}
|
|
620
|
+
} | {
|
|
621
|
+
forOpcode: "WRITE";
|
|
622
|
+
unique: bigint;
|
|
623
|
+
errorCode: number;
|
|
624
|
+
result: undefined;
|
|
625
|
+
} | {
|
|
626
|
+
forOpcode: "WRITE";
|
|
627
|
+
unique: bigint;
|
|
628
|
+
errorCode: undefined;
|
|
629
|
+
result: {
|
|
630
|
+
bytesWritten: bigint;
|
|
631
|
+
}
|
|
632
|
+
} | {
|
|
633
|
+
forOpcode: "FLUSH";
|
|
634
|
+
unique: bigint;
|
|
635
|
+
errorCode: number;
|
|
636
|
+
result: undefined;
|
|
637
|
+
} | {
|
|
638
|
+
forOpcode: "FLUSH";
|
|
639
|
+
unique: bigint;
|
|
640
|
+
errorCode: undefined;
|
|
641
|
+
result: Record<string, never>;
|
|
642
|
+
} | {
|
|
643
|
+
forOpcode: "FSYNC";
|
|
644
|
+
unique: bigint;
|
|
645
|
+
errorCode: number;
|
|
646
|
+
result: undefined;
|
|
647
|
+
} | {
|
|
648
|
+
forOpcode: "FSYNC";
|
|
649
|
+
unique: bigint;
|
|
650
|
+
errorCode: undefined;
|
|
651
|
+
result: Record<string, never>;
|
|
652
|
+
} | {
|
|
653
|
+
forOpcode: "ACCESS";
|
|
654
|
+
unique: bigint;
|
|
655
|
+
errorCode: number;
|
|
656
|
+
result: undefined;
|
|
657
|
+
} | {
|
|
658
|
+
forOpcode: "ACCESS";
|
|
659
|
+
unique: bigint;
|
|
660
|
+
errorCode: undefined;
|
|
661
|
+
result: Record<string, never>;
|
|
662
|
+
} | {
|
|
663
|
+
forOpcode: "SETXATTR";
|
|
664
|
+
unique: bigint;
|
|
665
|
+
errorCode: number;
|
|
666
|
+
result: undefined;
|
|
667
|
+
} | {
|
|
668
|
+
forOpcode: "SETXATTR";
|
|
669
|
+
unique: bigint;
|
|
670
|
+
errorCode: undefined;
|
|
671
|
+
result: Record<string, never>;
|
|
672
|
+
} | {
|
|
673
|
+
forOpcode: "REMOVEXATTR";
|
|
674
|
+
unique: bigint;
|
|
675
|
+
errorCode: number;
|
|
676
|
+
result: undefined;
|
|
677
|
+
} | {
|
|
678
|
+
forOpcode: "REMOVEXATTR";
|
|
679
|
+
unique: bigint;
|
|
680
|
+
errorCode: undefined;
|
|
681
|
+
result: Record<string, never>;
|
|
682
|
+
} | {
|
|
683
|
+
forOpcode: "CREATE";
|
|
684
|
+
unique: bigint;
|
|
685
|
+
errorCode: number;
|
|
686
|
+
result: undefined;
|
|
687
|
+
} | {
|
|
688
|
+
forOpcode: "CREATE";
|
|
689
|
+
unique: bigint;
|
|
690
|
+
errorCode: undefined;
|
|
691
|
+
result: TFuseEntry & {
|
|
692
|
+
fh: bigint;
|
|
693
|
+
openFlagsToKernel: TOpenFlagsToKernel;
|
|
694
|
+
};
|
|
695
|
+
} | {
|
|
696
|
+
forOpcode: "DESTROY";
|
|
697
|
+
unique: bigint;
|
|
698
|
+
errorCode: number;
|
|
699
|
+
result: undefined;
|
|
700
|
+
} | {
|
|
701
|
+
forOpcode: "DESTROY";
|
|
702
|
+
unique: bigint;
|
|
703
|
+
errorCode: undefined;
|
|
704
|
+
result: Record<string, never>;
|
|
705
|
+
} | {
|
|
706
|
+
forOpcode: "GETLK";
|
|
707
|
+
unique: bigint;
|
|
708
|
+
errorCode: number;
|
|
709
|
+
result: undefined;
|
|
710
|
+
} | {
|
|
711
|
+
forOpcode: "GETLK";
|
|
712
|
+
unique: bigint;
|
|
713
|
+
errorCode: undefined;
|
|
714
|
+
result: {
|
|
715
|
+
lockStart: bigint;
|
|
716
|
+
lockEnd: bigint;
|
|
717
|
+
lockType: bigint;
|
|
718
|
+
lockPid: bigint;
|
|
719
|
+
};
|
|
720
|
+
} | {
|
|
721
|
+
forOpcode: "SETLK";
|
|
722
|
+
unique: bigint;
|
|
723
|
+
errorCode: number;
|
|
724
|
+
result: undefined;
|
|
725
|
+
} | {
|
|
726
|
+
forOpcode: "SETLK";
|
|
727
|
+
unique: bigint;
|
|
728
|
+
errorCode: undefined;
|
|
729
|
+
result: Record<string, never>;
|
|
730
|
+
} | {
|
|
731
|
+
forOpcode: "SETLKW";
|
|
732
|
+
unique: bigint;
|
|
733
|
+
errorCode: number;
|
|
734
|
+
result: undefined;
|
|
735
|
+
} | {
|
|
736
|
+
forOpcode: "SETLKW";
|
|
737
|
+
unique: bigint;
|
|
738
|
+
errorCode: undefined;
|
|
739
|
+
result: Record<string, never>;
|
|
740
|
+
} | {
|
|
741
|
+
forOpcode: "BMAP";
|
|
742
|
+
unique: bigint;
|
|
743
|
+
errorCode: number;
|
|
744
|
+
result: undefined;
|
|
745
|
+
} | {
|
|
746
|
+
forOpcode: "BMAP";
|
|
747
|
+
unique: bigint;
|
|
748
|
+
errorCode: undefined;
|
|
749
|
+
result: {
|
|
750
|
+
block: bigint;
|
|
751
|
+
};
|
|
752
|
+
} | {
|
|
753
|
+
forOpcode: "IOCTL";
|
|
754
|
+
unique: bigint;
|
|
755
|
+
errorCode: number;
|
|
756
|
+
result: undefined;
|
|
757
|
+
} | {
|
|
758
|
+
forOpcode: "IOCTL";
|
|
759
|
+
unique: bigint;
|
|
760
|
+
errorCode: undefined;
|
|
761
|
+
result: {
|
|
762
|
+
ioctlResult: bigint;
|
|
763
|
+
flags: bigint;
|
|
764
|
+
data: Uint8Array;
|
|
765
|
+
};
|
|
766
|
+
} | {
|
|
767
|
+
forOpcode: "POLL";
|
|
768
|
+
unique: bigint;
|
|
769
|
+
errorCode: number;
|
|
770
|
+
result: undefined;
|
|
771
|
+
} | {
|
|
772
|
+
forOpcode: "POLL";
|
|
773
|
+
unique: bigint;
|
|
774
|
+
errorCode: undefined;
|
|
775
|
+
result: {
|
|
776
|
+
revents: bigint;
|
|
777
|
+
};
|
|
778
|
+
} | {
|
|
779
|
+
forOpcode: "FALLOCATE";
|
|
780
|
+
unique: bigint;
|
|
781
|
+
errorCode: number;
|
|
782
|
+
result: undefined;
|
|
783
|
+
} | {
|
|
784
|
+
forOpcode: "FALLOCATE";
|
|
785
|
+
unique: bigint;
|
|
786
|
+
errorCode: undefined;
|
|
787
|
+
result: Record<string, never>;
|
|
788
|
+
} | {
|
|
789
|
+
forOpcode: "READDIRPLUS";
|
|
790
|
+
unique: bigint;
|
|
791
|
+
errorCode: number;
|
|
792
|
+
result: undefined;
|
|
793
|
+
} | {
|
|
794
|
+
forOpcode: "READDIRPLUS";
|
|
795
|
+
unique: bigint;
|
|
796
|
+
errorCode: undefined;
|
|
797
|
+
result: {
|
|
798
|
+
data: Uint8Array;
|
|
799
|
+
};
|
|
800
|
+
};*/
|
|
801
|
+
|
|
802
|
+
/*type TGenericInterpretResult<T> = {
|
|
803
|
+
error: Error;
|
|
804
|
+
interpreted: undefined;
|
|
805
|
+
} | {
|
|
806
|
+
error: undefined;
|
|
807
|
+
interpreted: T;
|
|
808
|
+
};*/
|
|
809
|
+
|
|
810
|
+
const hasFlag = ({ bitmask, flag }/*: { bitmask: bigint; flag: bigint }*/)/*: boolean*/ => {
|
|
811
|
+
return (bitmask & flag) === flag;
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
const fuseAttrToPayloadValue = ({ attr }/*: { attr: TFuseAttr }*/) => {
|
|
815
|
+
return {
|
|
816
|
+
ino: attr.ino,
|
|
817
|
+
mode: attr.mode,
|
|
818
|
+
nlink: attr.nlink,
|
|
819
|
+
uid: attr.uid,
|
|
820
|
+
gid: attr.gid,
|
|
821
|
+
rdev: attr.rdev,
|
|
822
|
+
size: attr.size,
|
|
823
|
+
blksize: attr.blksize,
|
|
824
|
+
blocks: attr.blocks,
|
|
825
|
+
atime: attr.atimeNsec / 1_000_000_000n,
|
|
826
|
+
atimensec: attr.atimeNsec % 1_000_000_000n,
|
|
827
|
+
mtime: attr.mtimeNsec / 1_000_000_000n,
|
|
828
|
+
mtimensec: attr.mtimeNsec % 1_000_000_000n,
|
|
829
|
+
ctime: attr.ctimeNsec / 1_000_000_000n,
|
|
830
|
+
ctimensec: attr.ctimeNsec % 1_000_000_000n,
|
|
831
|
+
padding: 0n,
|
|
832
|
+
};
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
const payloadValueToFuseAttr = ({ attr }/*: { attr: ReturnType<typeof fuseAttrOutParser.parse>["attr"] }*/)/*: TFuseAttr*/ => {
|
|
836
|
+
return {
|
|
837
|
+
ino: attr.ino,
|
|
838
|
+
mode: attr.mode,
|
|
839
|
+
nlink: attr.nlink,
|
|
840
|
+
uid: attr.uid,
|
|
841
|
+
gid: attr.gid,
|
|
842
|
+
rdev: attr.rdev,
|
|
843
|
+
size: attr.size,
|
|
844
|
+
blksize: attr.blksize,
|
|
845
|
+
blocks: attr.blocks,
|
|
846
|
+
atimeNsec: attr.atime * 1_000_000_000n + attr.atimensec,
|
|
847
|
+
mtimeNsec: attr.mtime * 1_000_000_000n + attr.mtimensec,
|
|
848
|
+
ctimeNsec: attr.ctime * 1_000_000_000n + attr.ctimensec,
|
|
849
|
+
};
|
|
850
|
+
};
|
|
851
|
+
|
|
852
|
+
const openFlagsToKernelToBitmask = ({ openFlagsToKernel }/*: { openFlagsToKernel: TOpenFlagsToKernel }*/)/*: bigint*/ => {
|
|
853
|
+
let bitmask = 0n;
|
|
854
|
+
|
|
855
|
+
if (openFlagsToKernel.directIo) {
|
|
856
|
+
bitmask |= FOPEN_DIRECT_IO;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
if (openFlagsToKernel.keepCache) {
|
|
860
|
+
bitmask |= FOPEN_KEEP_CACHE;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
if (openFlagsToKernel.nonSeekable) {
|
|
864
|
+
bitmask |= FOPEN_NONSEEKABLE;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
return bitmask;
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
const openFlagsToKernelFromBitmask = ({ bitmask }/*: { bitmask: bigint }*/)/*: TOpenFlagsToKernel*/ => {
|
|
871
|
+
return {
|
|
872
|
+
directIo: hasFlag({ bitmask, flag: FOPEN_DIRECT_IO }),
|
|
873
|
+
keepCache: hasFlag({ bitmask, flag: FOPEN_KEEP_CACHE }),
|
|
874
|
+
nonSeekable: hasFlag({ bitmask, flag: FOPEN_NONSEEKABLE }),
|
|
875
|
+
};
|
|
876
|
+
};
|
|
877
|
+
|
|
878
|
+
const encodeAttrPayload = (
|
|
879
|
+
{ unique, result }/*: {
|
|
880
|
+
unique: bigint;
|
|
881
|
+
forOpcode: "GETATTR" | "SETATTR";
|
|
882
|
+
result: { attrValidNsec: bigint; attr: TFuseAttr };
|
|
883
|
+
}*/,
|
|
884
|
+
)/*: Extract<TParsedMessageToKernel, { header: { unique: bigint } }>*/ => {
|
|
885
|
+
const payload = fuseAttrOutParser.format({
|
|
886
|
+
value: {
|
|
887
|
+
dummy: 0n,
|
|
888
|
+
attr_valid: result.attrValidNsec / 1_000_000_000n,
|
|
889
|
+
attr_valid_nsec: result.attrValidNsec % 1_000_000_000n,
|
|
890
|
+
attr: fuseAttrToPayloadValue({ attr: result.attr }),
|
|
891
|
+
}
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
return {
|
|
895
|
+
header: {
|
|
896
|
+
unique,
|
|
897
|
+
error: 0n,
|
|
898
|
+
},
|
|
899
|
+
payload,
|
|
900
|
+
};
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
const interpretAttrPayload = /*<TForOpcode extends "GETATTR" | "SETATTR">*/(
|
|
904
|
+
{ unique, forOpcode, payload }/*: { unique: bigint; forOpcode: TForOpcode; payload: Uint8Array }*/
|
|
905
|
+
)/*: TGenericInterpretResult<Extract<TFuseResponse, { forOpcode: TForOpcode }>>*/ => {
|
|
906
|
+
if (payload.length !== fuseAttrOutParser.size) {
|
|
907
|
+
return {
|
|
908
|
+
error: Error(
|
|
909
|
+
`Invalid payload size for ${forOpcode} response. Expected ${fuseAttrOutParser.size} bytes, got ${payload.length} bytes.`
|
|
910
|
+
),
|
|
911
|
+
interpreted: undefined,
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
const parsed = fuseAttrOutParser.parse({ data: payload });
|
|
916
|
+
|
|
917
|
+
return {
|
|
918
|
+
error: undefined,
|
|
919
|
+
interpreted: {
|
|
920
|
+
forOpcode,
|
|
921
|
+
unique,
|
|
922
|
+
errorCode: undefined,
|
|
923
|
+
result: {
|
|
924
|
+
attrValidNsec: parsed.attr_valid * 1_000_000_000n + parsed.attr_valid_nsec,
|
|
925
|
+
attr: payloadValueToFuseAttr({ attr: parsed.attr }),
|
|
926
|
+
}
|
|
927
|
+
} /*as Extract<TFuseResponse, { forOpcode: TForOpcode }>*/,
|
|
928
|
+
};
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
const encodeEntryPayload = (
|
|
932
|
+
{ unique, result }/*: {
|
|
933
|
+
unique: bigint;
|
|
934
|
+
forOpcode: "LOOKUP" | "SYMLINK" | "MKNOD" | "MKDIR" | "LINK";
|
|
935
|
+
result: TFuseEntry;
|
|
936
|
+
}*/,
|
|
937
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
938
|
+
const payload = fuseEntryOutParser.format({
|
|
939
|
+
value: {
|
|
940
|
+
nodeid: result.nodeId,
|
|
941
|
+
generation: result.generation,
|
|
942
|
+
entry_valid: result.entryValidNsec / 1_000_000_000n,
|
|
943
|
+
attr_valid: result.attrValidNsec / 1_000_000_000n,
|
|
944
|
+
entry_valid_nsec: result.entryValidNsec % 1_000_000_000n,
|
|
945
|
+
attr_valid_nsec: result.attrValidNsec % 1_000_000_000n,
|
|
946
|
+
attr: fuseAttrToPayloadValue({ attr: result.attr }),
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
return {
|
|
951
|
+
header: {
|
|
952
|
+
unique,
|
|
953
|
+
error: 0n,
|
|
954
|
+
},
|
|
955
|
+
payload,
|
|
956
|
+
};
|
|
957
|
+
};
|
|
958
|
+
|
|
959
|
+
const interpretEntryPayload = /*<TForOpcode extends "LOOKUP" | "SYMLINK" | "MKNOD" | "MKDIR" | "LINK">*/(
|
|
960
|
+
{ unique, forOpcode, payload }/*: { unique: bigint; forOpcode: TForOpcode; payload: Uint8Array }*/
|
|
961
|
+
)/*: TGenericInterpretResult<Extract<TFuseResponse, { forOpcode: TForOpcode }>>*/ => {
|
|
962
|
+
if (payload.length !== fuseEntryOutParser.size) {
|
|
963
|
+
return {
|
|
964
|
+
error: Error(
|
|
965
|
+
`Invalid payload size for ${forOpcode} response. Expected ${fuseEntryOutParser.size} bytes, got ${payload.length} bytes.`
|
|
966
|
+
),
|
|
967
|
+
interpreted: undefined,
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
const parsed = fuseEntryOutParser.parse({ data: payload });
|
|
972
|
+
|
|
973
|
+
return {
|
|
974
|
+
error: undefined,
|
|
975
|
+
interpreted: {
|
|
976
|
+
forOpcode,
|
|
977
|
+
unique,
|
|
978
|
+
errorCode: undefined,
|
|
979
|
+
result: {
|
|
980
|
+
nodeId: parsed.nodeid,
|
|
981
|
+
generation: parsed.generation,
|
|
982
|
+
entryValidNsec: parsed.entry_valid * 1_000_000_000n + parsed.entry_valid_nsec,
|
|
983
|
+
attrValidNsec: parsed.attr_valid * 1_000_000_000n + parsed.attr_valid_nsec,
|
|
984
|
+
attr: payloadValueToFuseAttr({ attr: parsed.attr }),
|
|
985
|
+
},
|
|
986
|
+
} /*as Extract<TFuseResponse, { forOpcode: TForOpcode }>*/,
|
|
987
|
+
};
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
const encodeOpenPayload = (
|
|
991
|
+
{ unique, result }/*: { unique: bigint; result: { fh: bigint; openFlagsToKernel: TOpenFlagsToKernel } }*/
|
|
992
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
993
|
+
const payload = fuseOpenOutParser.format({
|
|
994
|
+
value: {
|
|
995
|
+
fh: result.fh,
|
|
996
|
+
open_flags: openFlagsToKernelToBitmask({ openFlagsToKernel: result.openFlagsToKernel }),
|
|
997
|
+
backing_id: 0n,
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
return {
|
|
1002
|
+
header: {
|
|
1003
|
+
unique,
|
|
1004
|
+
error: 0n,
|
|
1005
|
+
},
|
|
1006
|
+
payload,
|
|
1007
|
+
};
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1010
|
+
const interpretOpenPayload = /*<TForOpcode extends "OPEN" | "OPENDIR">*/(
|
|
1011
|
+
{ unique, forOpcode, payload }/*: { unique: bigint; forOpcode: TForOpcode; payload: Uint8Array }*/
|
|
1012
|
+
)/*: TGenericInterpretResult<Extract<TFuseResponse, { forOpcode: TForOpcode }>>*/ => {
|
|
1013
|
+
if (payload.length !== fuseOpenOutParser.size) {
|
|
1014
|
+
return {
|
|
1015
|
+
error: Error(
|
|
1016
|
+
`Invalid payload size for ${forOpcode} response. Expected ${fuseOpenOutParser.size} bytes, got ${payload.length} bytes.`
|
|
1017
|
+
),
|
|
1018
|
+
interpreted: undefined,
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
const parsed = fuseOpenOutParser.parse({ data: payload });
|
|
1023
|
+
|
|
1024
|
+
return {
|
|
1025
|
+
error: undefined,
|
|
1026
|
+
interpreted: {
|
|
1027
|
+
forOpcode,
|
|
1028
|
+
unique,
|
|
1029
|
+
errorCode: undefined,
|
|
1030
|
+
result: {
|
|
1031
|
+
fh: parsed.fh,
|
|
1032
|
+
openFlagsToKernel: openFlagsToKernelFromBitmask({ bitmask: parsed.open_flags }),
|
|
1033
|
+
}
|
|
1034
|
+
} /*as Extract<TFuseResponse, { forOpcode: TForOpcode }>*/,
|
|
1035
|
+
};
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
const encodeEmptyPayload = ({ unique }/*: { unique: bigint }*/)/*: TParsedMessageToKernel*/ => {
|
|
1039
|
+
return {
|
|
1040
|
+
header: {
|
|
1041
|
+
unique,
|
|
1042
|
+
error: 0n,
|
|
1043
|
+
},
|
|
1044
|
+
payload: new Uint8Array(0),
|
|
1045
|
+
};
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1048
|
+
const interpretEmptyPayload = /*<T extends Extract<TFuseResponse, { result: Record<string, never> }>["forOpcode"]>*/(
|
|
1049
|
+
{ unique, forOpcode }/*: { unique: bigint; forOpcode: T }*/,
|
|
1050
|
+
)/*: TGenericInterpretResult<Extract<TFuseResponse, { forOpcode: T }>>*/ => {
|
|
1051
|
+
return {
|
|
1052
|
+
error: undefined,
|
|
1053
|
+
interpreted: {
|
|
1054
|
+
forOpcode,
|
|
1055
|
+
unique,
|
|
1056
|
+
errorCode: undefined,
|
|
1057
|
+
result: {},
|
|
1058
|
+
} /*as Extract<TFuseResponse, { forOpcode: T }>*/,
|
|
1059
|
+
};
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
const encodeXAttrPayload = ({ unique, result }/*: { unique: bigint; result: TFuseXAttrResult }*/)/*: TParsedMessageToKernel*/ => {
|
|
1063
|
+
const payload = "size" in result
|
|
1064
|
+
? fuseGetxattrOutParser.format({ value: { size: result.size, padding: 0n } })
|
|
1065
|
+
: result.data;
|
|
1066
|
+
|
|
1067
|
+
return {
|
|
1068
|
+
header: {
|
|
1069
|
+
unique,
|
|
1070
|
+
error: 0n,
|
|
1071
|
+
},
|
|
1072
|
+
payload,
|
|
1073
|
+
};
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1076
|
+
const interpretXAttrPayload = /*<TForOpcode extends "GETXATTR" | "LISTXATTR">*/(
|
|
1077
|
+
{ unique, forOpcode, payload, requestedSize }/*:
|
|
1078
|
+
{ unique: bigint; forOpcode: TForOpcode; payload: Uint8Array; requestedSize: bigint }*/
|
|
1079
|
+
)/*: TGenericInterpretResult<Extract<TFuseResponse, { forOpcode: TForOpcode }>>*/ => {
|
|
1080
|
+
if (requestedSize === 0n) {
|
|
1081
|
+
if (payload.length !== fuseGetxattrOutParser.size) {
|
|
1082
|
+
return {
|
|
1083
|
+
error: Error(
|
|
1084
|
+
`Invalid payload size for ${forOpcode} size response. Expected ${fuseGetxattrOutParser.size} bytes, got ${payload.length} bytes.`
|
|
1085
|
+
),
|
|
1086
|
+
interpreted: undefined,
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
const parsed = fuseGetxattrOutParser.parse({ data: payload });
|
|
1091
|
+
|
|
1092
|
+
return {
|
|
1093
|
+
error: undefined,
|
|
1094
|
+
interpreted: {
|
|
1095
|
+
forOpcode,
|
|
1096
|
+
unique,
|
|
1097
|
+
errorCode: undefined,
|
|
1098
|
+
result: { size: parsed.size },
|
|
1099
|
+
} /*as Extract<TFuseResponse, { forOpcode: TForOpcode }>*/,
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
return {
|
|
1104
|
+
error: undefined,
|
|
1105
|
+
interpreted: {
|
|
1106
|
+
forOpcode,
|
|
1107
|
+
unique,
|
|
1108
|
+
errorCode: undefined,
|
|
1109
|
+
result: { data: payload },
|
|
1110
|
+
} /*as Extract<TFuseResponse, { forOpcode: TForOpcode }>*/,
|
|
1111
|
+
};
|
|
1112
|
+
};
|
|
1113
|
+
|
|
1114
|
+
const createMessageFromKernelInterpreter = () => {
|
|
1115
|
+
|
|
1116
|
+
/*type TInterpretFunc<T extends string> = (
|
|
1117
|
+
args: { unique: bigint, nodeId: bigint, requester: TRequesterInfo, payload: Uint8Array }
|
|
1118
|
+
) => TGenericInterpretResult<Extract<TFuseRequest, { opcode: T }>>;*/
|
|
1119
|
+
|
|
1120
|
+
const interpretInit/*: TInterpretFunc<"INIT">*/ = ({ unique, requester, payload }) => {
|
|
1121
|
+
|
|
1122
|
+
if (payload.length !== fuseInitInParser.size) {
|
|
1123
|
+
return {
|
|
1124
|
+
error: Error(`Invalid payload size for INIT request. Expected ${fuseInitInParser.size} bytes, got ${payload.length} bytes.`),
|
|
1125
|
+
interpreted: undefined,
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
const { major, minor } = fuseInitInParser.parse({ data: payload });
|
|
1130
|
+
|
|
1131
|
+
return {
|
|
1132
|
+
error: undefined,
|
|
1133
|
+
interpreted: {
|
|
1134
|
+
unique,
|
|
1135
|
+
requester,
|
|
1136
|
+
opcode: "INIT",
|
|
1137
|
+
major,
|
|
1138
|
+
minor,
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
};
|
|
1142
|
+
|
|
1143
|
+
const interpretGetAttr/*: TInterpretFunc<"GETATTR">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1144
|
+
if (payload.length !== fuseGetattrInParser.size) {
|
|
1145
|
+
return {
|
|
1146
|
+
error: Error(
|
|
1147
|
+
`Invalid payload size for GETATTR request. Expected ${fuseGetattrInParser.size} bytes, got ${payload.length} bytes.`
|
|
1148
|
+
),
|
|
1149
|
+
interpreted: undefined,
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
const { getattr_flags, fh } = fuseGetattrInParser.parse({ data: payload });
|
|
1154
|
+
|
|
1155
|
+
if (hasFlag({ bitmask: getattr_flags, flag: FUSE_GETATTR_FH })) {
|
|
1156
|
+
return {
|
|
1157
|
+
error: undefined,
|
|
1158
|
+
interpreted: {
|
|
1159
|
+
unique,
|
|
1160
|
+
requester,
|
|
1161
|
+
opcode: "GETATTR",
|
|
1162
|
+
getattrMode: "fileHandle",
|
|
1163
|
+
fh,
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
return {
|
|
1169
|
+
error: undefined,
|
|
1170
|
+
interpreted: {
|
|
1171
|
+
unique,
|
|
1172
|
+
requester,
|
|
1173
|
+
opcode: "GETATTR",
|
|
1174
|
+
getattrMode: "node",
|
|
1175
|
+
nodeId,
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
};
|
|
1179
|
+
|
|
1180
|
+
const interpretForget/*: TInterpretFunc<"FORGET">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1181
|
+
if (payload.length !== fuseForgetInParser.size) {
|
|
1182
|
+
return {
|
|
1183
|
+
error: Error(
|
|
1184
|
+
`Invalid payload size for FORGET request. Expected ${fuseForgetInParser.size} bytes, got ${payload.length} bytes.`
|
|
1185
|
+
),
|
|
1186
|
+
interpreted: undefined,
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
const { nlookup } = fuseForgetInParser.parse({ data: payload });
|
|
1191
|
+
|
|
1192
|
+
return {
|
|
1193
|
+
error: undefined,
|
|
1194
|
+
interpreted: {
|
|
1195
|
+
unique,
|
|
1196
|
+
requester,
|
|
1197
|
+
opcode: "FORGET",
|
|
1198
|
+
nodeId,
|
|
1199
|
+
lookupCount: nlookup,
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
};
|
|
1203
|
+
|
|
1204
|
+
const interpretBatchForget/*: TInterpretFunc<"BATCH_FORGET">*/ = ({ unique, requester, payload }) => {
|
|
1205
|
+
if (payload.length < fuseBatchForgetInParser.size) {
|
|
1206
|
+
return {
|
|
1207
|
+
error: Error(
|
|
1208
|
+
`Invalid payload size for BATCH_FORGET request. ` +
|
|
1209
|
+
`Expected at least ${fuseBatchForgetInParser.size} bytes, got ${payload.length} bytes.`
|
|
1210
|
+
),
|
|
1211
|
+
interpreted: undefined,
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
const header = fuseBatchForgetInParser.parse({ data: payload.subarray(0, fuseBatchForgetInParser.size) });
|
|
1216
|
+
const count = Number(header.count);
|
|
1217
|
+
const expectedSize = fuseBatchForgetInParser.size + (count * fuseForgetOneParser.size);
|
|
1218
|
+
if (payload.length !== expectedSize) {
|
|
1219
|
+
return {
|
|
1220
|
+
error: Error(`Invalid payload size for BATCH_FORGET request. Expected ${expectedSize} bytes, got ${payload.length} bytes.`),
|
|
1221
|
+
interpreted: undefined,
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
let forgets/*: Array<{ nodeId: bigint; lookupCount: bigint }>*/ = [];
|
|
1226
|
+
for (let index = 0; index < count; index += 1) {
|
|
1227
|
+
const start = fuseBatchForgetInParser.size + (index * fuseForgetOneParser.size);
|
|
1228
|
+
const parsed = fuseForgetOneParser.parse({ data: payload.subarray(start, start + fuseForgetOneParser.size) });
|
|
1229
|
+
forgets = [...forgets, {
|
|
1230
|
+
nodeId: parsed.nodeid,
|
|
1231
|
+
lookupCount: parsed.nlookup,
|
|
1232
|
+
}];
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
return {
|
|
1236
|
+
error: undefined,
|
|
1237
|
+
interpreted: {
|
|
1238
|
+
unique,
|
|
1239
|
+
requester,
|
|
1240
|
+
opcode: "BATCH_FORGET",
|
|
1241
|
+
forgets,
|
|
1242
|
+
}
|
|
1243
|
+
};
|
|
1244
|
+
};
|
|
1245
|
+
|
|
1246
|
+
const interpretListXAttrRequest/*: TInterpretFunc<"LISTXATTR">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1247
|
+
if (payload.length !== fuseGetxattrInParser.size) {
|
|
1248
|
+
return {
|
|
1249
|
+
error: Error(
|
|
1250
|
+
`Invalid payload size for LISTXATTR request. Expected ${fuseGetxattrInParser.size} bytes, got ${payload.length} bytes.`
|
|
1251
|
+
),
|
|
1252
|
+
interpreted: undefined,
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
const { size } = fuseGetxattrInParser.parse({ data: payload });
|
|
1257
|
+
|
|
1258
|
+
return {
|
|
1259
|
+
error: undefined,
|
|
1260
|
+
interpreted: {
|
|
1261
|
+
unique,
|
|
1262
|
+
requester,
|
|
1263
|
+
opcode: "LISTXATTR",
|
|
1264
|
+
nodeId,
|
|
1265
|
+
size,
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1268
|
+
};
|
|
1269
|
+
|
|
1270
|
+
const interpretGetXAttr/*: TInterpretFunc<"GETXATTR">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1271
|
+
if (payload.length < fuseGetxattrInParser.size) {
|
|
1272
|
+
return {
|
|
1273
|
+
error: Error(
|
|
1274
|
+
`Invalid payload size for GETXATTR request. Expected at least ${fuseGetxattrInParser.size} bytes, got ${payload.length} bytes.`
|
|
1275
|
+
),
|
|
1276
|
+
interpreted: undefined,
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
const { size } = fuseGetxattrInParser.parse({ data: payload.subarray(0, fuseGetxattrInParser.size) });
|
|
1281
|
+
|
|
1282
|
+
return {
|
|
1283
|
+
error: undefined,
|
|
1284
|
+
interpreted: {
|
|
1285
|
+
unique,
|
|
1286
|
+
requester,
|
|
1287
|
+
opcode: "GETXATTR",
|
|
1288
|
+
nodeId,
|
|
1289
|
+
size,
|
|
1290
|
+
name: decodeCString(payload.subarray(fuseGetxattrInParser.size)),
|
|
1291
|
+
}
|
|
1292
|
+
};
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1295
|
+
const interpretSetAttr/*: TInterpretFunc<"SETATTR">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1296
|
+
if (payload.length !== fuseSetattrInParser.size) {
|
|
1297
|
+
return {
|
|
1298
|
+
error: Error(
|
|
1299
|
+
`Invalid payload size for SETATTR request. Expected ${fuseSetattrInParser.size} bytes, got ${payload.length} bytes.`
|
|
1300
|
+
),
|
|
1301
|
+
interpreted: undefined,
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
const parsed = fuseSetattrInParser.parse({ data: payload });
|
|
1306
|
+
const validFlags = Number(parsed.valid);
|
|
1307
|
+
|
|
1308
|
+
let atimeNsec/*: bigint | "now" | undefined*/ = undefined;
|
|
1309
|
+
if ((validFlags & FATTR_ATIME_NOW) !== 0) {
|
|
1310
|
+
atimeNsec = "now";
|
|
1311
|
+
} else if ((validFlags & FATTR_ATIME) !== 0) {
|
|
1312
|
+
atimeNsec = parsed.atime * 1_000_000_000n + parsed.atimensec;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
let mtimeNsec/*: bigint | "now" | undefined*/ = undefined;
|
|
1316
|
+
if ((validFlags & FATTR_MTIME_NOW) !== 0) {
|
|
1317
|
+
mtimeNsec = "now";
|
|
1318
|
+
} else if ((validFlags & FATTR_MTIME) !== 0) {
|
|
1319
|
+
mtimeNsec = parsed.mtime * 1_000_000_000n + parsed.mtimensec;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
return {
|
|
1323
|
+
error: undefined,
|
|
1324
|
+
interpreted: {
|
|
1325
|
+
unique,
|
|
1326
|
+
requester,
|
|
1327
|
+
opcode: "SETATTR",
|
|
1328
|
+
nodeId,
|
|
1329
|
+
fh: (validFlags & FATTR_FH) === 0 ? undefined : parsed.fh,
|
|
1330
|
+
size: (validFlags & FATTR_SIZE) === 0 ? undefined : parsed.size,
|
|
1331
|
+
lockOwner: parsed.lock_owner,
|
|
1332
|
+
atimeNsec,
|
|
1333
|
+
mtimeNsec,
|
|
1334
|
+
ctimeNsec: parsed.ctime * 1_000_000_000n + parsed.ctimensec,
|
|
1335
|
+
mode: (validFlags & FATTR_MODE) === 0 ? undefined : parsed.mode,
|
|
1336
|
+
uid: (validFlags & FATTR_UID) === 0 ? undefined : parsed.uid,
|
|
1337
|
+
gid: (validFlags & FATTR_GID) === 0 ? undefined : parsed.gid,
|
|
1338
|
+
}
|
|
1339
|
+
};
|
|
1340
|
+
};
|
|
1341
|
+
|
|
1342
|
+
const interpretReadLink/*: TInterpretFunc<"READLINK">*/ = ({ unique, nodeId, requester }) => {
|
|
1343
|
+
return {
|
|
1344
|
+
error: undefined,
|
|
1345
|
+
interpreted: {
|
|
1346
|
+
unique,
|
|
1347
|
+
requester,
|
|
1348
|
+
opcode: "READLINK",
|
|
1349
|
+
nodeId,
|
|
1350
|
+
}
|
|
1351
|
+
};
|
|
1352
|
+
};
|
|
1353
|
+
|
|
1354
|
+
const interpretSymlink/*: TInterpretFunc<"SYMLINK">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1355
|
+
const { first: name, second: target } = decodeCStringPair(payload);
|
|
1356
|
+
|
|
1357
|
+
return {
|
|
1358
|
+
error: undefined,
|
|
1359
|
+
interpreted: {
|
|
1360
|
+
unique,
|
|
1361
|
+
requester,
|
|
1362
|
+
opcode: "SYMLINK",
|
|
1363
|
+
parentNodeId: nodeId,
|
|
1364
|
+
name,
|
|
1365
|
+
target,
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
};
|
|
1369
|
+
|
|
1370
|
+
const interpretMknod/*: TInterpretFunc<"MKNOD">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1371
|
+
if (payload.length < fuseMknodInParser.size) {
|
|
1372
|
+
return {
|
|
1373
|
+
error: Error(
|
|
1374
|
+
`Invalid payload size for MKNOD request. Expected at least ${fuseMknodInParser.size} bytes, got ${payload.length} bytes.`
|
|
1375
|
+
),
|
|
1376
|
+
interpreted: undefined,
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
const { mode, rdev, umask } = fuseMknodInParser.parse({ data: payload.subarray(0, fuseMknodInParser.size) });
|
|
1381
|
+
|
|
1382
|
+
return {
|
|
1383
|
+
error: undefined,
|
|
1384
|
+
interpreted: {
|
|
1385
|
+
unique,
|
|
1386
|
+
requester,
|
|
1387
|
+
opcode: "MKNOD",
|
|
1388
|
+
parentNodeId: nodeId,
|
|
1389
|
+
name: decodeCString(payload.subarray(fuseMknodInParser.size)),
|
|
1390
|
+
mode,
|
|
1391
|
+
rdev,
|
|
1392
|
+
umask,
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
};
|
|
1396
|
+
|
|
1397
|
+
const interpretMkdir/*: TInterpretFunc<"MKDIR">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1398
|
+
if (payload.length < fuseMkdirInParser.size) {
|
|
1399
|
+
return {
|
|
1400
|
+
error: Error(
|
|
1401
|
+
`Invalid payload size for MKDIR request. Expected at least ${fuseMkdirInParser.size} bytes, got ${payload.length} bytes.`
|
|
1402
|
+
),
|
|
1403
|
+
interpreted: undefined,
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
const { mode, umask } = fuseMkdirInParser.parse({ data: payload.subarray(0, fuseMkdirInParser.size) });
|
|
1408
|
+
|
|
1409
|
+
return {
|
|
1410
|
+
error: undefined,
|
|
1411
|
+
interpreted: {
|
|
1412
|
+
unique,
|
|
1413
|
+
requester,
|
|
1414
|
+
opcode: "MKDIR",
|
|
1415
|
+
parentNodeId: nodeId,
|
|
1416
|
+
name: decodeCString(payload.subarray(fuseMkdirInParser.size)),
|
|
1417
|
+
mode,
|
|
1418
|
+
umask,
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
};
|
|
1422
|
+
|
|
1423
|
+
const interpretUnlink/*: TInterpretFunc<"UNLINK">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1424
|
+
return {
|
|
1425
|
+
error: undefined,
|
|
1426
|
+
interpreted: {
|
|
1427
|
+
unique,
|
|
1428
|
+
requester,
|
|
1429
|
+
opcode: "UNLINK",
|
|
1430
|
+
parentNodeId: nodeId,
|
|
1431
|
+
name: decodeCString(payload),
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
};
|
|
1435
|
+
|
|
1436
|
+
const interpretRmDir/*: TInterpretFunc<"RMDIR">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1437
|
+
return {
|
|
1438
|
+
error: undefined,
|
|
1439
|
+
interpreted: {
|
|
1440
|
+
unique,
|
|
1441
|
+
requester,
|
|
1442
|
+
opcode: "RMDIR",
|
|
1443
|
+
parentNodeId: nodeId,
|
|
1444
|
+
name: decodeCString(payload),
|
|
1445
|
+
}
|
|
1446
|
+
};
|
|
1447
|
+
};
|
|
1448
|
+
|
|
1449
|
+
const interpretRename = (
|
|
1450
|
+
{ unique, nodeId, requester, payload, supportsFlags }/*:
|
|
1451
|
+
{ unique: bigint; nodeId: bigint; requester: TRequesterInfo; payload: Uint8Array; supportsFlags: boolean }*/
|
|
1452
|
+
)/*: TGenericInterpretResult<Extract<TFuseRequest, { opcode: "RENAME" }>>*/ => {
|
|
1453
|
+
const headerSize = supportsFlags ? fuseRename2InParser.size : fuseRenameInParser.size;
|
|
1454
|
+
if (payload.length < headerSize) {
|
|
1455
|
+
return {
|
|
1456
|
+
error: Error(
|
|
1457
|
+
`Invalid payload size for ${supportsFlags ? "RENAME2" : "RENAME"} request. ` +
|
|
1458
|
+
`Expected at least ${headerSize} bytes, got ${payload.length} bytes.`
|
|
1459
|
+
),
|
|
1460
|
+
interpreted: undefined,
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
const { newdir, flags } = supportsFlags
|
|
1465
|
+
? fuseRename2InParser.parse({ data: payload.subarray(0, fuseRename2InParser.size) })
|
|
1466
|
+
: { ...fuseRenameInParser.parse({ data: payload.subarray(0, fuseRenameInParser.size) }), flags: 0n };
|
|
1467
|
+
const { first: oldName, second: newName } = decodeCStringPair(payload.subarray(headerSize));
|
|
1468
|
+
|
|
1469
|
+
return {
|
|
1470
|
+
error: undefined,
|
|
1471
|
+
interpreted: {
|
|
1472
|
+
unique,
|
|
1473
|
+
requester,
|
|
1474
|
+
opcode: "RENAME",
|
|
1475
|
+
parentNodeId: nodeId,
|
|
1476
|
+
newParentNodeId: newdir,
|
|
1477
|
+
oldName,
|
|
1478
|
+
newName,
|
|
1479
|
+
flags,
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1482
|
+
};
|
|
1483
|
+
|
|
1484
|
+
const interpretOpenDir/*: TInterpretFunc<"OPENDIR">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1485
|
+
if (payload.length !== fuseOpenInParser.size) {
|
|
1486
|
+
return {
|
|
1487
|
+
error: Error(`Invalid payload size for OPENDIR request. Expected ${fuseOpenInParser.size} bytes, got ${payload.length} bytes.`),
|
|
1488
|
+
interpreted: undefined,
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
const { flags } = fuseOpenInParser.parse({ data: payload });
|
|
1493
|
+
|
|
1494
|
+
return {
|
|
1495
|
+
error: undefined,
|
|
1496
|
+
interpreted: {
|
|
1497
|
+
unique,
|
|
1498
|
+
requester,
|
|
1499
|
+
opcode: "OPENDIR",
|
|
1500
|
+
nodeId,
|
|
1501
|
+
flags,
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1504
|
+
};
|
|
1505
|
+
|
|
1506
|
+
const interpretLink/*: TInterpretFunc<"LINK">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1507
|
+
if (payload.length < fuseLinkInParser.size) {
|
|
1508
|
+
return {
|
|
1509
|
+
error: Error(
|
|
1510
|
+
`Invalid payload size for LINK request. Expected at least ${fuseLinkInParser.size} bytes, got ${payload.length} bytes.`
|
|
1511
|
+
),
|
|
1512
|
+
interpreted: undefined,
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
const { oldnodeid } = fuseLinkInParser.parse({ data: payload.subarray(0, fuseLinkInParser.size) });
|
|
1517
|
+
|
|
1518
|
+
return {
|
|
1519
|
+
error: undefined,
|
|
1520
|
+
interpreted: {
|
|
1521
|
+
unique,
|
|
1522
|
+
requester,
|
|
1523
|
+
opcode: "LINK",
|
|
1524
|
+
oldNodeId: oldnodeid,
|
|
1525
|
+
newParentNodeId: nodeId,
|
|
1526
|
+
name: decodeCString(payload.subarray(fuseLinkInParser.size)),
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
};
|
|
1530
|
+
|
|
1531
|
+
const interpretReadDir/*: TInterpretFunc<"READDIR">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1532
|
+
if (payload.length !== fuseReadInParser.size) {
|
|
1533
|
+
return {
|
|
1534
|
+
error: Error(`Invalid payload size for READDIR request. Expected ${fuseReadInParser.size} bytes, got ${payload.length} bytes.`),
|
|
1535
|
+
interpreted: undefined,
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
const { fh, offset, size, flags, lock_owner, read_flags } = fuseReadInParser.parse({ data: payload });
|
|
1540
|
+
|
|
1541
|
+
return {
|
|
1542
|
+
error: undefined,
|
|
1543
|
+
interpreted: {
|
|
1544
|
+
unique,
|
|
1545
|
+
requester,
|
|
1546
|
+
opcode: "READDIR",
|
|
1547
|
+
nodeId,
|
|
1548
|
+
fh,
|
|
1549
|
+
offset,
|
|
1550
|
+
size,
|
|
1551
|
+
flags,
|
|
1552
|
+
lockOwner: lock_owner,
|
|
1553
|
+
readFlags: read_flags,
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
};
|
|
1557
|
+
|
|
1558
|
+
const interpretReleaseDir/*: TInterpretFunc<"RELEASEDIR">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1559
|
+
if (payload.length !== fuseReleaseInParser.size) {
|
|
1560
|
+
return {
|
|
1561
|
+
error: Error(
|
|
1562
|
+
`Invalid payload size for RELEASEDIR request. Expected ${fuseReleaseInParser.size} bytes, got ${payload.length} bytes.`
|
|
1563
|
+
),
|
|
1564
|
+
interpreted: undefined,
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
const { fh, flags, release_flags, lock_owner } = fuseReleaseInParser.parse({ data: payload });
|
|
1569
|
+
|
|
1570
|
+
return {
|
|
1571
|
+
error: undefined,
|
|
1572
|
+
interpreted: {
|
|
1573
|
+
unique,
|
|
1574
|
+
requester,
|
|
1575
|
+
opcode: "RELEASEDIR",
|
|
1576
|
+
nodeId,
|
|
1577
|
+
fh,
|
|
1578
|
+
flags,
|
|
1579
|
+
releaseFlags: release_flags,
|
|
1580
|
+
lockOwner: lock_owner,
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
};
|
|
1584
|
+
|
|
1585
|
+
const interpretRelease/*: TInterpretFunc<"RELEASE">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1586
|
+
if (payload.length !== fuseReleaseInParser.size) {
|
|
1587
|
+
return {
|
|
1588
|
+
error: Error(
|
|
1589
|
+
`Invalid payload size for RELEASE request. Expected ${fuseReleaseInParser.size} bytes, got ${payload.length} bytes.`
|
|
1590
|
+
),
|
|
1591
|
+
interpreted: undefined,
|
|
1592
|
+
};
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
const { fh, flags, release_flags, lock_owner } = fuseReleaseInParser.parse({ data: payload });
|
|
1596
|
+
|
|
1597
|
+
return {
|
|
1598
|
+
error: undefined,
|
|
1599
|
+
interpreted: {
|
|
1600
|
+
unique,
|
|
1601
|
+
requester,
|
|
1602
|
+
opcode: "RELEASE",
|
|
1603
|
+
nodeId,
|
|
1604
|
+
fh,
|
|
1605
|
+
flags,
|
|
1606
|
+
releaseFlags: release_flags,
|
|
1607
|
+
lockOwner: lock_owner,
|
|
1608
|
+
}
|
|
1609
|
+
};
|
|
1610
|
+
};
|
|
1611
|
+
|
|
1612
|
+
const interpretStatFs/*: TInterpretFunc<"STATFS">*/ = ({ unique, requester }) => {
|
|
1613
|
+
return {
|
|
1614
|
+
error: undefined,
|
|
1615
|
+
interpreted: {
|
|
1616
|
+
unique,
|
|
1617
|
+
requester,
|
|
1618
|
+
opcode: "STATFS",
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
};
|
|
1622
|
+
|
|
1623
|
+
const interpretLookup/*: TInterpretFunc<"LOOKUP">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1624
|
+
const name = decodeCString(payload);
|
|
1625
|
+
|
|
1626
|
+
return {
|
|
1627
|
+
error: undefined,
|
|
1628
|
+
interpreted: {
|
|
1629
|
+
unique,
|
|
1630
|
+
requester,
|
|
1631
|
+
opcode: "LOOKUP",
|
|
1632
|
+
parentNodeId: nodeId,
|
|
1633
|
+
name,
|
|
1634
|
+
}
|
|
1635
|
+
};
|
|
1636
|
+
};
|
|
1637
|
+
|
|
1638
|
+
const interpretOpen/*: TInterpretFunc<"OPEN">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1639
|
+
if (payload.length !== fuseOpenInParser.size) {
|
|
1640
|
+
return {
|
|
1641
|
+
error: Error(`Invalid payload size for OPEN request. Expected ${fuseOpenInParser.size} bytes, got ${payload.length} bytes.`),
|
|
1642
|
+
interpreted: undefined,
|
|
1643
|
+
};
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
const { flags } = fuseOpenInParser.parse({ data: payload });
|
|
1647
|
+
|
|
1648
|
+
return {
|
|
1649
|
+
error: undefined,
|
|
1650
|
+
interpreted: {
|
|
1651
|
+
unique,
|
|
1652
|
+
requester,
|
|
1653
|
+
opcode: "OPEN",
|
|
1654
|
+
nodeId,
|
|
1655
|
+
flags,
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
};
|
|
1659
|
+
|
|
1660
|
+
const interpretRead/*: TInterpretFunc<"READ">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1661
|
+
if (payload.length !== fuseReadInParser.size) {
|
|
1662
|
+
return {
|
|
1663
|
+
error: Error(`Invalid payload size for READ request. Expected ${fuseReadInParser.size} bytes, got ${payload.length} bytes.`),
|
|
1664
|
+
interpreted: undefined,
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
const { fh, offset, size, lock_owner, read_flags } = fuseReadInParser.parse({ data: payload });
|
|
1669
|
+
|
|
1670
|
+
return {
|
|
1671
|
+
error: undefined,
|
|
1672
|
+
interpreted: {
|
|
1673
|
+
unique,
|
|
1674
|
+
requester,
|
|
1675
|
+
opcode: "READ",
|
|
1676
|
+
nodeId,
|
|
1677
|
+
fh,
|
|
1678
|
+
offset,
|
|
1679
|
+
size,
|
|
1680
|
+
lockOwner: lock_owner,
|
|
1681
|
+
readFlags: read_flags,
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
};
|
|
1685
|
+
|
|
1686
|
+
const interpretWrite/*: TInterpretFunc<"WRITE">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1687
|
+
if (payload.length < fuseWriteInParser.size) {
|
|
1688
|
+
return {
|
|
1689
|
+
error: Error(
|
|
1690
|
+
`Invalid payload size for WRITE request. Expected at least ${fuseWriteInParser.size} bytes, got ${payload.length} bytes.`
|
|
1691
|
+
),
|
|
1692
|
+
interpreted: undefined,
|
|
1693
|
+
};
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
const { fh, offset, write_flags, lock_owner } = fuseWriteInParser.parse({ data: payload.subarray(0, fuseWriteInParser.size) });
|
|
1697
|
+
const data = payload.subarray(fuseWriteInParser.size);
|
|
1698
|
+
|
|
1699
|
+
return {
|
|
1700
|
+
error: undefined,
|
|
1701
|
+
interpreted: {
|
|
1702
|
+
unique,
|
|
1703
|
+
requester,
|
|
1704
|
+
opcode: "WRITE",
|
|
1705
|
+
nodeId,
|
|
1706
|
+
fh,
|
|
1707
|
+
offset,
|
|
1708
|
+
data,
|
|
1709
|
+
writeFlags: write_flags,
|
|
1710
|
+
lockOwner: lock_owner,
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
};
|
|
1714
|
+
|
|
1715
|
+
const interpretFlush/*: TInterpretFunc<"FLUSH">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1716
|
+
if (payload.length !== fuseFlushInParser.size) {
|
|
1717
|
+
return {
|
|
1718
|
+
error: Error(`Invalid payload size for FLUSH request. Expected ${fuseFlushInParser.size} bytes, got ${payload.length} bytes.`),
|
|
1719
|
+
interpreted: undefined,
|
|
1720
|
+
};
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
const { fh, lock_owner } = fuseFlushInParser.parse({ data: payload });
|
|
1724
|
+
|
|
1725
|
+
return {
|
|
1726
|
+
error: undefined,
|
|
1727
|
+
interpreted: {
|
|
1728
|
+
unique,
|
|
1729
|
+
requester,
|
|
1730
|
+
opcode: "FLUSH",
|
|
1731
|
+
nodeId,
|
|
1732
|
+
fh,
|
|
1733
|
+
lockOwner: lock_owner,
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
};
|
|
1737
|
+
|
|
1738
|
+
const interpretFsync = (
|
|
1739
|
+
{ unique, nodeId, requester, payload, forOpcode }/*:
|
|
1740
|
+
{ unique: bigint; nodeId: bigint; requester: TRequesterInfo; payload: Uint8Array; forOpcode: "FSYNC" | "FSYNCDIR" }*/
|
|
1741
|
+
)/*: TGenericInterpretResult<Extract<TFuseRequest, { opcode: typeof forOpcode }>>*/ => {
|
|
1742
|
+
if (payload.length !== fuseFsyncInParser.size) {
|
|
1743
|
+
return {
|
|
1744
|
+
error: Error(
|
|
1745
|
+
`Invalid payload size for ${forOpcode} request. Expected ${fuseFsyncInParser.size} bytes, got ${payload.length} bytes.`
|
|
1746
|
+
),
|
|
1747
|
+
interpreted: undefined,
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
const { fh, fsync_flags } = fuseFsyncInParser.parse({ data: payload });
|
|
1752
|
+
|
|
1753
|
+
return {
|
|
1754
|
+
error: undefined,
|
|
1755
|
+
interpreted: {
|
|
1756
|
+
unique,
|
|
1757
|
+
requester,
|
|
1758
|
+
opcode: forOpcode,
|
|
1759
|
+
nodeId,
|
|
1760
|
+
fh,
|
|
1761
|
+
fsyncFlags: fsync_flags,
|
|
1762
|
+
} /*as Extract<TFuseRequest, { opcode: typeof forOpcode }>*/,
|
|
1763
|
+
};
|
|
1764
|
+
};
|
|
1765
|
+
|
|
1766
|
+
const interpretAccess/*: TInterpretFunc<"ACCESS">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1767
|
+
if (payload.length !== fuseAccessInParser.size) {
|
|
1768
|
+
return {
|
|
1769
|
+
error: Error(
|
|
1770
|
+
`Invalid payload size for ACCESS request. Expected ${fuseAccessInParser.size} bytes, got ${payload.length} bytes.`
|
|
1771
|
+
),
|
|
1772
|
+
interpreted: undefined,
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
const { mask } = fuseAccessInParser.parse({ data: payload });
|
|
1777
|
+
|
|
1778
|
+
return {
|
|
1779
|
+
error: undefined,
|
|
1780
|
+
interpreted: {
|
|
1781
|
+
unique,
|
|
1782
|
+
requester,
|
|
1783
|
+
opcode: "ACCESS",
|
|
1784
|
+
nodeId,
|
|
1785
|
+
mask,
|
|
1786
|
+
}
|
|
1787
|
+
};
|
|
1788
|
+
};
|
|
1789
|
+
|
|
1790
|
+
const interpretSetXAttr/*: TInterpretFunc<"SETXATTR">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1791
|
+
if (payload.length < fuseSetxattrInParser.size) {
|
|
1792
|
+
return {
|
|
1793
|
+
error: Error(
|
|
1794
|
+
`Invalid payload size for SETXATTR request. Expected at least ${fuseSetxattrInParser.size} bytes, got ${payload.length} bytes.`
|
|
1795
|
+
),
|
|
1796
|
+
interpreted: undefined,
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
const { size, flags, setxattr_flags } = fuseSetxattrInParser.parse({ data: payload.subarray(0, fuseSetxattrInParser.size) });
|
|
1801
|
+
const trailing = payload.subarray(fuseSetxattrInParser.size);
|
|
1802
|
+
const nameTerminator = trailing.indexOf(0);
|
|
1803
|
+
if (nameTerminator === -1) {
|
|
1804
|
+
return {
|
|
1805
|
+
error: Error("Invalid payload for SETXATTR request. Expected a nul-terminated attribute name."),
|
|
1806
|
+
interpreted: undefined,
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
const name = decodeCString(trailing);
|
|
1811
|
+
const data = trailing.subarray(nameTerminator + 1);
|
|
1812
|
+
if (BigInt(data.length) !== size) {
|
|
1813
|
+
return {
|
|
1814
|
+
error: Error(`Invalid payload size for SETXATTR request data. Expected ${size} bytes, got ${data.length} bytes.`),
|
|
1815
|
+
interpreted: undefined,
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
return {
|
|
1820
|
+
error: undefined,
|
|
1821
|
+
interpreted: {
|
|
1822
|
+
unique,
|
|
1823
|
+
requester,
|
|
1824
|
+
opcode: "SETXATTR",
|
|
1825
|
+
nodeId,
|
|
1826
|
+
name,
|
|
1827
|
+
data,
|
|
1828
|
+
flags,
|
|
1829
|
+
setxattrFlags: setxattr_flags,
|
|
1830
|
+
}
|
|
1831
|
+
};
|
|
1832
|
+
};
|
|
1833
|
+
|
|
1834
|
+
const interpretRemoveXAttr/*: TInterpretFunc<"REMOVEXATTR">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1835
|
+
return {
|
|
1836
|
+
error: undefined,
|
|
1837
|
+
interpreted: {
|
|
1838
|
+
unique,
|
|
1839
|
+
requester,
|
|
1840
|
+
opcode: "REMOVEXATTR",
|
|
1841
|
+
nodeId,
|
|
1842
|
+
name: decodeCString(payload),
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
};
|
|
1846
|
+
|
|
1847
|
+
const interpretCreate/*: TInterpretFunc<"CREATE">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1848
|
+
if (payload.length < fuseCreateInParser.size) {
|
|
1849
|
+
return {
|
|
1850
|
+
error: Error(
|
|
1851
|
+
`Invalid payload size for CREATE request. Expected at least ${fuseCreateInParser.size} bytes, got ${payload.length} bytes.`
|
|
1852
|
+
),
|
|
1853
|
+
interpreted: undefined,
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
const { flags, mode, umask } = fuseCreateInParser.parse({ data: payload.subarray(0, fuseCreateInParser.size) });
|
|
1858
|
+
|
|
1859
|
+
return {
|
|
1860
|
+
error: undefined,
|
|
1861
|
+
interpreted: {
|
|
1862
|
+
unique,
|
|
1863
|
+
requester,
|
|
1864
|
+
opcode: "CREATE",
|
|
1865
|
+
parentNodeId: nodeId,
|
|
1866
|
+
name: decodeCString(payload.subarray(fuseCreateInParser.size)),
|
|
1867
|
+
flags,
|
|
1868
|
+
mode,
|
|
1869
|
+
umask,
|
|
1870
|
+
}
|
|
1871
|
+
};
|
|
1872
|
+
};
|
|
1873
|
+
|
|
1874
|
+
const interpretDestroy/*: TInterpretFunc<"DESTROY">*/ = ({ unique, requester }) => {
|
|
1875
|
+
return {
|
|
1876
|
+
error: undefined,
|
|
1877
|
+
interpreted: {
|
|
1878
|
+
unique,
|
|
1879
|
+
requester,
|
|
1880
|
+
opcode: "DESTROY",
|
|
1881
|
+
}
|
|
1882
|
+
};
|
|
1883
|
+
};
|
|
1884
|
+
|
|
1885
|
+
const interpretLk = (
|
|
1886
|
+
{ unique, nodeId, requester, payload, forOpcode }/*:
|
|
1887
|
+
{ unique: bigint; nodeId: bigint; requester: TRequesterInfo; payload: Uint8Array; forOpcode: "GETLK" | "SETLK" | "SETLKW" }*/
|
|
1888
|
+
)/*: TGenericInterpretResult<Extract<TFuseRequest, { opcode: typeof forOpcode }>>*/ => {
|
|
1889
|
+
if (payload.length !== fuseLkInParser.size) {
|
|
1890
|
+
return {
|
|
1891
|
+
error: Error(
|
|
1892
|
+
`Invalid payload size for ${forOpcode} request. Expected ${fuseLkInParser.size} bytes, got ${payload.length} bytes.`
|
|
1893
|
+
),
|
|
1894
|
+
interpreted: undefined,
|
|
1895
|
+
};
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
const { fh, owner, lk, lk_flags } = fuseLkInParser.parse({ data: payload });
|
|
1899
|
+
|
|
1900
|
+
return {
|
|
1901
|
+
error: undefined,
|
|
1902
|
+
interpreted: {
|
|
1903
|
+
unique,
|
|
1904
|
+
requester,
|
|
1905
|
+
opcode: forOpcode,
|
|
1906
|
+
nodeId,
|
|
1907
|
+
fh,
|
|
1908
|
+
owner,
|
|
1909
|
+
lockStart: lk.start,
|
|
1910
|
+
lockEnd: lk.end,
|
|
1911
|
+
lockType: lk.type,
|
|
1912
|
+
lockPid: lk.pid,
|
|
1913
|
+
lkFlags: lk_flags,
|
|
1914
|
+
} /*as Extract<TFuseRequest, { opcode: typeof forOpcode }>*/,
|
|
1915
|
+
};
|
|
1916
|
+
};
|
|
1917
|
+
|
|
1918
|
+
const interpretInterrupt/*: TInterpretFunc<"INTERRUPT">*/ = ({ unique, requester, payload }) => {
|
|
1919
|
+
if (payload.length !== fuseInterruptInParser.size) {
|
|
1920
|
+
return {
|
|
1921
|
+
error: Error(
|
|
1922
|
+
`Invalid payload size for INTERRUPT request. Expected ${fuseInterruptInParser.size} bytes, got ${payload.length} bytes.`
|
|
1923
|
+
),
|
|
1924
|
+
interpreted: undefined,
|
|
1925
|
+
};
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
const parsed = fuseInterruptInParser.parse({ data: payload });
|
|
1929
|
+
|
|
1930
|
+
return {
|
|
1931
|
+
error: undefined,
|
|
1932
|
+
interpreted: {
|
|
1933
|
+
unique,
|
|
1934
|
+
requester,
|
|
1935
|
+
opcode: "INTERRUPT",
|
|
1936
|
+
targetUnique: parsed.unique,
|
|
1937
|
+
}
|
|
1938
|
+
};
|
|
1939
|
+
};
|
|
1940
|
+
|
|
1941
|
+
const interpretBmap/*: TInterpretFunc<"BMAP">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1942
|
+
if (payload.length !== fuseBmapInParser.size) {
|
|
1943
|
+
return {
|
|
1944
|
+
error: Error(`Invalid payload size for BMAP request. Expected ${fuseBmapInParser.size} bytes, got ${payload.length} bytes.`),
|
|
1945
|
+
interpreted: undefined,
|
|
1946
|
+
};
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
const { block, blocksize } = fuseBmapInParser.parse({ data: payload });
|
|
1950
|
+
|
|
1951
|
+
return {
|
|
1952
|
+
error: undefined,
|
|
1953
|
+
interpreted: {
|
|
1954
|
+
unique,
|
|
1955
|
+
requester,
|
|
1956
|
+
opcode: "BMAP",
|
|
1957
|
+
nodeId,
|
|
1958
|
+
block,
|
|
1959
|
+
blocksize,
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
};
|
|
1963
|
+
|
|
1964
|
+
const interpretIoctl/*: TInterpretFunc<"IOCTL">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1965
|
+
if (payload.length < fuseIoctlInParser.size) {
|
|
1966
|
+
return {
|
|
1967
|
+
error: Error(
|
|
1968
|
+
`Invalid payload size for IOCTL request. Expected at least ${fuseIoctlInParser.size} bytes, got ${payload.length} bytes.`
|
|
1969
|
+
),
|
|
1970
|
+
interpreted: undefined,
|
|
1971
|
+
};
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
const { fh, flags, cmd, arg, out_size } = fuseIoctlInParser.parse({ data: payload.subarray(0, fuseIoctlInParser.size) });
|
|
1975
|
+
|
|
1976
|
+
return {
|
|
1977
|
+
error: undefined,
|
|
1978
|
+
interpreted: {
|
|
1979
|
+
unique,
|
|
1980
|
+
requester,
|
|
1981
|
+
opcode: "IOCTL",
|
|
1982
|
+
nodeId,
|
|
1983
|
+
fh,
|
|
1984
|
+
flags,
|
|
1985
|
+
cmd,
|
|
1986
|
+
arg,
|
|
1987
|
+
inData: payload.subarray(fuseIoctlInParser.size),
|
|
1988
|
+
outSize: out_size,
|
|
1989
|
+
}
|
|
1990
|
+
};
|
|
1991
|
+
};
|
|
1992
|
+
|
|
1993
|
+
const interpretPoll/*: TInterpretFunc<"POLL">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
1994
|
+
if (payload.length !== fusePollInParser.size) {
|
|
1995
|
+
return {
|
|
1996
|
+
error: Error(`Invalid payload size for POLL request. Expected ${fusePollInParser.size} bytes, got ${payload.length} bytes.`),
|
|
1997
|
+
interpreted: undefined,
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
const { fh, kh, flags, events } = fusePollInParser.parse({ data: payload });
|
|
2002
|
+
|
|
2003
|
+
return {
|
|
2004
|
+
error: undefined,
|
|
2005
|
+
interpreted: {
|
|
2006
|
+
unique,
|
|
2007
|
+
requester,
|
|
2008
|
+
opcode: "POLL",
|
|
2009
|
+
nodeId,
|
|
2010
|
+
fh,
|
|
2011
|
+
kh,
|
|
2012
|
+
flags,
|
|
2013
|
+
events,
|
|
2014
|
+
}
|
|
2015
|
+
};
|
|
2016
|
+
};
|
|
2017
|
+
|
|
2018
|
+
const interpretNotifyReply/*: TInterpretFunc<"NOTIFY_REPLY">*/ = ({ unique, requester, payload }) => {
|
|
2019
|
+
return {
|
|
2020
|
+
error: undefined,
|
|
2021
|
+
interpreted: {
|
|
2022
|
+
unique,
|
|
2023
|
+
requester,
|
|
2024
|
+
opcode: "NOTIFY_REPLY",
|
|
2025
|
+
data: payload,
|
|
2026
|
+
}
|
|
2027
|
+
};
|
|
2028
|
+
};
|
|
2029
|
+
|
|
2030
|
+
const interpretFallocate/*: TInterpretFunc<"FALLOCATE">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
2031
|
+
if (payload.length !== fuseFallocateInParser.size) {
|
|
2032
|
+
return {
|
|
2033
|
+
error: Error(
|
|
2034
|
+
`Invalid payload size for FALLOCATE request. Expected ${fuseFallocateInParser.size} bytes, got ${payload.length} bytes.`
|
|
2035
|
+
),
|
|
2036
|
+
interpreted: undefined,
|
|
2037
|
+
};
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
const { fh, offset, length, mode } = fuseFallocateInParser.parse({ data: payload });
|
|
2041
|
+
|
|
2042
|
+
return {
|
|
2043
|
+
error: undefined,
|
|
2044
|
+
interpreted: {
|
|
2045
|
+
unique,
|
|
2046
|
+
requester,
|
|
2047
|
+
opcode: "FALLOCATE",
|
|
2048
|
+
nodeId,
|
|
2049
|
+
fh,
|
|
2050
|
+
offset,
|
|
2051
|
+
length,
|
|
2052
|
+
mode,
|
|
2053
|
+
}
|
|
2054
|
+
};
|
|
2055
|
+
};
|
|
2056
|
+
|
|
2057
|
+
const interpretReadDirPlus/*: TInterpretFunc<"READDIRPLUS">*/ = ({ unique, nodeId, requester, payload }) => {
|
|
2058
|
+
if (payload.length !== fuseReadInParser.size) {
|
|
2059
|
+
return {
|
|
2060
|
+
error: Error(
|
|
2061
|
+
`Invalid payload size for READDIRPLUS request. Expected ${fuseReadInParser.size} bytes, got ${payload.length} bytes.`
|
|
2062
|
+
),
|
|
2063
|
+
interpreted: undefined,
|
|
2064
|
+
};
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
const { fh, offset, size, flags, lock_owner, read_flags } = fuseReadInParser.parse({ data: payload });
|
|
2068
|
+
|
|
2069
|
+
return {
|
|
2070
|
+
error: undefined,
|
|
2071
|
+
interpreted: {
|
|
2072
|
+
unique,
|
|
2073
|
+
requester,
|
|
2074
|
+
opcode: "READDIRPLUS",
|
|
2075
|
+
nodeId,
|
|
2076
|
+
fh,
|
|
2077
|
+
offset,
|
|
2078
|
+
size,
|
|
2079
|
+
flags,
|
|
2080
|
+
lockOwner: lock_owner,
|
|
2081
|
+
readFlags: read_flags,
|
|
2082
|
+
}
|
|
2083
|
+
};
|
|
2084
|
+
};
|
|
2085
|
+
|
|
2086
|
+
const interpretMessageFromKernel = (
|
|
2087
|
+
{ parsedMessageFromKernel }/*: { parsedMessageFromKernel: TParsedMessageFromKernel }*/
|
|
2088
|
+
)/*: TGenericInterpretResult<TFuseRequest>*/ => {
|
|
2089
|
+
|
|
2090
|
+
const unique = parsedMessageFromKernel.header.unique;
|
|
2091
|
+
const nodeId = parsedMessageFromKernel.header.nodeid;
|
|
2092
|
+
const requester = {
|
|
2093
|
+
uid: parsedMessageFromKernel.header.uid,
|
|
2094
|
+
gid: parsedMessageFromKernel.header.gid,
|
|
2095
|
+
pid: parsedMessageFromKernel.header.pid,
|
|
2096
|
+
};
|
|
2097
|
+
|
|
2098
|
+
switch (parsedMessageFromKernel.header.opcode) {
|
|
2099
|
+
case BigInt(opcode.INIT): {
|
|
2100
|
+
return interpretInit({
|
|
2101
|
+
unique,
|
|
2102
|
+
nodeId,
|
|
2103
|
+
requester,
|
|
2104
|
+
payload: parsedMessageFromKernel.payload,
|
|
2105
|
+
});
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
case BigInt(opcode.FORGET): {
|
|
2109
|
+
return interpretForget({
|
|
2110
|
+
unique,
|
|
2111
|
+
nodeId,
|
|
2112
|
+
requester,
|
|
2113
|
+
payload: parsedMessageFromKernel.payload,
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
case BigInt(opcode.BATCH_FORGET): {
|
|
2118
|
+
return interpretBatchForget({
|
|
2119
|
+
unique,
|
|
2120
|
+
nodeId,
|
|
2121
|
+
requester,
|
|
2122
|
+
payload: parsedMessageFromKernel.payload,
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
case BigInt(opcode.GETATTR): {
|
|
2127
|
+
return interpretGetAttr({
|
|
2128
|
+
unique,
|
|
2129
|
+
nodeId,
|
|
2130
|
+
requester,
|
|
2131
|
+
payload: parsedMessageFromKernel.payload,
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
case BigInt(opcode.SETATTR): {
|
|
2136
|
+
return interpretSetAttr({
|
|
2137
|
+
unique,
|
|
2138
|
+
nodeId,
|
|
2139
|
+
requester,
|
|
2140
|
+
payload: parsedMessageFromKernel.payload,
|
|
2141
|
+
});
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
case BigInt(opcode.LISTXATTR): {
|
|
2145
|
+
return interpretListXAttrRequest({
|
|
2146
|
+
unique,
|
|
2147
|
+
nodeId,
|
|
2148
|
+
requester,
|
|
2149
|
+
payload: parsedMessageFromKernel.payload,
|
|
2150
|
+
});
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
case BigInt(opcode.GETXATTR): {
|
|
2154
|
+
return interpretGetXAttr({
|
|
2155
|
+
unique,
|
|
2156
|
+
nodeId,
|
|
2157
|
+
requester,
|
|
2158
|
+
payload: parsedMessageFromKernel.payload,
|
|
2159
|
+
});
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
case BigInt(opcode.READLINK): {
|
|
2163
|
+
return interpretReadLink({
|
|
2164
|
+
unique,
|
|
2165
|
+
nodeId,
|
|
2166
|
+
requester,
|
|
2167
|
+
payload: parsedMessageFromKernel.payload,
|
|
2168
|
+
});
|
|
2169
|
+
}
|
|
2170
|
+
|
|
2171
|
+
case BigInt(opcode.SYMLINK): {
|
|
2172
|
+
return interpretSymlink({
|
|
2173
|
+
unique,
|
|
2174
|
+
nodeId,
|
|
2175
|
+
requester,
|
|
2176
|
+
payload: parsedMessageFromKernel.payload,
|
|
2177
|
+
});
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
case BigInt(opcode.MKNOD): {
|
|
2181
|
+
return interpretMknod({
|
|
2182
|
+
unique,
|
|
2183
|
+
nodeId,
|
|
2184
|
+
requester,
|
|
2185
|
+
payload: parsedMessageFromKernel.payload,
|
|
2186
|
+
});
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
case BigInt(opcode.MKDIR): {
|
|
2190
|
+
return interpretMkdir({
|
|
2191
|
+
unique,
|
|
2192
|
+
nodeId,
|
|
2193
|
+
requester,
|
|
2194
|
+
payload: parsedMessageFromKernel.payload,
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
case BigInt(opcode.UNLINK): {
|
|
2199
|
+
return interpretUnlink({
|
|
2200
|
+
unique,
|
|
2201
|
+
nodeId,
|
|
2202
|
+
requester,
|
|
2203
|
+
payload: parsedMessageFromKernel.payload,
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
case BigInt(opcode.RMDIR): {
|
|
2208
|
+
return interpretRmDir({
|
|
2209
|
+
unique,
|
|
2210
|
+
nodeId,
|
|
2211
|
+
requester,
|
|
2212
|
+
payload: parsedMessageFromKernel.payload,
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
case BigInt(opcode.RENAME): {
|
|
2217
|
+
return interpretRename({
|
|
2218
|
+
unique,
|
|
2219
|
+
nodeId,
|
|
2220
|
+
requester,
|
|
2221
|
+
payload: parsedMessageFromKernel.payload,
|
|
2222
|
+
supportsFlags: false,
|
|
2223
|
+
});
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
case BigInt(opcode.RENAME2): {
|
|
2227
|
+
return interpretRename({
|
|
2228
|
+
unique,
|
|
2229
|
+
nodeId,
|
|
2230
|
+
requester,
|
|
2231
|
+
payload: parsedMessageFromKernel.payload,
|
|
2232
|
+
supportsFlags: true,
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
2235
|
+
|
|
2236
|
+
case BigInt(opcode.OPENDIR): {
|
|
2237
|
+
return interpretOpenDir({
|
|
2238
|
+
unique,
|
|
2239
|
+
nodeId,
|
|
2240
|
+
requester,
|
|
2241
|
+
payload: parsedMessageFromKernel.payload,
|
|
2242
|
+
});
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
case BigInt(opcode.LINK): {
|
|
2246
|
+
return interpretLink({
|
|
2247
|
+
unique,
|
|
2248
|
+
nodeId,
|
|
2249
|
+
requester,
|
|
2250
|
+
payload: parsedMessageFromKernel.payload,
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
case BigInt(opcode.READDIR): {
|
|
2255
|
+
return interpretReadDir({
|
|
2256
|
+
unique,
|
|
2257
|
+
nodeId,
|
|
2258
|
+
requester,
|
|
2259
|
+
payload: parsedMessageFromKernel.payload,
|
|
2260
|
+
});
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
case BigInt(opcode.RELEASE): {
|
|
2264
|
+
return interpretRelease({
|
|
2265
|
+
unique,
|
|
2266
|
+
nodeId,
|
|
2267
|
+
requester,
|
|
2268
|
+
payload: parsedMessageFromKernel.payload,
|
|
2269
|
+
});
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
case BigInt(opcode.RELEASEDIR): {
|
|
2273
|
+
return interpretReleaseDir({
|
|
2274
|
+
unique,
|
|
2275
|
+
nodeId,
|
|
2276
|
+
requester,
|
|
2277
|
+
payload: parsedMessageFromKernel.payload,
|
|
2278
|
+
});
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
case BigInt(opcode.FSYNCDIR): {
|
|
2282
|
+
return interpretFsync({
|
|
2283
|
+
unique,
|
|
2284
|
+
nodeId,
|
|
2285
|
+
requester,
|
|
2286
|
+
payload: parsedMessageFromKernel.payload,
|
|
2287
|
+
forOpcode: "FSYNCDIR",
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
case BigInt(opcode.STATFS): {
|
|
2292
|
+
return interpretStatFs({
|
|
2293
|
+
unique,
|
|
2294
|
+
nodeId,
|
|
2295
|
+
requester,
|
|
2296
|
+
payload: parsedMessageFromKernel.payload,
|
|
2297
|
+
});
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
case BigInt(opcode.LOOKUP): {
|
|
2301
|
+
return interpretLookup({
|
|
2302
|
+
unique,
|
|
2303
|
+
nodeId,
|
|
2304
|
+
requester,
|
|
2305
|
+
payload: parsedMessageFromKernel.payload,
|
|
2306
|
+
});
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
case BigInt(opcode.OPEN): {
|
|
2310
|
+
return interpretOpen({
|
|
2311
|
+
unique,
|
|
2312
|
+
nodeId,
|
|
2313
|
+
requester,
|
|
2314
|
+
payload: parsedMessageFromKernel.payload,
|
|
2315
|
+
});
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
case BigInt(opcode.READ): {
|
|
2319
|
+
return interpretRead({
|
|
2320
|
+
unique,
|
|
2321
|
+
nodeId,
|
|
2322
|
+
requester,
|
|
2323
|
+
payload: parsedMessageFromKernel.payload,
|
|
2324
|
+
});
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
case BigInt(opcode.WRITE): {
|
|
2328
|
+
return interpretWrite({
|
|
2329
|
+
unique,
|
|
2330
|
+
nodeId,
|
|
2331
|
+
requester,
|
|
2332
|
+
payload: parsedMessageFromKernel.payload,
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
case BigInt(opcode.FLUSH): {
|
|
2337
|
+
return interpretFlush({
|
|
2338
|
+
unique,
|
|
2339
|
+
nodeId,
|
|
2340
|
+
requester,
|
|
2341
|
+
payload: parsedMessageFromKernel.payload,
|
|
2342
|
+
});
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
case BigInt(opcode.FSYNC): {
|
|
2346
|
+
return interpretFsync({
|
|
2347
|
+
unique,
|
|
2348
|
+
nodeId,
|
|
2349
|
+
requester,
|
|
2350
|
+
payload: parsedMessageFromKernel.payload,
|
|
2351
|
+
forOpcode: "FSYNC",
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
case BigInt(opcode.ACCESS): {
|
|
2356
|
+
return interpretAccess({
|
|
2357
|
+
unique,
|
|
2358
|
+
nodeId,
|
|
2359
|
+
requester,
|
|
2360
|
+
payload: parsedMessageFromKernel.payload,
|
|
2361
|
+
});
|
|
2362
|
+
}
|
|
2363
|
+
|
|
2364
|
+
case BigInt(opcode.SETXATTR): {
|
|
2365
|
+
return interpretSetXAttr({
|
|
2366
|
+
unique,
|
|
2367
|
+
nodeId,
|
|
2368
|
+
requester,
|
|
2369
|
+
payload: parsedMessageFromKernel.payload,
|
|
2370
|
+
});
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2373
|
+
case BigInt(opcode.REMOVEXATTR): {
|
|
2374
|
+
return interpretRemoveXAttr({
|
|
2375
|
+
unique,
|
|
2376
|
+
nodeId,
|
|
2377
|
+
requester,
|
|
2378
|
+
payload: parsedMessageFromKernel.payload,
|
|
2379
|
+
});
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
case BigInt(opcode.CREATE): {
|
|
2383
|
+
return interpretCreate({
|
|
2384
|
+
unique,
|
|
2385
|
+
nodeId,
|
|
2386
|
+
requester,
|
|
2387
|
+
payload: parsedMessageFromKernel.payload,
|
|
2388
|
+
});
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
case BigInt(opcode.DESTROY): {
|
|
2392
|
+
return interpretDestroy({
|
|
2393
|
+
unique,
|
|
2394
|
+
nodeId,
|
|
2395
|
+
requester,
|
|
2396
|
+
payload: parsedMessageFromKernel.payload,
|
|
2397
|
+
});
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2400
|
+
case BigInt(opcode.GETLK): {
|
|
2401
|
+
return interpretLk({
|
|
2402
|
+
unique,
|
|
2403
|
+
nodeId,
|
|
2404
|
+
requester,
|
|
2405
|
+
payload: parsedMessageFromKernel.payload,
|
|
2406
|
+
forOpcode: "GETLK",
|
|
2407
|
+
});
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
case BigInt(opcode.SETLK): {
|
|
2411
|
+
return interpretLk({
|
|
2412
|
+
unique,
|
|
2413
|
+
nodeId,
|
|
2414
|
+
requester,
|
|
2415
|
+
payload: parsedMessageFromKernel.payload,
|
|
2416
|
+
forOpcode: "SETLK",
|
|
2417
|
+
});
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
case BigInt(opcode.SETLKW): {
|
|
2421
|
+
return interpretLk({
|
|
2422
|
+
unique,
|
|
2423
|
+
nodeId,
|
|
2424
|
+
requester,
|
|
2425
|
+
payload: parsedMessageFromKernel.payload,
|
|
2426
|
+
forOpcode: "SETLKW",
|
|
2427
|
+
});
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
case BigInt(opcode.INTERRUPT): {
|
|
2431
|
+
return interpretInterrupt({
|
|
2432
|
+
unique,
|
|
2433
|
+
nodeId,
|
|
2434
|
+
requester,
|
|
2435
|
+
payload: parsedMessageFromKernel.payload,
|
|
2436
|
+
});
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2439
|
+
case BigInt(opcode.BMAP): {
|
|
2440
|
+
return interpretBmap({
|
|
2441
|
+
unique,
|
|
2442
|
+
nodeId,
|
|
2443
|
+
requester,
|
|
2444
|
+
payload: parsedMessageFromKernel.payload,
|
|
2445
|
+
});
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
case BigInt(opcode.IOCTL): {
|
|
2449
|
+
return interpretIoctl({
|
|
2450
|
+
unique,
|
|
2451
|
+
nodeId,
|
|
2452
|
+
requester,
|
|
2453
|
+
payload: parsedMessageFromKernel.payload,
|
|
2454
|
+
});
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2457
|
+
case BigInt(opcode.POLL): {
|
|
2458
|
+
return interpretPoll({
|
|
2459
|
+
unique,
|
|
2460
|
+
nodeId,
|
|
2461
|
+
requester,
|
|
2462
|
+
payload: parsedMessageFromKernel.payload,
|
|
2463
|
+
});
|
|
2464
|
+
}
|
|
2465
|
+
|
|
2466
|
+
case BigInt(opcode.NOTIFY_REPLY): {
|
|
2467
|
+
return interpretNotifyReply({
|
|
2468
|
+
unique,
|
|
2469
|
+
nodeId,
|
|
2470
|
+
requester,
|
|
2471
|
+
payload: parsedMessageFromKernel.payload,
|
|
2472
|
+
});
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
case BigInt(opcode.FALLOCATE): {
|
|
2476
|
+
return interpretFallocate({
|
|
2477
|
+
unique,
|
|
2478
|
+
nodeId,
|
|
2479
|
+
requester,
|
|
2480
|
+
payload: parsedMessageFromKernel.payload,
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
case BigInt(opcode.READDIRPLUS): {
|
|
2485
|
+
return interpretReadDirPlus({
|
|
2486
|
+
unique,
|
|
2487
|
+
nodeId,
|
|
2488
|
+
requester,
|
|
2489
|
+
payload: parsedMessageFromKernel.payload,
|
|
2490
|
+
});
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
default: {
|
|
2494
|
+
break;
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
return {
|
|
2499
|
+
error: Error(`Unsupported opcode: ${parsedMessageFromKernel.header.opcode}`),
|
|
2500
|
+
interpreted: undefined,
|
|
2501
|
+
};
|
|
2502
|
+
};
|
|
2503
|
+
|
|
2504
|
+
return {
|
|
2505
|
+
interpretMessageFromKernel,
|
|
2506
|
+
};
|
|
2507
|
+
};
|
|
2508
|
+
|
|
2509
|
+
|
|
2510
|
+
const createMessageToKernelInterpreter = () => {
|
|
2511
|
+
|
|
2512
|
+
/*type TInterpretFunc<T extends string> = (
|
|
2513
|
+
args: { unique: bigint, payload: Uint8Array }
|
|
2514
|
+
) => TGenericInterpretResult<Extract<TFuseResponse, { forOpcode: T }>>;*/
|
|
2515
|
+
|
|
2516
|
+
const encodeInitResponse = (
|
|
2517
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "INIT", errorCode: undefined }> }*/
|
|
2518
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2519
|
+
|
|
2520
|
+
const initResult = response.result;
|
|
2521
|
+
|
|
2522
|
+
const initResultPayload = fuseInitOutParser.format({
|
|
2523
|
+
value: {
|
|
2524
|
+
major: initResult.major,
|
|
2525
|
+
minor: initResult.minor,
|
|
2526
|
+
max_readahead: initResult.maxReadahead,
|
|
2527
|
+
flags: initResult.flags,
|
|
2528
|
+
max_background: initResult.maxBackground,
|
|
2529
|
+
congestion_threshold: initResult.congestionThreshold,
|
|
2530
|
+
max_write: initResult.maxWrite,
|
|
2531
|
+
time_gran: initResult.timeGran,
|
|
2532
|
+
max_pages: initResult.maxPages,
|
|
2533
|
+
map_alignment: initResult.mapAlignment,
|
|
2534
|
+
flags2: initResult.flags2,
|
|
2535
|
+
max_stack_depth: initResult.maxStackDepth,
|
|
2536
|
+
request_timeout: initResult.requestTimeout,
|
|
2537
|
+
unused: [0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n],
|
|
2538
|
+
}
|
|
2539
|
+
});
|
|
2540
|
+
|
|
2541
|
+
return {
|
|
2542
|
+
header: {
|
|
2543
|
+
unique: response.unique,
|
|
2544
|
+
error: 0n,
|
|
2545
|
+
},
|
|
2546
|
+
payload: initResultPayload,
|
|
2547
|
+
};
|
|
2548
|
+
};
|
|
2549
|
+
|
|
2550
|
+
const encodeGetAttrResponse = (
|
|
2551
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "GETATTR", errorCode: undefined }> }*/
|
|
2552
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2553
|
+
return encodeAttrPayload({ unique: response.unique, forOpcode: "GETATTR", result: response.result });
|
|
2554
|
+
};
|
|
2555
|
+
|
|
2556
|
+
const encodeSetAttrResponse = (
|
|
2557
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "SETATTR", errorCode: undefined }> }*/
|
|
2558
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2559
|
+
return encodeAttrPayload({ unique: response.unique, forOpcode: "SETATTR", result: response.result });
|
|
2560
|
+
};
|
|
2561
|
+
|
|
2562
|
+
const encodeOpenDirResponse = (
|
|
2563
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "OPENDIR", errorCode: undefined }> }*/
|
|
2564
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2565
|
+
return encodeOpenPayload({ unique: response.unique, result: response.result });
|
|
2566
|
+
};
|
|
2567
|
+
|
|
2568
|
+
const encodeReadDirResponse = (
|
|
2569
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "READDIR", errorCode: undefined }> }*/
|
|
2570
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2571
|
+
return {
|
|
2572
|
+
header: {
|
|
2573
|
+
unique: response.unique,
|
|
2574
|
+
error: 0n,
|
|
2575
|
+
},
|
|
2576
|
+
payload: response.result.data,
|
|
2577
|
+
};
|
|
2578
|
+
};
|
|
2579
|
+
|
|
2580
|
+
const encodeReleaseDirResponse = (
|
|
2581
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "RELEASEDIR", errorCode: undefined }> }*/
|
|
2582
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2583
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2584
|
+
};
|
|
2585
|
+
|
|
2586
|
+
const encodeReleaseResponse = (
|
|
2587
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "RELEASE", errorCode: undefined }> }*/
|
|
2588
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2589
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2590
|
+
};
|
|
2591
|
+
|
|
2592
|
+
const encodeOpenResponse = (
|
|
2593
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "OPEN", errorCode: undefined }> }*/
|
|
2594
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2595
|
+
return encodeOpenPayload({ unique: response.unique, result: response.result });
|
|
2596
|
+
};
|
|
2597
|
+
|
|
2598
|
+
const encodeReadResponse = (
|
|
2599
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "READ", errorCode: undefined }> }*/
|
|
2600
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2601
|
+
return {
|
|
2602
|
+
header: {
|
|
2603
|
+
unique: response.unique,
|
|
2604
|
+
error: 0n,
|
|
2605
|
+
},
|
|
2606
|
+
payload: response.result.data,
|
|
2607
|
+
};
|
|
2608
|
+
};
|
|
2609
|
+
|
|
2610
|
+
const encodeWriteResponse = (
|
|
2611
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "WRITE", errorCode: undefined }> }*/
|
|
2612
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2613
|
+
const writeResultPayload = fuseWriteOutParser.format({
|
|
2614
|
+
value: {
|
|
2615
|
+
size: response.result.bytesWritten,
|
|
2616
|
+
padding: 0n,
|
|
2617
|
+
}
|
|
2618
|
+
});
|
|
2619
|
+
|
|
2620
|
+
return {
|
|
2621
|
+
header: {
|
|
2622
|
+
unique: response.unique,
|
|
2623
|
+
error: 0n,
|
|
2624
|
+
},
|
|
2625
|
+
payload: writeResultPayload,
|
|
2626
|
+
};
|
|
2627
|
+
};
|
|
2628
|
+
|
|
2629
|
+
const encodeLookupResponse = (
|
|
2630
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "LOOKUP", errorCode: undefined }> }*/
|
|
2631
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2632
|
+
return encodeEntryPayload({ unique: response.unique, forOpcode: "LOOKUP", result: response.result });
|
|
2633
|
+
};
|
|
2634
|
+
|
|
2635
|
+
const encodeSymlinkResponse = (
|
|
2636
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "SYMLINK", errorCode: undefined }> }*/
|
|
2637
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2638
|
+
return encodeEntryPayload({ unique: response.unique, forOpcode: "SYMLINK", result: response.result });
|
|
2639
|
+
};
|
|
2640
|
+
|
|
2641
|
+
const encodeMkdirResponse = (
|
|
2642
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "MKDIR", errorCode: undefined }> }*/
|
|
2643
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2644
|
+
return encodeEntryPayload({ unique: response.unique, forOpcode: "MKDIR", result: response.result });
|
|
2645
|
+
};
|
|
2646
|
+
|
|
2647
|
+
const encodeStatFsResponse = (
|
|
2648
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "STATFS", errorCode: undefined }> }*/
|
|
2649
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2650
|
+
const statFsResult = response.result;
|
|
2651
|
+
|
|
2652
|
+
const statFsResultPayload = fuseStatfsOutParser.format({
|
|
2653
|
+
value: {
|
|
2654
|
+
st: {
|
|
2655
|
+
blocks: statFsResult.blocks,
|
|
2656
|
+
bfree: statFsResult.bfree,
|
|
2657
|
+
bavail: statFsResult.bavail,
|
|
2658
|
+
files: statFsResult.files,
|
|
2659
|
+
ffree: statFsResult.ffree,
|
|
2660
|
+
bsize: statFsResult.bsize,
|
|
2661
|
+
namelen: statFsResult.namelen,
|
|
2662
|
+
frsize: statFsResult.frsize,
|
|
2663
|
+
padding: 0n,
|
|
2664
|
+
spare: [0n, 0n, 0n, 0n, 0n, 0n],
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
});
|
|
2668
|
+
|
|
2669
|
+
return {
|
|
2670
|
+
header: {
|
|
2671
|
+
unique: response.unique,
|
|
2672
|
+
error: 0n,
|
|
2673
|
+
},
|
|
2674
|
+
payload: statFsResultPayload,
|
|
2675
|
+
};
|
|
2676
|
+
};
|
|
2677
|
+
|
|
2678
|
+
const encodeGetXAttrResponse = (
|
|
2679
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "GETXATTR", errorCode: undefined }> }*/
|
|
2680
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2681
|
+
return encodeXAttrPayload({ unique: response.unique, result: response.result });
|
|
2682
|
+
};
|
|
2683
|
+
|
|
2684
|
+
const encodeListXAttrResponse = (
|
|
2685
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "LISTXATTR", errorCode: undefined }> }*/
|
|
2686
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2687
|
+
return encodeXAttrPayload({ unique: response.unique, result: response.result });
|
|
2688
|
+
};
|
|
2689
|
+
|
|
2690
|
+
const encodeReadLinkResponse = (
|
|
2691
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "READLINK", errorCode: undefined }> }*/
|
|
2692
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2693
|
+
return {
|
|
2694
|
+
header: {
|
|
2695
|
+
unique: response.unique,
|
|
2696
|
+
error: 0n,
|
|
2697
|
+
},
|
|
2698
|
+
payload: new TextEncoder().encode(response.result.target),
|
|
2699
|
+
};
|
|
2700
|
+
};
|
|
2701
|
+
|
|
2702
|
+
const encodeUnlinkResponse = (
|
|
2703
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "UNLINK", errorCode: undefined }> }*/
|
|
2704
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2705
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2706
|
+
};
|
|
2707
|
+
|
|
2708
|
+
const encodeRmDirResponse = (
|
|
2709
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "RMDIR", errorCode: undefined }> }*/
|
|
2710
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2711
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2712
|
+
};
|
|
2713
|
+
|
|
2714
|
+
const encodeRenameResponse = (
|
|
2715
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "RENAME", errorCode: undefined }> }*/
|
|
2716
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2717
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2718
|
+
};
|
|
2719
|
+
|
|
2720
|
+
const encodeFsyncResponse = (
|
|
2721
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "FSYNC", errorCode: undefined }> }*/
|
|
2722
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2723
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2724
|
+
};
|
|
2725
|
+
|
|
2726
|
+
const encodeSetXAttrResponse = (
|
|
2727
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "SETXATTR", errorCode: undefined }> }*/
|
|
2728
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2729
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2730
|
+
};
|
|
2731
|
+
|
|
2732
|
+
const encodeRemoveXAttrResponse = (
|
|
2733
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "REMOVEXATTR", errorCode: undefined }> }*/
|
|
2734
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2735
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2736
|
+
};
|
|
2737
|
+
|
|
2738
|
+
const encodeMknodResponse = (
|
|
2739
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "MKNOD", errorCode: undefined }> }*/
|
|
2740
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2741
|
+
return encodeEntryPayload({ unique: response.unique, forOpcode: "MKNOD", result: response.result });
|
|
2742
|
+
};
|
|
2743
|
+
|
|
2744
|
+
const encodeLinkResponse = (
|
|
2745
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "LINK", errorCode: undefined }> }*/
|
|
2746
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2747
|
+
return encodeEntryPayload({ unique: response.unique, forOpcode: "LINK", result: response.result });
|
|
2748
|
+
};
|
|
2749
|
+
|
|
2750
|
+
const encodeFsyncDirResponse = (
|
|
2751
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "FSYNCDIR", errorCode: undefined }> }*/
|
|
2752
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2753
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2754
|
+
};
|
|
2755
|
+
|
|
2756
|
+
const encodeFlushResponse = (
|
|
2757
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "FLUSH", errorCode: undefined }> }*/
|
|
2758
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2759
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2760
|
+
};
|
|
2761
|
+
|
|
2762
|
+
const encodeAccessResponse = (
|
|
2763
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "ACCESS", errorCode: undefined }> }*/
|
|
2764
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2765
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2766
|
+
};
|
|
2767
|
+
|
|
2768
|
+
const encodeCreateResponse = (
|
|
2769
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "CREATE", errorCode: undefined }> }*/
|
|
2770
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2771
|
+
const entryPayload = fuseEntryOutParser.format({
|
|
2772
|
+
value: {
|
|
2773
|
+
nodeid: response.result.nodeId,
|
|
2774
|
+
generation: response.result.generation,
|
|
2775
|
+
entry_valid: response.result.entryValidNsec / 1_000_000_000n,
|
|
2776
|
+
attr_valid: response.result.attrValidNsec / 1_000_000_000n,
|
|
2777
|
+
entry_valid_nsec: response.result.entryValidNsec % 1_000_000_000n,
|
|
2778
|
+
attr_valid_nsec: response.result.attrValidNsec % 1_000_000_000n,
|
|
2779
|
+
attr: fuseAttrToPayloadValue({ attr: response.result.attr }),
|
|
2780
|
+
}
|
|
2781
|
+
});
|
|
2782
|
+
const openPayload = fuseOpenOutParser.format({
|
|
2783
|
+
value: {
|
|
2784
|
+
fh: response.result.fh,
|
|
2785
|
+
open_flags: openFlagsToKernelToBitmask({ openFlagsToKernel: response.result.openFlagsToKernel }),
|
|
2786
|
+
backing_id: 0n,
|
|
2787
|
+
}
|
|
2788
|
+
});
|
|
2789
|
+
|
|
2790
|
+
const payload = new Uint8Array(entryPayload.length + openPayload.length);
|
|
2791
|
+
payload.set(entryPayload, 0);
|
|
2792
|
+
payload.set(openPayload, entryPayload.length);
|
|
2793
|
+
|
|
2794
|
+
return {
|
|
2795
|
+
header: {
|
|
2796
|
+
unique: response.unique,
|
|
2797
|
+
error: 0n,
|
|
2798
|
+
},
|
|
2799
|
+
payload,
|
|
2800
|
+
};
|
|
2801
|
+
};
|
|
2802
|
+
|
|
2803
|
+
const encodeDestroyResponse = (
|
|
2804
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "DESTROY", errorCode: undefined }> }*/
|
|
2805
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2806
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2807
|
+
};
|
|
2808
|
+
|
|
2809
|
+
const encodeGetLkResponse = (
|
|
2810
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "GETLK", errorCode: undefined }> }*/
|
|
2811
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2812
|
+
const payload = fuseLkOutParser.format({
|
|
2813
|
+
value: {
|
|
2814
|
+
lk: {
|
|
2815
|
+
start: response.result.lockStart,
|
|
2816
|
+
end: response.result.lockEnd,
|
|
2817
|
+
type: response.result.lockType,
|
|
2818
|
+
pid: response.result.lockPid,
|
|
2819
|
+
},
|
|
2820
|
+
}
|
|
2821
|
+
});
|
|
2822
|
+
|
|
2823
|
+
return {
|
|
2824
|
+
header: {
|
|
2825
|
+
unique: response.unique,
|
|
2826
|
+
error: 0n,
|
|
2827
|
+
},
|
|
2828
|
+
payload,
|
|
2829
|
+
};
|
|
2830
|
+
};
|
|
2831
|
+
|
|
2832
|
+
const encodeSetLkResponse = (
|
|
2833
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "SETLK", errorCode: undefined }> }*/
|
|
2834
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2835
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2836
|
+
};
|
|
2837
|
+
|
|
2838
|
+
const encodeSetLkWResponse = (
|
|
2839
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "SETLKW", errorCode: undefined }> }*/
|
|
2840
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2841
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2842
|
+
};
|
|
2843
|
+
|
|
2844
|
+
const encodeBmapResponse = (
|
|
2845
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "BMAP", errorCode: undefined }> }*/
|
|
2846
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2847
|
+
const payload = fuseBmapOutParser.format({
|
|
2848
|
+
value: {
|
|
2849
|
+
block: response.result.block,
|
|
2850
|
+
}
|
|
2851
|
+
});
|
|
2852
|
+
|
|
2853
|
+
return {
|
|
2854
|
+
header: {
|
|
2855
|
+
unique: response.unique,
|
|
2856
|
+
error: 0n,
|
|
2857
|
+
},
|
|
2858
|
+
payload,
|
|
2859
|
+
};
|
|
2860
|
+
};
|
|
2861
|
+
|
|
2862
|
+
const encodeIoctlResponse = (
|
|
2863
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "IOCTL", errorCode: undefined }> }*/
|
|
2864
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2865
|
+
const headerPayload = fuseIoctlOutParser.format({
|
|
2866
|
+
value: {
|
|
2867
|
+
result: response.result.ioctlResult,
|
|
2868
|
+
flags: response.result.flags,
|
|
2869
|
+
in_iovs: 0n,
|
|
2870
|
+
out_iovs: 0n,
|
|
2871
|
+
}
|
|
2872
|
+
});
|
|
2873
|
+
|
|
2874
|
+
const payload = new Uint8Array(headerPayload.length + response.result.data.length);
|
|
2875
|
+
payload.set(headerPayload, 0);
|
|
2876
|
+
payload.set(response.result.data, headerPayload.length);
|
|
2877
|
+
|
|
2878
|
+
return {
|
|
2879
|
+
header: {
|
|
2880
|
+
unique: response.unique,
|
|
2881
|
+
error: 0n,
|
|
2882
|
+
},
|
|
2883
|
+
payload,
|
|
2884
|
+
};
|
|
2885
|
+
};
|
|
2886
|
+
|
|
2887
|
+
const encodePollResponse = (
|
|
2888
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "POLL", errorCode: undefined }> }*/
|
|
2889
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2890
|
+
const payload = fusePollOutParser.format({
|
|
2891
|
+
value: {
|
|
2892
|
+
revents: response.result.revents,
|
|
2893
|
+
padding: 0n,
|
|
2894
|
+
}
|
|
2895
|
+
});
|
|
2896
|
+
|
|
2897
|
+
return {
|
|
2898
|
+
header: {
|
|
2899
|
+
unique: response.unique,
|
|
2900
|
+
error: 0n,
|
|
2901
|
+
},
|
|
2902
|
+
payload,
|
|
2903
|
+
};
|
|
2904
|
+
};
|
|
2905
|
+
|
|
2906
|
+
const encodeFallocateResponse = (
|
|
2907
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "FALLOCATE", errorCode: undefined }> }*/
|
|
2908
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2909
|
+
return encodeEmptyPayload({ unique: response.unique });
|
|
2910
|
+
};
|
|
2911
|
+
|
|
2912
|
+
const encodeReadDirPlusResponse = (
|
|
2913
|
+
{ response }/*: { response: Extract<TFuseResponse, { forOpcode: "READDIRPLUS", errorCode: undefined }> }*/
|
|
2914
|
+
)/*: TParsedMessageToKernel*/ => {
|
|
2915
|
+
return {
|
|
2916
|
+
header: {
|
|
2917
|
+
unique: response.unique,
|
|
2918
|
+
error: 0n,
|
|
2919
|
+
},
|
|
2920
|
+
payload: response.result.data,
|
|
2921
|
+
};
|
|
2922
|
+
};
|
|
2923
|
+
|
|
2924
|
+
const encodeMessageToKernel = ({ response }/*: { response: TFuseResponse }*/)/*: TParsedMessageToKernel*/ => {
|
|
2925
|
+
|
|
2926
|
+
if (response.errorCode !== undefined) {
|
|
2927
|
+
|
|
2928
|
+
if (response.errorCode > 0) {
|
|
2929
|
+
throw Error(`fuse expects error codes to be negative numbers. Got ${response.errorCode}`);
|
|
2930
|
+
}
|
|
2931
|
+
|
|
2932
|
+
return {
|
|
2933
|
+
header: {
|
|
2934
|
+
unique: response.unique,
|
|
2935
|
+
error: BigInt(response.errorCode),
|
|
2936
|
+
},
|
|
2937
|
+
payload: new Uint8Array(0),
|
|
2938
|
+
};
|
|
2939
|
+
}
|
|
2940
|
+
|
|
2941
|
+
switch (response.forOpcode) {
|
|
2942
|
+
case "INIT": {
|
|
2943
|
+
return encodeInitResponse({ response });
|
|
2944
|
+
}
|
|
2945
|
+
|
|
2946
|
+
case "GETATTR": {
|
|
2947
|
+
return encodeGetAttrResponse({ response });
|
|
2948
|
+
}
|
|
2949
|
+
|
|
2950
|
+
case "SETATTR": {
|
|
2951
|
+
return encodeSetAttrResponse({ response });
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
case "LISTXATTR": {
|
|
2955
|
+
return encodeListXAttrResponse({ response });
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2958
|
+
case "GETXATTR": {
|
|
2959
|
+
return encodeGetXAttrResponse({ response });
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2962
|
+
case "READLINK": {
|
|
2963
|
+
return encodeReadLinkResponse({ response });
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
case "MKNOD": {
|
|
2967
|
+
return encodeMknodResponse({ response });
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
case "OPENDIR": {
|
|
2971
|
+
return encodeOpenDirResponse({ response });
|
|
2972
|
+
}
|
|
2973
|
+
|
|
2974
|
+
case "READDIR": {
|
|
2975
|
+
return encodeReadDirResponse({ response });
|
|
2976
|
+
}
|
|
2977
|
+
|
|
2978
|
+
case "RELEASEDIR": {
|
|
2979
|
+
return encodeReleaseDirResponse({ response });
|
|
2980
|
+
}
|
|
2981
|
+
|
|
2982
|
+
case "FSYNCDIR": {
|
|
2983
|
+
return encodeFsyncDirResponse({ response });
|
|
2984
|
+
}
|
|
2985
|
+
|
|
2986
|
+
case "RELEASE": {
|
|
2987
|
+
return encodeReleaseResponse({ response });
|
|
2988
|
+
}
|
|
2989
|
+
|
|
2990
|
+
case "STATFS": {
|
|
2991
|
+
return encodeStatFsResponse({ response });
|
|
2992
|
+
}
|
|
2993
|
+
|
|
2994
|
+
case "LOOKUP": {
|
|
2995
|
+
return encodeLookupResponse({ response });
|
|
2996
|
+
}
|
|
2997
|
+
|
|
2998
|
+
case "SYMLINK": {
|
|
2999
|
+
return encodeSymlinkResponse({ response });
|
|
3000
|
+
}
|
|
3001
|
+
|
|
3002
|
+
case "MKDIR": {
|
|
3003
|
+
return encodeMkdirResponse({ response });
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
case "LINK": {
|
|
3007
|
+
return encodeLinkResponse({ response });
|
|
3008
|
+
}
|
|
3009
|
+
|
|
3010
|
+
case "UNLINK": {
|
|
3011
|
+
return encodeUnlinkResponse({ response });
|
|
3012
|
+
}
|
|
3013
|
+
|
|
3014
|
+
case "RMDIR": {
|
|
3015
|
+
return encodeRmDirResponse({ response });
|
|
3016
|
+
}
|
|
3017
|
+
|
|
3018
|
+
case "RENAME": {
|
|
3019
|
+
return encodeRenameResponse({ response });
|
|
3020
|
+
}
|
|
3021
|
+
|
|
3022
|
+
case "OPEN": {
|
|
3023
|
+
return encodeOpenResponse({ response });
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
case "READ": {
|
|
3027
|
+
return encodeReadResponse({ response });
|
|
3028
|
+
}
|
|
3029
|
+
|
|
3030
|
+
case "WRITE": {
|
|
3031
|
+
return encodeWriteResponse({ response });
|
|
3032
|
+
}
|
|
3033
|
+
|
|
3034
|
+
case "FLUSH": {
|
|
3035
|
+
return encodeFlushResponse({ response });
|
|
3036
|
+
}
|
|
3037
|
+
|
|
3038
|
+
case "FSYNC": {
|
|
3039
|
+
return encodeFsyncResponse({ response });
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
case "ACCESS": {
|
|
3043
|
+
return encodeAccessResponse({ response });
|
|
3044
|
+
}
|
|
3045
|
+
|
|
3046
|
+
case "SETXATTR": {
|
|
3047
|
+
return encodeSetXAttrResponse({ response });
|
|
3048
|
+
}
|
|
3049
|
+
|
|
3050
|
+
case "REMOVEXATTR": {
|
|
3051
|
+
return encodeRemoveXAttrResponse({ response });
|
|
3052
|
+
}
|
|
3053
|
+
|
|
3054
|
+
case "CREATE": {
|
|
3055
|
+
return encodeCreateResponse({ response });
|
|
3056
|
+
}
|
|
3057
|
+
|
|
3058
|
+
case "DESTROY": {
|
|
3059
|
+
return encodeDestroyResponse({ response });
|
|
3060
|
+
}
|
|
3061
|
+
|
|
3062
|
+
case "GETLK": {
|
|
3063
|
+
return encodeGetLkResponse({ response });
|
|
3064
|
+
}
|
|
3065
|
+
|
|
3066
|
+
case "SETLK": {
|
|
3067
|
+
return encodeSetLkResponse({ response });
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3070
|
+
case "SETLKW": {
|
|
3071
|
+
return encodeSetLkWResponse({ response });
|
|
3072
|
+
}
|
|
3073
|
+
|
|
3074
|
+
case "BMAP": {
|
|
3075
|
+
return encodeBmapResponse({ response });
|
|
3076
|
+
}
|
|
3077
|
+
|
|
3078
|
+
case "IOCTL": {
|
|
3079
|
+
return encodeIoctlResponse({ response });
|
|
3080
|
+
}
|
|
3081
|
+
|
|
3082
|
+
case "POLL": {
|
|
3083
|
+
return encodePollResponse({ response });
|
|
3084
|
+
}
|
|
3085
|
+
|
|
3086
|
+
case "FALLOCATE": {
|
|
3087
|
+
return encodeFallocateResponse({ response });
|
|
3088
|
+
}
|
|
3089
|
+
|
|
3090
|
+
case "READDIRPLUS": {
|
|
3091
|
+
return encodeReadDirPlusResponse({ response });
|
|
3092
|
+
}
|
|
3093
|
+
|
|
3094
|
+
default: {
|
|
3095
|
+
// @ts-expect-error exhaustiveness check
|
|
3096
|
+
throw Error(`Unsupported opcode: ${response.forOpcode}`);
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
};
|
|
3100
|
+
|
|
3101
|
+
const interpretInitResponse/*: TInterpretFunc<"INIT">*/ = ({ unique, payload }) => {
|
|
3102
|
+
if (payload.length !== fuseInitOutParser.size) {
|
|
3103
|
+
return {
|
|
3104
|
+
error: Error(`Invalid payload size for INIT response. Expected ${fuseInitOutParser.size} bytes, got ${payload.length} bytes.`),
|
|
3105
|
+
interpreted: undefined,
|
|
3106
|
+
};
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
const initResult = fuseInitOutParser.parse({ data: payload });
|
|
3110
|
+
|
|
3111
|
+
return {
|
|
3112
|
+
error: undefined,
|
|
3113
|
+
interpreted: {
|
|
3114
|
+
forOpcode: "INIT",
|
|
3115
|
+
unique,
|
|
3116
|
+
errorCode: undefined,
|
|
3117
|
+
result: {
|
|
3118
|
+
major: initResult.major,
|
|
3119
|
+
minor: initResult.minor,
|
|
3120
|
+
maxReadahead: initResult.max_readahead,
|
|
3121
|
+
flags: initResult.flags,
|
|
3122
|
+
maxBackground: initResult.max_background,
|
|
3123
|
+
congestionThreshold: initResult.congestion_threshold,
|
|
3124
|
+
maxWrite: initResult.max_write,
|
|
3125
|
+
timeGran: initResult.time_gran,
|
|
3126
|
+
maxPages: initResult.max_pages,
|
|
3127
|
+
mapAlignment: initResult.map_alignment,
|
|
3128
|
+
flags2: initResult.flags2,
|
|
3129
|
+
maxStackDepth: initResult.max_stack_depth,
|
|
3130
|
+
requestTimeout: initResult.request_timeout,
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3133
|
+
};
|
|
3134
|
+
};
|
|
3135
|
+
|
|
3136
|
+
const interpretGetAttrResponse/*: TInterpretFunc<"GETATTR">*/ = ({ unique, payload }) => {
|
|
3137
|
+
return interpretAttrPayload({ unique, forOpcode: "GETATTR", payload });
|
|
3138
|
+
};
|
|
3139
|
+
|
|
3140
|
+
const interpretSetAttrResponse/*: TInterpretFunc<"SETATTR">*/ = ({ unique, payload }) => {
|
|
3141
|
+
return interpretAttrPayload({ unique, forOpcode: "SETATTR", payload });
|
|
3142
|
+
};
|
|
3143
|
+
|
|
3144
|
+
const interpretOpenDirResponse/*: TInterpretFunc<"OPENDIR">*/ = ({ unique, payload }) => {
|
|
3145
|
+
return interpretOpenPayload({ unique, forOpcode: "OPENDIR", payload });
|
|
3146
|
+
};
|
|
3147
|
+
|
|
3148
|
+
const interpretReadDirResponse/*: TInterpretFunc<"READDIR">*/ = ({ unique, payload }) => {
|
|
3149
|
+
return {
|
|
3150
|
+
error: undefined,
|
|
3151
|
+
interpreted: {
|
|
3152
|
+
forOpcode: "READDIR",
|
|
3153
|
+
unique,
|
|
3154
|
+
errorCode: undefined,
|
|
3155
|
+
result: {
|
|
3156
|
+
data: payload,
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
};
|
|
3160
|
+
};
|
|
3161
|
+
|
|
3162
|
+
const interpretReleaseDirResponse/*: TInterpretFunc<"RELEASEDIR">*/ = ({ unique }) => {
|
|
3163
|
+
return interpretEmptyPayload({ unique, forOpcode: "RELEASEDIR" });
|
|
3164
|
+
};
|
|
3165
|
+
|
|
3166
|
+
const interpretReleaseResponse/*: TInterpretFunc<"RELEASE">*/ = ({ unique }) => {
|
|
3167
|
+
return interpretEmptyPayload({ unique, forOpcode: "RELEASE" });
|
|
3168
|
+
};
|
|
3169
|
+
|
|
3170
|
+
const interpretLookupResponse/*: TInterpretFunc<"LOOKUP">*/ = ({ unique, payload }) => {
|
|
3171
|
+
return interpretEntryPayload({ unique, forOpcode: "LOOKUP", payload });
|
|
3172
|
+
};
|
|
3173
|
+
|
|
3174
|
+
const interpretSymlinkResponse/*: TInterpretFunc<"SYMLINK">*/ = ({ unique, payload }) => {
|
|
3175
|
+
return interpretEntryPayload({ unique, forOpcode: "SYMLINK", payload });
|
|
3176
|
+
};
|
|
3177
|
+
|
|
3178
|
+
const interpretMknodResponse/*: TInterpretFunc<"MKNOD">*/ = ({ unique, payload }) => {
|
|
3179
|
+
return interpretEntryPayload({ unique, forOpcode: "MKNOD", payload });
|
|
3180
|
+
};
|
|
3181
|
+
|
|
3182
|
+
const interpretMkdirResponse/*: TInterpretFunc<"MKDIR">*/ = ({ unique, payload }) => {
|
|
3183
|
+
return interpretEntryPayload({ unique, forOpcode: "MKDIR", payload });
|
|
3184
|
+
};
|
|
3185
|
+
|
|
3186
|
+
const interpretLinkResponse/*: TInterpretFunc<"LINK">*/ = ({ unique, payload }) => {
|
|
3187
|
+
return interpretEntryPayload({ unique, forOpcode: "LINK", payload });
|
|
3188
|
+
};
|
|
3189
|
+
|
|
3190
|
+
const interpretOpenResponse/*: TInterpretFunc<"OPEN">*/ = ({ unique, payload }) => {
|
|
3191
|
+
return interpretOpenPayload({ unique, forOpcode: "OPEN", payload });
|
|
3192
|
+
};
|
|
3193
|
+
|
|
3194
|
+
const interpretReadResponse/*: TInterpretFunc<"READ">*/ = ({ unique, payload }) => {
|
|
3195
|
+
return {
|
|
3196
|
+
error: undefined,
|
|
3197
|
+
interpreted: {
|
|
3198
|
+
forOpcode: "READ",
|
|
3199
|
+
unique,
|
|
3200
|
+
errorCode: undefined,
|
|
3201
|
+
result: {
|
|
3202
|
+
data: payload,
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
};
|
|
3206
|
+
};
|
|
3207
|
+
|
|
3208
|
+
const interpretWriteResponse/*: TInterpretFunc<"WRITE">*/ = ({ unique, payload }) => {
|
|
3209
|
+
if (payload.length !== fuseWriteOutParser.size) {
|
|
3210
|
+
return {
|
|
3211
|
+
error: Error(
|
|
3212
|
+
`Invalid payload size for WRITE response. Expected ${fuseWriteOutParser.size} bytes, got ${payload.length} bytes.`
|
|
3213
|
+
),
|
|
3214
|
+
interpreted: undefined,
|
|
3215
|
+
};
|
|
3216
|
+
}
|
|
3217
|
+
|
|
3218
|
+
const writeResult = fuseWriteOutParser.parse({ data: payload });
|
|
3219
|
+
|
|
3220
|
+
return {
|
|
3221
|
+
error: undefined,
|
|
3222
|
+
interpreted: {
|
|
3223
|
+
forOpcode: "WRITE",
|
|
3224
|
+
unique,
|
|
3225
|
+
errorCode: undefined,
|
|
3226
|
+
result: {
|
|
3227
|
+
bytesWritten: writeResult.size,
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
};
|
|
3231
|
+
};
|
|
3232
|
+
|
|
3233
|
+
const interpretGetXAttrResponse = (
|
|
3234
|
+
{ unique, payload, request }/*:
|
|
3235
|
+
{ unique: bigint; payload: Uint8Array; request: Extract<TFuseRequest, { opcode: "GETXATTR" }> }*/
|
|
3236
|
+
)/*: TGenericInterpretResult<Extract<TFuseResponse, { forOpcode: "GETXATTR" }>>*/ => {
|
|
3237
|
+
return interpretXAttrPayload({ unique, forOpcode: "GETXATTR", payload, requestedSize: request.size });
|
|
3238
|
+
};
|
|
3239
|
+
|
|
3240
|
+
const interpretListXAttrResponse = (
|
|
3241
|
+
{ unique, payload, request }/*:
|
|
3242
|
+
{ unique: bigint; payload: Uint8Array; request: Extract<TFuseRequest, { opcode: "LISTXATTR" }> }*/
|
|
3243
|
+
)/*: TGenericInterpretResult<Extract<TFuseResponse, { forOpcode: "LISTXATTR" }>>*/ => {
|
|
3244
|
+
return interpretXAttrPayload({ unique, forOpcode: "LISTXATTR", payload, requestedSize: request.size });
|
|
3245
|
+
};
|
|
3246
|
+
|
|
3247
|
+
const interpretReadLinkResponse/*: TInterpretFunc<"READLINK">*/ = ({ unique, payload }) => {
|
|
3248
|
+
return {
|
|
3249
|
+
error: undefined,
|
|
3250
|
+
interpreted: {
|
|
3251
|
+
forOpcode: "READLINK",
|
|
3252
|
+
unique,
|
|
3253
|
+
errorCode: undefined,
|
|
3254
|
+
result: {
|
|
3255
|
+
target: new TextDecoder().decode(payload),
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
};
|
|
3259
|
+
};
|
|
3260
|
+
|
|
3261
|
+
const interpretUnlinkResponse/*: TInterpretFunc<"UNLINK">*/ = ({ unique }) => {
|
|
3262
|
+
return interpretEmptyPayload({ unique, forOpcode: "UNLINK" });
|
|
3263
|
+
};
|
|
3264
|
+
|
|
3265
|
+
const interpretRmDirResponse/*: TInterpretFunc<"RMDIR">*/ = ({ unique }) => {
|
|
3266
|
+
return interpretEmptyPayload({ unique, forOpcode: "RMDIR" });
|
|
3267
|
+
};
|
|
3268
|
+
|
|
3269
|
+
const interpretRenameResponse/*: TInterpretFunc<"RENAME">*/ = ({ unique }) => {
|
|
3270
|
+
return interpretEmptyPayload({ unique, forOpcode: "RENAME" });
|
|
3271
|
+
};
|
|
3272
|
+
|
|
3273
|
+
const interpretFlushResponse/*: TInterpretFunc<"FLUSH">*/ = ({ unique }) => {
|
|
3274
|
+
return interpretEmptyPayload({ unique, forOpcode: "FLUSH" });
|
|
3275
|
+
};
|
|
3276
|
+
|
|
3277
|
+
const interpretFsyncResponse/*: TInterpretFunc<"FSYNC">*/ = ({ unique }) => {
|
|
3278
|
+
return interpretEmptyPayload({ unique, forOpcode: "FSYNC" });
|
|
3279
|
+
};
|
|
3280
|
+
|
|
3281
|
+
const interpretAccessResponse/*: TInterpretFunc<"ACCESS">*/ = ({ unique }) => {
|
|
3282
|
+
return interpretEmptyPayload({ unique, forOpcode: "ACCESS" });
|
|
3283
|
+
};
|
|
3284
|
+
|
|
3285
|
+
const interpretSetXAttrResponse/*: TInterpretFunc<"SETXATTR">*/ = ({ unique }) => {
|
|
3286
|
+
return interpretEmptyPayload({ unique, forOpcode: "SETXATTR" });
|
|
3287
|
+
};
|
|
3288
|
+
|
|
3289
|
+
const interpretRemoveXAttrResponse/*: TInterpretFunc<"REMOVEXATTR">*/ = ({ unique }) => {
|
|
3290
|
+
return interpretEmptyPayload({ unique, forOpcode: "REMOVEXATTR" });
|
|
3291
|
+
};
|
|
3292
|
+
|
|
3293
|
+
const interpretFsyncDirResponse/*: TInterpretFunc<"FSYNCDIR">*/ = ({ unique }) => {
|
|
3294
|
+
return interpretEmptyPayload({ unique, forOpcode: "FSYNCDIR" });
|
|
3295
|
+
};
|
|
3296
|
+
|
|
3297
|
+
const interpretCreateResponse/*: TInterpretFunc<"CREATE">*/ = ({ unique, payload }) => {
|
|
3298
|
+
const expectedSize = fuseEntryOutParser.size + fuseOpenOutParser.size;
|
|
3299
|
+
if (payload.length !== expectedSize) {
|
|
3300
|
+
return {
|
|
3301
|
+
error: Error(`Invalid payload size for CREATE response. Expected ${expectedSize} bytes, got ${payload.length} bytes.`),
|
|
3302
|
+
interpreted: undefined,
|
|
3303
|
+
};
|
|
3304
|
+
}
|
|
3305
|
+
|
|
3306
|
+
const entry = fuseEntryOutParser.parse({ data: payload.subarray(0, fuseEntryOutParser.size) });
|
|
3307
|
+
const open = fuseOpenOutParser.parse({ data: payload.subarray(fuseEntryOutParser.size) });
|
|
3308
|
+
|
|
3309
|
+
return {
|
|
3310
|
+
error: undefined,
|
|
3311
|
+
interpreted: {
|
|
3312
|
+
forOpcode: "CREATE",
|
|
3313
|
+
unique,
|
|
3314
|
+
errorCode: undefined,
|
|
3315
|
+
result: {
|
|
3316
|
+
nodeId: entry.nodeid,
|
|
3317
|
+
generation: entry.generation,
|
|
3318
|
+
entryValidNsec: entry.entry_valid * 1_000_000_000n + entry.entry_valid_nsec,
|
|
3319
|
+
attrValidNsec: entry.attr_valid * 1_000_000_000n + entry.attr_valid_nsec,
|
|
3320
|
+
attr: payloadValueToFuseAttr({ attr: entry.attr }),
|
|
3321
|
+
fh: open.fh,
|
|
3322
|
+
openFlagsToKernel: openFlagsToKernelFromBitmask({ bitmask: open.open_flags }),
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
};
|
|
3326
|
+
};
|
|
3327
|
+
|
|
3328
|
+
const interpretDestroyResponse/*: TInterpretFunc<"DESTROY">*/ = ({ unique }) => {
|
|
3329
|
+
return interpretEmptyPayload({ unique, forOpcode: "DESTROY" });
|
|
3330
|
+
};
|
|
3331
|
+
|
|
3332
|
+
const interpretGetLkResponse/*: TInterpretFunc<"GETLK">*/ = ({ unique, payload }) => {
|
|
3333
|
+
if (payload.length !== fuseLkOutParser.size) {
|
|
3334
|
+
return {
|
|
3335
|
+
error: Error(`Invalid payload size for GETLK response. Expected ${fuseLkOutParser.size} bytes, got ${payload.length} bytes.`),
|
|
3336
|
+
interpreted: undefined,
|
|
3337
|
+
};
|
|
3338
|
+
}
|
|
3339
|
+
|
|
3340
|
+
const parsed = fuseLkOutParser.parse({ data: payload });
|
|
3341
|
+
|
|
3342
|
+
return {
|
|
3343
|
+
error: undefined,
|
|
3344
|
+
interpreted: {
|
|
3345
|
+
forOpcode: "GETLK",
|
|
3346
|
+
unique,
|
|
3347
|
+
errorCode: undefined,
|
|
3348
|
+
result: {
|
|
3349
|
+
lockStart: parsed.lk.start,
|
|
3350
|
+
lockEnd: parsed.lk.end,
|
|
3351
|
+
lockType: parsed.lk.type,
|
|
3352
|
+
lockPid: parsed.lk.pid,
|
|
3353
|
+
}
|
|
3354
|
+
}
|
|
3355
|
+
};
|
|
3356
|
+
};
|
|
3357
|
+
|
|
3358
|
+
const interpretSetLkResponse/*: TInterpretFunc<"SETLK">*/ = ({ unique }) => {
|
|
3359
|
+
return interpretEmptyPayload({ unique, forOpcode: "SETLK" });
|
|
3360
|
+
};
|
|
3361
|
+
|
|
3362
|
+
const interpretSetLkWResponse/*: TInterpretFunc<"SETLKW">*/ = ({ unique }) => {
|
|
3363
|
+
return interpretEmptyPayload({ unique, forOpcode: "SETLKW" });
|
|
3364
|
+
};
|
|
3365
|
+
|
|
3366
|
+
const interpretBmapResponse/*: TInterpretFunc<"BMAP">*/ = ({ unique, payload }) => {
|
|
3367
|
+
if (payload.length !== fuseBmapOutParser.size) {
|
|
3368
|
+
return {
|
|
3369
|
+
error: Error(`Invalid payload size for BMAP response. Expected ${fuseBmapOutParser.size} bytes, got ${payload.length} bytes.`),
|
|
3370
|
+
interpreted: undefined,
|
|
3371
|
+
};
|
|
3372
|
+
}
|
|
3373
|
+
|
|
3374
|
+
const parsed = fuseBmapOutParser.parse({ data: payload });
|
|
3375
|
+
|
|
3376
|
+
return {
|
|
3377
|
+
error: undefined,
|
|
3378
|
+
interpreted: {
|
|
3379
|
+
forOpcode: "BMAP",
|
|
3380
|
+
unique,
|
|
3381
|
+
errorCode: undefined,
|
|
3382
|
+
result: {
|
|
3383
|
+
block: parsed.block,
|
|
3384
|
+
}
|
|
3385
|
+
}
|
|
3386
|
+
};
|
|
3387
|
+
};
|
|
3388
|
+
|
|
3389
|
+
const interpretIoctlResponse/*: TInterpretFunc<"IOCTL">*/ = ({ unique, payload }) => {
|
|
3390
|
+
if (payload.length < fuseIoctlOutParser.size) {
|
|
3391
|
+
return {
|
|
3392
|
+
error: Error(
|
|
3393
|
+
`Invalid payload size for IOCTL response. Expected at least ${fuseIoctlOutParser.size} bytes, got ${payload.length} bytes.`
|
|
3394
|
+
),
|
|
3395
|
+
interpreted: undefined,
|
|
3396
|
+
};
|
|
3397
|
+
}
|
|
3398
|
+
|
|
3399
|
+
const parsed = fuseIoctlOutParser.parse({ data: payload.subarray(0, fuseIoctlOutParser.size) });
|
|
3400
|
+
|
|
3401
|
+
return {
|
|
3402
|
+
error: undefined,
|
|
3403
|
+
interpreted: {
|
|
3404
|
+
forOpcode: "IOCTL",
|
|
3405
|
+
unique,
|
|
3406
|
+
errorCode: undefined,
|
|
3407
|
+
result: {
|
|
3408
|
+
ioctlResult: parsed.result,
|
|
3409
|
+
flags: parsed.flags,
|
|
3410
|
+
data: payload.subarray(fuseIoctlOutParser.size),
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
};
|
|
3414
|
+
};
|
|
3415
|
+
|
|
3416
|
+
const interpretPollResponse/*: TInterpretFunc<"POLL">*/ = ({ unique, payload }) => {
|
|
3417
|
+
if (payload.length !== fusePollOutParser.size) {
|
|
3418
|
+
return {
|
|
3419
|
+
error: Error(`Invalid payload size for POLL response. Expected ${fusePollOutParser.size} bytes, got ${payload.length} bytes.`),
|
|
3420
|
+
interpreted: undefined,
|
|
3421
|
+
};
|
|
3422
|
+
}
|
|
3423
|
+
|
|
3424
|
+
const parsed = fusePollOutParser.parse({ data: payload });
|
|
3425
|
+
|
|
3426
|
+
return {
|
|
3427
|
+
error: undefined,
|
|
3428
|
+
interpreted: {
|
|
3429
|
+
forOpcode: "POLL",
|
|
3430
|
+
unique,
|
|
3431
|
+
errorCode: undefined,
|
|
3432
|
+
result: {
|
|
3433
|
+
revents: parsed.revents,
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
};
|
|
3437
|
+
};
|
|
3438
|
+
|
|
3439
|
+
const interpretFallocateResponse/*: TInterpretFunc<"FALLOCATE">*/ = ({ unique }) => {
|
|
3440
|
+
return interpretEmptyPayload({ unique, forOpcode: "FALLOCATE" });
|
|
3441
|
+
};
|
|
3442
|
+
|
|
3443
|
+
const interpretReadDirPlusResponse/*: TInterpretFunc<"READDIRPLUS">*/ = ({ unique, payload }) => {
|
|
3444
|
+
return {
|
|
3445
|
+
error: undefined,
|
|
3446
|
+
interpreted: {
|
|
3447
|
+
forOpcode: "READDIRPLUS",
|
|
3448
|
+
unique,
|
|
3449
|
+
errorCode: undefined,
|
|
3450
|
+
result: {
|
|
3451
|
+
data: payload,
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
};
|
|
3455
|
+
};
|
|
3456
|
+
|
|
3457
|
+
const interpretStatFsResponse/*: TInterpretFunc<"STATFS">*/ = ({ unique, payload }) => {
|
|
3458
|
+
if (payload.length !== fuseStatfsOutParser.size) {
|
|
3459
|
+
return {
|
|
3460
|
+
error: Error(
|
|
3461
|
+
`Invalid payload size for STATFS response. Expected ${fuseStatfsOutParser.size} bytes, got ${payload.length} bytes.`
|
|
3462
|
+
),
|
|
3463
|
+
interpreted: undefined,
|
|
3464
|
+
};
|
|
3465
|
+
}
|
|
3466
|
+
|
|
3467
|
+
const statFsResult = fuseStatfsOutParser.parse({ data: payload });
|
|
3468
|
+
|
|
3469
|
+
return {
|
|
3470
|
+
error: undefined,
|
|
3471
|
+
interpreted: {
|
|
3472
|
+
forOpcode: "STATFS",
|
|
3473
|
+
unique,
|
|
3474
|
+
errorCode: undefined,
|
|
3475
|
+
result: {
|
|
3476
|
+
blocks: statFsResult.st.blocks,
|
|
3477
|
+
bfree: statFsResult.st.bfree,
|
|
3478
|
+
bavail: statFsResult.st.bavail,
|
|
3479
|
+
files: statFsResult.st.files,
|
|
3480
|
+
ffree: statFsResult.st.ffree,
|
|
3481
|
+
bsize: statFsResult.st.bsize,
|
|
3482
|
+
namelen: statFsResult.st.namelen,
|
|
3483
|
+
frsize: statFsResult.st.frsize,
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3486
|
+
};
|
|
3487
|
+
};
|
|
3488
|
+
|
|
3489
|
+
const interpretMessageToKernel = (
|
|
3490
|
+
{ request, parsedMessageToKernel }/*: { request: TFuseRequest, parsedMessageToKernel: TParsedMessageToKernel }*/
|
|
3491
|
+
)/*: TGenericInterpretResult<TFuseResponse>*/ => {
|
|
3492
|
+
|
|
3493
|
+
const unique = parsedMessageToKernel.header.unique;
|
|
3494
|
+
const forOpcode = request.opcode /*as TFuseResponse["forOpcode"]*/;
|
|
3495
|
+
|
|
3496
|
+
if (parsedMessageToKernel.header.error !== 0n) {
|
|
3497
|
+
return {
|
|
3498
|
+
error: undefined,
|
|
3499
|
+
interpreted: {
|
|
3500
|
+
forOpcode,
|
|
3501
|
+
unique,
|
|
3502
|
+
errorCode: Number(parsedMessageToKernel.header.error),
|
|
3503
|
+
result: undefined,
|
|
3504
|
+
} /*as Extract<TFuseResponse, { forOpcode: typeof forOpcode; errorCode: number }>*/,
|
|
3505
|
+
};
|
|
3506
|
+
}
|
|
3507
|
+
|
|
3508
|
+
switch (forOpcode) {
|
|
3509
|
+
case "INIT": {
|
|
3510
|
+
return interpretInitResponse({
|
|
3511
|
+
unique,
|
|
3512
|
+
payload: parsedMessageToKernel.payload,
|
|
3513
|
+
});
|
|
3514
|
+
}
|
|
3515
|
+
|
|
3516
|
+
case "GETATTR": {
|
|
3517
|
+
return interpretGetAttrResponse({
|
|
3518
|
+
unique,
|
|
3519
|
+
payload: parsedMessageToKernel.payload,
|
|
3520
|
+
});
|
|
3521
|
+
}
|
|
3522
|
+
|
|
3523
|
+
case "SETATTR": {
|
|
3524
|
+
return interpretSetAttrResponse({
|
|
3525
|
+
unique,
|
|
3526
|
+
payload: parsedMessageToKernel.payload,
|
|
3527
|
+
});
|
|
3528
|
+
}
|
|
3529
|
+
|
|
3530
|
+
case "LISTXATTR": {
|
|
3531
|
+
return interpretListXAttrResponse({
|
|
3532
|
+
unique,
|
|
3533
|
+
payload: parsedMessageToKernel.payload,
|
|
3534
|
+
request: request /*as Extract<TFuseRequest, { opcode: "LISTXATTR" }>*/,
|
|
3535
|
+
});
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3538
|
+
case "GETXATTR": {
|
|
3539
|
+
return interpretGetXAttrResponse({
|
|
3540
|
+
unique,
|
|
3541
|
+
payload: parsedMessageToKernel.payload,
|
|
3542
|
+
request: request /*as Extract<TFuseRequest, { opcode: "GETXATTR" }>*/,
|
|
3543
|
+
});
|
|
3544
|
+
}
|
|
3545
|
+
|
|
3546
|
+
case "READLINK": {
|
|
3547
|
+
return interpretReadLinkResponse({
|
|
3548
|
+
unique,
|
|
3549
|
+
payload: parsedMessageToKernel.payload,
|
|
3550
|
+
});
|
|
3551
|
+
}
|
|
3552
|
+
|
|
3553
|
+
case "MKNOD": {
|
|
3554
|
+
return interpretMknodResponse({
|
|
3555
|
+
unique,
|
|
3556
|
+
payload: parsedMessageToKernel.payload,
|
|
3557
|
+
});
|
|
3558
|
+
}
|
|
3559
|
+
|
|
3560
|
+
case "OPENDIR": {
|
|
3561
|
+
return interpretOpenDirResponse({
|
|
3562
|
+
unique,
|
|
3563
|
+
payload: parsedMessageToKernel.payload,
|
|
3564
|
+
});
|
|
3565
|
+
}
|
|
3566
|
+
|
|
3567
|
+
case "READDIR": {
|
|
3568
|
+
return interpretReadDirResponse({
|
|
3569
|
+
unique,
|
|
3570
|
+
payload: parsedMessageToKernel.payload,
|
|
3571
|
+
});
|
|
3572
|
+
}
|
|
3573
|
+
|
|
3574
|
+
case "RELEASEDIR": {
|
|
3575
|
+
return interpretReleaseDirResponse({
|
|
3576
|
+
unique,
|
|
3577
|
+
payload: parsedMessageToKernel.payload,
|
|
3578
|
+
});
|
|
3579
|
+
}
|
|
3580
|
+
|
|
3581
|
+
case "FSYNCDIR": {
|
|
3582
|
+
return interpretFsyncDirResponse({
|
|
3583
|
+
unique,
|
|
3584
|
+
payload: parsedMessageToKernel.payload,
|
|
3585
|
+
});
|
|
3586
|
+
}
|
|
3587
|
+
|
|
3588
|
+
case "RELEASE": {
|
|
3589
|
+
return interpretReleaseResponse({
|
|
3590
|
+
unique,
|
|
3591
|
+
payload: parsedMessageToKernel.payload,
|
|
3592
|
+
});
|
|
3593
|
+
}
|
|
3594
|
+
|
|
3595
|
+
case "STATFS": {
|
|
3596
|
+
return interpretStatFsResponse({
|
|
3597
|
+
unique,
|
|
3598
|
+
payload: parsedMessageToKernel.payload,
|
|
3599
|
+
});
|
|
3600
|
+
}
|
|
3601
|
+
|
|
3602
|
+
case "LOOKUP": {
|
|
3603
|
+
return interpretLookupResponse({
|
|
3604
|
+
unique,
|
|
3605
|
+
payload: parsedMessageToKernel.payload,
|
|
3606
|
+
});
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3609
|
+
case "SYMLINK": {
|
|
3610
|
+
return interpretSymlinkResponse({
|
|
3611
|
+
unique,
|
|
3612
|
+
payload: parsedMessageToKernel.payload,
|
|
3613
|
+
});
|
|
3614
|
+
}
|
|
3615
|
+
|
|
3616
|
+
case "LINK": {
|
|
3617
|
+
return interpretLinkResponse({
|
|
3618
|
+
unique,
|
|
3619
|
+
payload: parsedMessageToKernel.payload,
|
|
3620
|
+
});
|
|
3621
|
+
}
|
|
3622
|
+
|
|
3623
|
+
case "MKDIR": {
|
|
3624
|
+
return interpretMkdirResponse({
|
|
3625
|
+
unique,
|
|
3626
|
+
payload: parsedMessageToKernel.payload,
|
|
3627
|
+
});
|
|
3628
|
+
}
|
|
3629
|
+
|
|
3630
|
+
case "UNLINK": {
|
|
3631
|
+
return interpretUnlinkResponse({
|
|
3632
|
+
unique,
|
|
3633
|
+
payload: parsedMessageToKernel.payload,
|
|
3634
|
+
});
|
|
3635
|
+
}
|
|
3636
|
+
|
|
3637
|
+
case "RMDIR": {
|
|
3638
|
+
return interpretRmDirResponse({
|
|
3639
|
+
unique,
|
|
3640
|
+
payload: parsedMessageToKernel.payload,
|
|
3641
|
+
});
|
|
3642
|
+
}
|
|
3643
|
+
|
|
3644
|
+
case "RENAME": {
|
|
3645
|
+
return interpretRenameResponse({
|
|
3646
|
+
unique,
|
|
3647
|
+
payload: parsedMessageToKernel.payload,
|
|
3648
|
+
});
|
|
3649
|
+
}
|
|
3650
|
+
|
|
3651
|
+
case "OPEN": {
|
|
3652
|
+
return interpretOpenResponse({
|
|
3653
|
+
unique,
|
|
3654
|
+
payload: parsedMessageToKernel.payload,
|
|
3655
|
+
});
|
|
3656
|
+
}
|
|
3657
|
+
|
|
3658
|
+
case "READ": {
|
|
3659
|
+
return interpretReadResponse({
|
|
3660
|
+
unique,
|
|
3661
|
+
payload: parsedMessageToKernel.payload,
|
|
3662
|
+
});
|
|
3663
|
+
}
|
|
3664
|
+
|
|
3665
|
+
case "WRITE": {
|
|
3666
|
+
return interpretWriteResponse({
|
|
3667
|
+
unique,
|
|
3668
|
+
payload: parsedMessageToKernel.payload,
|
|
3669
|
+
});
|
|
3670
|
+
}
|
|
3671
|
+
|
|
3672
|
+
case "FLUSH": {
|
|
3673
|
+
return interpretFlushResponse({
|
|
3674
|
+
unique,
|
|
3675
|
+
payload: parsedMessageToKernel.payload,
|
|
3676
|
+
});
|
|
3677
|
+
}
|
|
3678
|
+
|
|
3679
|
+
case "FSYNC": {
|
|
3680
|
+
return interpretFsyncResponse({
|
|
3681
|
+
unique,
|
|
3682
|
+
payload: parsedMessageToKernel.payload,
|
|
3683
|
+
});
|
|
3684
|
+
}
|
|
3685
|
+
|
|
3686
|
+
case "ACCESS": {
|
|
3687
|
+
return interpretAccessResponse({
|
|
3688
|
+
unique,
|
|
3689
|
+
payload: parsedMessageToKernel.payload,
|
|
3690
|
+
});
|
|
3691
|
+
}
|
|
3692
|
+
|
|
3693
|
+
case "SETXATTR": {
|
|
3694
|
+
return interpretSetXAttrResponse({
|
|
3695
|
+
unique,
|
|
3696
|
+
payload: parsedMessageToKernel.payload,
|
|
3697
|
+
});
|
|
3698
|
+
}
|
|
3699
|
+
|
|
3700
|
+
case "REMOVEXATTR": {
|
|
3701
|
+
return interpretRemoveXAttrResponse({
|
|
3702
|
+
unique,
|
|
3703
|
+
payload: parsedMessageToKernel.payload,
|
|
3704
|
+
});
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3707
|
+
case "CREATE": {
|
|
3708
|
+
return interpretCreateResponse({
|
|
3709
|
+
unique,
|
|
3710
|
+
payload: parsedMessageToKernel.payload,
|
|
3711
|
+
});
|
|
3712
|
+
}
|
|
3713
|
+
|
|
3714
|
+
case "DESTROY": {
|
|
3715
|
+
return interpretDestroyResponse({
|
|
3716
|
+
unique,
|
|
3717
|
+
payload: parsedMessageToKernel.payload,
|
|
3718
|
+
});
|
|
3719
|
+
}
|
|
3720
|
+
|
|
3721
|
+
case "GETLK": {
|
|
3722
|
+
return interpretGetLkResponse({
|
|
3723
|
+
unique,
|
|
3724
|
+
payload: parsedMessageToKernel.payload,
|
|
3725
|
+
});
|
|
3726
|
+
}
|
|
3727
|
+
|
|
3728
|
+
case "SETLK": {
|
|
3729
|
+
return interpretSetLkResponse({
|
|
3730
|
+
unique,
|
|
3731
|
+
payload: parsedMessageToKernel.payload,
|
|
3732
|
+
});
|
|
3733
|
+
}
|
|
3734
|
+
|
|
3735
|
+
case "SETLKW": {
|
|
3736
|
+
return interpretSetLkWResponse({
|
|
3737
|
+
unique,
|
|
3738
|
+
payload: parsedMessageToKernel.payload,
|
|
3739
|
+
});
|
|
3740
|
+
}
|
|
3741
|
+
|
|
3742
|
+
case "BMAP": {
|
|
3743
|
+
return interpretBmapResponse({
|
|
3744
|
+
unique,
|
|
3745
|
+
payload: parsedMessageToKernel.payload,
|
|
3746
|
+
});
|
|
3747
|
+
}
|
|
3748
|
+
|
|
3749
|
+
case "IOCTL": {
|
|
3750
|
+
return interpretIoctlResponse({
|
|
3751
|
+
unique,
|
|
3752
|
+
payload: parsedMessageToKernel.payload,
|
|
3753
|
+
});
|
|
3754
|
+
}
|
|
3755
|
+
|
|
3756
|
+
case "POLL": {
|
|
3757
|
+
return interpretPollResponse({
|
|
3758
|
+
unique,
|
|
3759
|
+
payload: parsedMessageToKernel.payload,
|
|
3760
|
+
});
|
|
3761
|
+
}
|
|
3762
|
+
|
|
3763
|
+
case "FALLOCATE": {
|
|
3764
|
+
return interpretFallocateResponse({
|
|
3765
|
+
unique,
|
|
3766
|
+
payload: parsedMessageToKernel.payload,
|
|
3767
|
+
});
|
|
3768
|
+
}
|
|
3769
|
+
|
|
3770
|
+
case "READDIRPLUS": {
|
|
3771
|
+
return interpretReadDirPlusResponse({
|
|
3772
|
+
unique,
|
|
3773
|
+
payload: parsedMessageToKernel.payload,
|
|
3774
|
+
});
|
|
3775
|
+
}
|
|
3776
|
+
|
|
3777
|
+
default: {
|
|
3778
|
+
throw Error(`unsupported opcode for interpretation: ${forOpcode}`);
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3781
|
+
};
|
|
3782
|
+
|
|
3783
|
+
return {
|
|
3784
|
+
encodeMessageToKernel,
|
|
3785
|
+
interpretMessageToKernel,
|
|
3786
|
+
};
|
|
3787
|
+
};
|
|
3788
|
+
|
|
3789
|
+
export {
|
|
3790
|
+
createMessageFromKernelInterpreter,
|
|
3791
|
+
createMessageToKernelInterpreter,
|
|
3792
|
+
};
|
|
3793
|
+
|
|
3794
|
+
/*export type {
|
|
3795
|
+
TFuseRequest,
|
|
3796
|
+
TFuseResponse,
|
|
3797
|
+
};*/
|