@zenfs/core 1.11.4 → 2.1.0
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/backends/backend.d.ts +19 -15
- package/dist/backends/backend.js +36 -19
- package/dist/backends/cow.d.ts +20 -30
- package/dist/backends/cow.js +83 -192
- package/dist/backends/fetch.d.ts +1 -0
- package/dist/backends/fetch.js +30 -30
- package/dist/backends/index.d.ts +1 -1
- package/dist/backends/index.js +1 -1
- package/dist/backends/memory.d.ts +5 -7
- package/dist/backends/memory.js +2 -3
- package/dist/backends/passthrough.d.ts +19 -23
- package/dist/backends/passthrough.js +98 -288
- package/dist/backends/port.d.ts +220 -0
- package/dist/backends/port.js +328 -0
- package/dist/backends/single_buffer.d.ts +59 -47
- package/dist/backends/single_buffer.js +468 -219
- package/dist/backends/store/fs.d.ts +25 -35
- package/dist/backends/store/fs.js +276 -315
- package/dist/backends/store/store.d.ts +10 -15
- package/dist/backends/store/store.js +11 -10
- package/dist/config.d.ts +3 -12
- package/dist/config.js +17 -19
- package/dist/context.d.ts +8 -21
- package/dist/context.js +33 -10
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/internal/contexts.d.ts +63 -0
- package/dist/internal/contexts.js +15 -0
- package/dist/internal/credentials.d.ts +2 -11
- package/dist/internal/credentials.js +0 -19
- package/dist/internal/devices.d.ts +18 -80
- package/dist/internal/devices.js +103 -316
- package/dist/internal/error.d.ts +9 -204
- package/dist/internal/error.js +19 -288
- package/dist/internal/file_index.d.ts +1 -1
- package/dist/internal/file_index.js +11 -11
- package/dist/internal/filesystem.d.ts +51 -94
- package/dist/internal/filesystem.js +21 -20
- package/dist/internal/index.d.ts +1 -2
- package/dist/internal/index.js +1 -2
- package/dist/internal/index_fs.d.ts +12 -30
- package/dist/internal/index_fs.js +37 -69
- package/dist/internal/inode.d.ts +140 -24
- package/dist/internal/inode.js +515 -66
- package/dist/mixins/async.js +52 -112
- package/dist/mixins/mutexed.d.ts +19 -18
- package/dist/mixins/mutexed.js +62 -64
- package/dist/mixins/readonly.d.ts +7 -6
- package/dist/mixins/readonly.js +24 -18
- package/dist/mixins/sync.js +8 -8
- package/dist/{vfs/path.d.ts → path.d.ts} +3 -4
- package/dist/{vfs/path.js → path.js} +6 -9
- package/dist/polyfills.js +1 -1
- package/dist/readline.d.ts +134 -0
- package/dist/readline.js +623 -0
- package/dist/utils.d.ts +9 -37
- package/dist/utils.js +17 -85
- package/dist/vfs/acl.d.ts +42 -0
- package/dist/vfs/acl.js +268 -0
- package/dist/vfs/async.d.ts +9 -23
- package/dist/vfs/async.js +25 -27
- package/dist/vfs/config.d.ts +6 -18
- package/dist/vfs/config.js +8 -18
- package/dist/vfs/dir.d.ts +3 -3
- package/dist/vfs/dir.js +12 -12
- package/dist/vfs/file.d.ts +106 -0
- package/dist/vfs/file.js +244 -0
- package/dist/vfs/flags.d.ts +19 -0
- package/dist/vfs/flags.js +62 -0
- package/dist/vfs/index.d.ts +4 -10
- package/dist/vfs/index.js +4 -13
- package/dist/vfs/ioctl.d.ts +88 -0
- package/dist/vfs/ioctl.js +409 -0
- package/dist/vfs/promises.d.ts +81 -19
- package/dist/vfs/promises.js +404 -288
- package/dist/vfs/shared.d.ts +7 -37
- package/dist/vfs/shared.js +29 -85
- package/dist/{stats.d.ts → vfs/stats.d.ts} +14 -28
- package/dist/{stats.js → vfs/stats.js} +11 -66
- package/dist/vfs/streams.d.ts +1 -0
- package/dist/vfs/streams.js +32 -27
- package/dist/vfs/sync.d.ts +3 -3
- package/dist/vfs/sync.js +263 -260
- package/dist/vfs/watchers.d.ts +2 -2
- package/dist/vfs/watchers.js +12 -12
- package/dist/vfs/xattr.d.ts +116 -0
- package/dist/vfs/xattr.js +201 -0
- package/package.json +5 -3
- package/readme.md +1 -1
- package/scripts/test.js +2 -2
- package/tests/assignment.ts +1 -1
- package/tests/backend/config.worker.js +4 -1
- package/tests/backend/fetch.test.ts +3 -0
- package/tests/backend/port.test.ts +19 -33
- package/tests/backend/remote.worker.js +4 -1
- package/tests/backend/single-buffer.test.ts +53 -0
- package/tests/backend/single-buffer.worker.js +30 -0
- package/tests/common/context.test.ts +3 -3
- package/tests/common/handle.test.ts +17 -12
- package/tests/common/mutex.test.ts +9 -9
- package/tests/common/path.test.ts +1 -1
- package/tests/common/readline.test.ts +104 -0
- package/tests/common.ts +4 -19
- package/tests/fetch/fetch.ts +2 -2
- package/tests/fs/append.test.ts +4 -4
- package/tests/fs/directory.test.ts +25 -25
- package/tests/fs/errors.test.ts +15 -19
- package/tests/fs/links.test.ts +4 -3
- package/tests/fs/open.test.ts +4 -21
- package/tests/fs/permissions.test.ts +14 -18
- package/tests/fs/read.test.ts +10 -9
- package/tests/fs/readFile.test.ts +10 -26
- package/tests/fs/rename.test.ts +4 -9
- package/tests/fs/stat.test.ts +8 -8
- package/tests/fs/streams.test.ts +2 -11
- package/tests/fs/times.test.ts +7 -7
- package/tests/fs/truncate.test.ts +8 -36
- package/tests/fs/watch.test.ts +10 -10
- package/tests/fs/write.test.ts +77 -13
- package/tests/fs/xattr.test.ts +85 -0
- package/tests/logs.js +22 -0
- package/tests/setup/context.ts +1 -1
- package/tests/setup/index.ts +3 -3
- package/tests/setup/port.ts +7 -1
- package/dist/backends/port/fs.d.ts +0 -84
- package/dist/backends/port/fs.js +0 -151
- package/dist/backends/port/rpc.d.ts +0 -77
- package/dist/backends/port/rpc.js +0 -100
- package/dist/backends/store/simple.d.ts +0 -20
- package/dist/backends/store/simple.js +0 -13
- package/dist/internal/file.d.ts +0 -359
- package/dist/internal/file.js +0 -751
- package/dist/internal/log.d.ts +0 -133
- package/dist/internal/log.js +0 -218
- package/tests/fs/writeFile.test.ts +0 -70
package/dist/internal/devices.js
CHANGED
|
@@ -1,203 +1,22 @@
|
|
|
1
1
|
/*
|
|
2
2
|
This is a great resource: https://www.kernel.org/doc/html/latest/admin-guide/devices.html
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var dispose, inner;
|
|
8
|
-
if (async) {
|
|
9
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
10
|
-
dispose = value[Symbol.asyncDispose];
|
|
11
|
-
}
|
|
12
|
-
if (dispose === void 0) {
|
|
13
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
14
|
-
dispose = value[Symbol.dispose];
|
|
15
|
-
if (async) inner = dispose;
|
|
16
|
-
}
|
|
17
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
18
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
19
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
20
|
-
}
|
|
21
|
-
else if (async) {
|
|
22
|
-
env.stack.push({ async: true });
|
|
23
|
-
}
|
|
24
|
-
return value;
|
|
25
|
-
};
|
|
26
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
27
|
-
return function (env) {
|
|
28
|
-
function fail(e) {
|
|
29
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
30
|
-
env.hasError = true;
|
|
31
|
-
}
|
|
32
|
-
var r, s = 0;
|
|
33
|
-
function next() {
|
|
34
|
-
while (r = env.stack.pop()) {
|
|
35
|
-
try {
|
|
36
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
37
|
-
if (r.dispose) {
|
|
38
|
-
var result = r.dispose.call(r.value);
|
|
39
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
40
|
-
}
|
|
41
|
-
else s |= 1;
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
fail(e);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
48
|
-
if (env.hasError) throw env.error;
|
|
49
|
-
}
|
|
50
|
-
return next();
|
|
51
|
-
};
|
|
52
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
53
|
-
var e = new Error(message);
|
|
54
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
55
|
-
});
|
|
56
|
-
import { canary } from 'utilium';
|
|
4
|
+
import { withErrno } from 'kerium';
|
|
5
|
+
import { debug, err, info } from 'kerium/log';
|
|
6
|
+
import { decodeUTF8, omit } from 'utilium';
|
|
57
7
|
import { InMemoryStore } from '../backends/memory.js';
|
|
58
8
|
import { StoreFS } from '../backends/store/fs.js';
|
|
59
|
-
import {
|
|
60
|
-
import {
|
|
61
|
-
import { S_IFBLK, S_IFCHR } from '../vfs/constants.js';
|
|
62
|
-
import { basename, dirname } from '../vfs/path.js';
|
|
63
|
-
import { Errno, ErrnoError } from './error.js';
|
|
64
|
-
import { File } from './file.js';
|
|
9
|
+
import { basename, dirname } from '../path.js';
|
|
10
|
+
import { S_IFCHR } from '../vfs/constants.js';
|
|
65
11
|
import { Inode } from './inode.js';
|
|
66
|
-
import { alert, debug, err, info, log_deprecated } from './log.js';
|
|
67
|
-
/**
|
|
68
|
-
* The base class for device files
|
|
69
|
-
* This class only does some simple things:
|
|
70
|
-
* It implements `truncate` using `write` and it has non-device methods throw.
|
|
71
|
-
* It is up to device drivers to implement the rest of the functionality.
|
|
72
|
-
* @category Internals
|
|
73
|
-
* @internal
|
|
74
|
-
*/
|
|
75
|
-
export class DeviceFile extends File {
|
|
76
|
-
constructor(fs, path, device) {
|
|
77
|
-
super(fs, path);
|
|
78
|
-
this.fs = fs;
|
|
79
|
-
this.device = device;
|
|
80
|
-
this.position = 0;
|
|
81
|
-
this.stats = new Inode({
|
|
82
|
-
mode: (this.driver.isBuffered ? S_IFBLK : S_IFCHR) | 0o666,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
get driver() {
|
|
86
|
-
return this.device.driver;
|
|
87
|
-
}
|
|
88
|
-
async stat() {
|
|
89
|
-
return Promise.resolve(new Stats(this.stats));
|
|
90
|
-
}
|
|
91
|
-
statSync() {
|
|
92
|
-
return new Stats(this.stats);
|
|
93
|
-
}
|
|
94
|
-
readSync(buffer, offset = 0, length = buffer.byteLength - offset, position = this.position) {
|
|
95
|
-
this.stats.atimeMs = Date.now();
|
|
96
|
-
const end = position + length;
|
|
97
|
-
this.position = end;
|
|
98
|
-
const uint8 = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
99
|
-
this.driver.readD(this.device, uint8.subarray(offset, length), position, end);
|
|
100
|
-
return length;
|
|
101
|
-
}
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
103
|
-
async read(buffer, offset, length) {
|
|
104
|
-
return { bytesRead: this.readSync(buffer, offset, length), buffer };
|
|
105
|
-
}
|
|
106
|
-
writeSync(buffer, offset = 0, length = buffer.byteLength - offset, position = this.position) {
|
|
107
|
-
const end = position + length;
|
|
108
|
-
if (end > this.stats.size)
|
|
109
|
-
this.stats.size = end;
|
|
110
|
-
this.stats.mtimeMs = Date.now();
|
|
111
|
-
this.position = end;
|
|
112
|
-
const data = buffer.subarray(offset, offset + length);
|
|
113
|
-
this.driver.writeD(this.device, data, position);
|
|
114
|
-
return length;
|
|
115
|
-
}
|
|
116
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
117
|
-
async write(buffer, offset, length, position) {
|
|
118
|
-
return this.writeSync(buffer, offset, length, position);
|
|
119
|
-
}
|
|
120
|
-
async truncate(length) {
|
|
121
|
-
const { size } = await this.stat();
|
|
122
|
-
const buffer = new Uint8Array(length > size ? length - size : 0);
|
|
123
|
-
await this.write(buffer, 0, buffer.length, length > size ? size : length);
|
|
124
|
-
}
|
|
125
|
-
truncateSync(length) {
|
|
126
|
-
const { size } = this.statSync();
|
|
127
|
-
const buffer = new Uint8Array(length > size ? length - size : 0);
|
|
128
|
-
this.writeSync(buffer, 0, buffer.length, length > size ? size : length);
|
|
129
|
-
}
|
|
130
|
-
closeSync() {
|
|
131
|
-
var _a, _b;
|
|
132
|
-
(_b = (_a = this.driver).close) === null || _b === void 0 ? void 0 : _b.call(_a, this);
|
|
133
|
-
}
|
|
134
|
-
close() {
|
|
135
|
-
this.closeSync();
|
|
136
|
-
return Promise.resolve();
|
|
137
|
-
}
|
|
138
|
-
syncSync() {
|
|
139
|
-
var _a, _b;
|
|
140
|
-
(_b = (_a = this.driver).sync) === null || _b === void 0 ? void 0 : _b.call(_a, this);
|
|
141
|
-
}
|
|
142
|
-
sync() {
|
|
143
|
-
this.syncSync();
|
|
144
|
-
return Promise.resolve();
|
|
145
|
-
}
|
|
146
|
-
chown() {
|
|
147
|
-
throw ErrnoError.With('ENOTSUP', this.path, 'chown');
|
|
148
|
-
}
|
|
149
|
-
chownSync() {
|
|
150
|
-
throw ErrnoError.With('ENOTSUP', this.path, 'chown');
|
|
151
|
-
}
|
|
152
|
-
chmod() {
|
|
153
|
-
throw ErrnoError.With('ENOTSUP', this.path, 'chmod');
|
|
154
|
-
}
|
|
155
|
-
chmodSync() {
|
|
156
|
-
throw ErrnoError.With('ENOTSUP', this.path, 'chmod');
|
|
157
|
-
}
|
|
158
|
-
utimes() {
|
|
159
|
-
throw ErrnoError.With('ENOTSUP', this.path, 'utimes');
|
|
160
|
-
}
|
|
161
|
-
utimesSync() {
|
|
162
|
-
throw ErrnoError.With('ENOTSUP', this.path, 'utimes');
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
12
|
/**
|
|
166
13
|
* A temporary file system that manages and interfaces with devices
|
|
167
14
|
* @category Internals
|
|
168
15
|
*/
|
|
169
16
|
export class DeviceFS extends StoreFS {
|
|
170
|
-
/* node:coverage disable */
|
|
171
|
-
/**
|
|
172
|
-
* Creates a new device at `path` relative to the `DeviceFS` root.
|
|
173
|
-
* @deprecated
|
|
174
|
-
*/
|
|
175
|
-
createDevice(path, driver, options = {}) {
|
|
176
|
-
var _a;
|
|
177
|
-
log_deprecated('DeviceFS#createDevice');
|
|
178
|
-
if (this.existsSync(path)) {
|
|
179
|
-
throw ErrnoError.With('EEXIST', path, 'mknod');
|
|
180
|
-
}
|
|
181
|
-
let ino = 1;
|
|
182
|
-
const silence = canary(ErrnoError.With('EDEADLK', path, 'mknod'));
|
|
183
|
-
while (this.store.has(ino))
|
|
184
|
-
ino++;
|
|
185
|
-
silence();
|
|
186
|
-
const dev = {
|
|
187
|
-
driver,
|
|
188
|
-
ino,
|
|
189
|
-
data: {},
|
|
190
|
-
minor: 0,
|
|
191
|
-
major: 0,
|
|
192
|
-
...(_a = driver.init) === null || _a === void 0 ? void 0 : _a.call(driver, ino, options),
|
|
193
|
-
};
|
|
194
|
-
this.devices.set(path, dev);
|
|
195
|
-
return dev;
|
|
196
|
-
}
|
|
197
|
-
/* node:coverage enable */
|
|
198
17
|
devicesWithDriver(driver, forceIdentity) {
|
|
199
18
|
if (forceIdentity && typeof driver == 'string') {
|
|
200
|
-
throw err(
|
|
19
|
+
throw err(withErrno('EINVAL', 'Can not fetch devices using only a driver name'));
|
|
201
20
|
}
|
|
202
21
|
const devs = [];
|
|
203
22
|
for (const device of this.devices.values()) {
|
|
@@ -215,19 +34,24 @@ export class DeviceFS extends StoreFS {
|
|
|
215
34
|
_createDevice(driver, options = {}) {
|
|
216
35
|
var _a;
|
|
217
36
|
let ino = 1;
|
|
218
|
-
|
|
37
|
+
const lastDev = Array.from(this.devices.values()).at(-1);
|
|
38
|
+
while (this.store.has(ino) || (lastDev === null || lastDev === void 0 ? void 0 : lastDev.inode.ino) == ino)
|
|
219
39
|
ino++;
|
|
40
|
+
const init = (_a = driver.init) === null || _a === void 0 ? void 0 : _a.call(driver, ino, options);
|
|
220
41
|
const dev = {
|
|
221
|
-
driver,
|
|
222
|
-
ino,
|
|
223
42
|
data: {},
|
|
224
43
|
minor: 0,
|
|
225
44
|
major: 0,
|
|
226
|
-
...(
|
|
45
|
+
...omit(init !== null && init !== void 0 ? init : {}, 'metadata'),
|
|
46
|
+
driver,
|
|
47
|
+
inode: new Inode({
|
|
48
|
+
mode: S_IFCHR | 0o666,
|
|
49
|
+
...init === null || init === void 0 ? void 0 : init.metadata,
|
|
50
|
+
}),
|
|
227
51
|
};
|
|
228
52
|
const path = '/' + (dev.name || driver.name) + (driver.singleton ? '' : this.devicesWithDriver(driver).length);
|
|
229
53
|
if (this.existsSync(path))
|
|
230
|
-
throw
|
|
54
|
+
throw withErrno('EEXIST');
|
|
231
55
|
this.devices.set(path, dev);
|
|
232
56
|
info('Initialized device: ' + this._mountPoint + path);
|
|
233
57
|
return dev;
|
|
@@ -250,93 +74,63 @@ export class DeviceFS extends StoreFS {
|
|
|
250
74
|
this.devices = new Map();
|
|
251
75
|
}
|
|
252
76
|
async rename(oldPath, newPath) {
|
|
253
|
-
if (this.devices.has(oldPath))
|
|
254
|
-
throw
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
throw ErrnoError.With('EEXIST', newPath, 'rename');
|
|
258
|
-
}
|
|
77
|
+
if (this.devices.has(oldPath))
|
|
78
|
+
throw withErrno('EPERM');
|
|
79
|
+
if (this.devices.has(newPath))
|
|
80
|
+
throw withErrno('EEXIST');
|
|
259
81
|
return super.rename(oldPath, newPath);
|
|
260
82
|
}
|
|
261
83
|
renameSync(oldPath, newPath) {
|
|
262
|
-
if (this.devices.has(oldPath))
|
|
263
|
-
throw
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
throw ErrnoError.With('EEXIST', newPath, 'rename');
|
|
267
|
-
}
|
|
84
|
+
if (this.devices.has(oldPath))
|
|
85
|
+
throw withErrno('EPERM');
|
|
86
|
+
if (this.devices.has(newPath))
|
|
87
|
+
throw withErrno('EEXIST');
|
|
268
88
|
return super.renameSync(oldPath, newPath);
|
|
269
89
|
}
|
|
270
90
|
async stat(path) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const file = __addDisposableResource(env_1, await this.openFile(path, 'r'), true);
|
|
275
|
-
return file.stat();
|
|
276
|
-
}
|
|
277
|
-
catch (e_1) {
|
|
278
|
-
env_1.error = e_1;
|
|
279
|
-
env_1.hasError = true;
|
|
280
|
-
}
|
|
281
|
-
finally {
|
|
282
|
-
const result_1 = __disposeResources(env_1);
|
|
283
|
-
if (result_1)
|
|
284
|
-
await result_1;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
91
|
+
const dev = this.devices.get(path);
|
|
92
|
+
if (dev)
|
|
93
|
+
return dev.inode;
|
|
287
94
|
return super.stat(path);
|
|
288
95
|
}
|
|
289
96
|
statSync(path) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const file = __addDisposableResource(env_2, this.openFileSync(path, 'r'), false);
|
|
294
|
-
return file.statSync();
|
|
295
|
-
}
|
|
296
|
-
catch (e_2) {
|
|
297
|
-
env_2.error = e_2;
|
|
298
|
-
env_2.hasError = true;
|
|
299
|
-
}
|
|
300
|
-
finally {
|
|
301
|
-
__disposeResources(env_2);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
97
|
+
const dev = this.devices.get(path);
|
|
98
|
+
if (dev)
|
|
99
|
+
return dev.inode;
|
|
304
100
|
return super.statSync(path);
|
|
305
101
|
}
|
|
306
|
-
async
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
return super.createFileSync(path,
|
|
102
|
+
async touch(path, metadata) {
|
|
103
|
+
const dev = this.devices.get(path);
|
|
104
|
+
if (dev)
|
|
105
|
+
dev.inode.update(metadata);
|
|
106
|
+
else
|
|
107
|
+
await super.touch(path, metadata);
|
|
108
|
+
}
|
|
109
|
+
touchSync(path, metadata) {
|
|
110
|
+
const dev = this.devices.get(path);
|
|
111
|
+
if (dev)
|
|
112
|
+
dev.inode.update(metadata);
|
|
113
|
+
else
|
|
114
|
+
super.touchSync(path, metadata);
|
|
115
|
+
}
|
|
116
|
+
async createFile(path, options) {
|
|
117
|
+
if (this.devices.has(path))
|
|
118
|
+
throw withErrno('EEXIST');
|
|
119
|
+
return super.createFile(path, options);
|
|
120
|
+
}
|
|
121
|
+
createFileSync(path, options) {
|
|
122
|
+
if (this.devices.has(path))
|
|
123
|
+
throw withErrno('EEXIST');
|
|
124
|
+
return super.createFileSync(path, options);
|
|
329
125
|
}
|
|
330
126
|
async unlink(path) {
|
|
331
|
-
if (this.devices.has(path))
|
|
332
|
-
throw
|
|
333
|
-
}
|
|
127
|
+
if (this.devices.has(path))
|
|
128
|
+
throw withErrno('EPERM');
|
|
334
129
|
return super.unlink(path);
|
|
335
130
|
}
|
|
336
131
|
unlinkSync(path) {
|
|
337
|
-
if (this.devices.has(path))
|
|
338
|
-
throw
|
|
339
|
-
}
|
|
132
|
+
if (this.devices.has(path))
|
|
133
|
+
throw withErrno('EPERM');
|
|
340
134
|
return super.unlinkSync(path);
|
|
341
135
|
}
|
|
342
136
|
async rmdir(path) {
|
|
@@ -345,17 +139,15 @@ export class DeviceFS extends StoreFS {
|
|
|
345
139
|
rmdirSync(path) {
|
|
346
140
|
return super.rmdirSync(path);
|
|
347
141
|
}
|
|
348
|
-
async mkdir(path,
|
|
349
|
-
if (this.devices.has(path))
|
|
350
|
-
throw
|
|
351
|
-
|
|
352
|
-
return super.mkdir(path, mode, options);
|
|
142
|
+
async mkdir(path, options) {
|
|
143
|
+
if (this.devices.has(path))
|
|
144
|
+
throw withErrno('EEXIST');
|
|
145
|
+
return super.mkdir(path, options);
|
|
353
146
|
}
|
|
354
|
-
mkdirSync(path,
|
|
355
|
-
if (this.devices.has(path))
|
|
356
|
-
throw
|
|
357
|
-
|
|
358
|
-
return super.mkdirSync(path, mode, options);
|
|
147
|
+
mkdirSync(path, options) {
|
|
148
|
+
if (this.devices.has(path))
|
|
149
|
+
throw withErrno('EEXIST');
|
|
150
|
+
return super.mkdirSync(path, options);
|
|
359
151
|
}
|
|
360
152
|
async readdir(path) {
|
|
361
153
|
const entries = await super.readdir(path);
|
|
@@ -376,34 +168,32 @@ export class DeviceFS extends StoreFS {
|
|
|
376
168
|
return entries;
|
|
377
169
|
}
|
|
378
170
|
async link(target, link) {
|
|
379
|
-
if (this.devices.has(target))
|
|
380
|
-
throw
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
throw ErrnoError.With('EEXIST', link, 'link');
|
|
384
|
-
}
|
|
171
|
+
if (this.devices.has(target))
|
|
172
|
+
throw withErrno('EPERM');
|
|
173
|
+
if (this.devices.has(link))
|
|
174
|
+
throw withErrno('EEXIST');
|
|
385
175
|
return super.link(target, link);
|
|
386
176
|
}
|
|
387
177
|
linkSync(target, link) {
|
|
388
|
-
if (this.devices.has(target))
|
|
389
|
-
throw
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
throw ErrnoError.With('EEXIST', link, 'link');
|
|
393
|
-
}
|
|
178
|
+
if (this.devices.has(target))
|
|
179
|
+
throw withErrno('EPERM');
|
|
180
|
+
if (this.devices.has(link))
|
|
181
|
+
throw withErrno('EEXIST');
|
|
394
182
|
return super.linkSync(target, link);
|
|
395
183
|
}
|
|
396
|
-
async sync(
|
|
397
|
-
|
|
398
|
-
|
|
184
|
+
async sync() {
|
|
185
|
+
var _a, _b;
|
|
186
|
+
for (const device of this.devices.values()) {
|
|
187
|
+
(_b = (_a = device.driver).sync) === null || _b === void 0 ? void 0 : _b.call(_a, device);
|
|
399
188
|
}
|
|
400
|
-
return super.sync(
|
|
189
|
+
return super.sync();
|
|
401
190
|
}
|
|
402
|
-
syncSync(
|
|
403
|
-
|
|
404
|
-
|
|
191
|
+
syncSync() {
|
|
192
|
+
var _a, _b;
|
|
193
|
+
for (const device of this.devices.values()) {
|
|
194
|
+
(_b = (_a = device.driver).sync) === null || _b === void 0 ? void 0 : _b.call(_a, device);
|
|
405
195
|
}
|
|
406
|
-
return super.syncSync(
|
|
196
|
+
return super.syncSync();
|
|
407
197
|
}
|
|
408
198
|
async read(path, buffer, offset, end) {
|
|
409
199
|
const device = this.devices.get(path);
|
|
@@ -411,7 +201,7 @@ export class DeviceFS extends StoreFS {
|
|
|
411
201
|
await super.read(path, buffer, offset, end);
|
|
412
202
|
return;
|
|
413
203
|
}
|
|
414
|
-
device.driver.
|
|
204
|
+
device.driver.read(device, buffer, offset, end);
|
|
415
205
|
}
|
|
416
206
|
readSync(path, buffer, offset, end) {
|
|
417
207
|
const device = this.devices.get(path);
|
|
@@ -419,26 +209,23 @@ export class DeviceFS extends StoreFS {
|
|
|
419
209
|
super.readSync(path, buffer, offset, end);
|
|
420
210
|
return;
|
|
421
211
|
}
|
|
422
|
-
device.driver.
|
|
212
|
+
device.driver.read(device, buffer, offset, end);
|
|
423
213
|
}
|
|
424
214
|
async write(path, data, offset) {
|
|
425
215
|
const device = this.devices.get(path);
|
|
426
216
|
if (!device) {
|
|
427
217
|
return await super.write(path, data, offset);
|
|
428
218
|
}
|
|
429
|
-
device.driver.
|
|
219
|
+
device.driver.write(device, data, offset);
|
|
430
220
|
}
|
|
431
221
|
writeSync(path, data, offset) {
|
|
432
222
|
const device = this.devices.get(path);
|
|
433
223
|
if (!device) {
|
|
434
224
|
return super.writeSync(path, data, offset);
|
|
435
225
|
}
|
|
436
|
-
device.driver.
|
|
226
|
+
device.driver.write(device, data, offset);
|
|
437
227
|
}
|
|
438
228
|
}
|
|
439
|
-
function defaultWrite(device, data, offset) {
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
229
|
const emptyBuffer = new Uint8Array();
|
|
443
230
|
/**
|
|
444
231
|
* Simulates the `/dev/null` device.
|
|
@@ -454,12 +241,11 @@ export const nullDevice = {
|
|
|
454
241
|
return { major: 1, minor: 3 };
|
|
455
242
|
},
|
|
456
243
|
read() {
|
|
457
|
-
return 0;
|
|
458
|
-
},
|
|
459
|
-
readD() {
|
|
460
244
|
return emptyBuffer;
|
|
461
245
|
},
|
|
462
|
-
|
|
246
|
+
write() {
|
|
247
|
+
return;
|
|
248
|
+
},
|
|
463
249
|
};
|
|
464
250
|
/**
|
|
465
251
|
* Simulates the `/dev/zero` device
|
|
@@ -478,10 +264,12 @@ export const zeroDevice = {
|
|
|
478
264
|
init() {
|
|
479
265
|
return { major: 1, minor: 5 };
|
|
480
266
|
},
|
|
481
|
-
|
|
267
|
+
read(device, buffer, offset, end) {
|
|
482
268
|
buffer.fill(0, offset, end);
|
|
483
269
|
},
|
|
484
|
-
|
|
270
|
+
write() {
|
|
271
|
+
return;
|
|
272
|
+
},
|
|
485
273
|
};
|
|
486
274
|
/**
|
|
487
275
|
* Simulates the `/dev/full` device.
|
|
@@ -496,14 +284,11 @@ export const fullDevice = {
|
|
|
496
284
|
init() {
|
|
497
285
|
return { major: 1, minor: 7 };
|
|
498
286
|
},
|
|
499
|
-
|
|
287
|
+
read(device, buffer, offset, end) {
|
|
500
288
|
buffer.fill(0, offset, end);
|
|
501
289
|
},
|
|
502
|
-
write(
|
|
503
|
-
throw
|
|
504
|
-
},
|
|
505
|
-
writeD() {
|
|
506
|
-
throw ErrnoError.With('ENOSPC', undefined, 'write');
|
|
290
|
+
write() {
|
|
291
|
+
throw withErrno('ENOSPC');
|
|
507
292
|
},
|
|
508
293
|
};
|
|
509
294
|
/**
|
|
@@ -519,12 +304,14 @@ export const randomDevice = {
|
|
|
519
304
|
init() {
|
|
520
305
|
return { major: 1, minor: 8 };
|
|
521
306
|
},
|
|
522
|
-
|
|
307
|
+
read(device, buffer) {
|
|
523
308
|
for (let i = 0; i < buffer.length; i++) {
|
|
524
309
|
buffer[i] = Math.floor(Math.random() * 256);
|
|
525
310
|
}
|
|
526
311
|
},
|
|
527
|
-
|
|
312
|
+
write() {
|
|
313
|
+
return;
|
|
314
|
+
},
|
|
528
315
|
};
|
|
529
316
|
/**
|
|
530
317
|
* Simulates the `/dev/console` device.
|
|
@@ -537,10 +324,10 @@ const consoleDevice = {
|
|
|
537
324
|
init(ino, { output = text => console.log(text) } = {}) {
|
|
538
325
|
return { major: 5, minor: 1, data: { output } };
|
|
539
326
|
},
|
|
540
|
-
|
|
327
|
+
read() {
|
|
541
328
|
return emptyBuffer;
|
|
542
329
|
},
|
|
543
|
-
|
|
330
|
+
write(device, buffer, offset) {
|
|
544
331
|
const text = decodeUTF8(buffer);
|
|
545
332
|
device.data.output(text, offset);
|
|
546
333
|
},
|