vfs: add callback readv and writev handlers

A mounted VFS causes callback readv and writev to call missing
handlers, breaking both virtual and real file descriptors.

Add both handlers while preserving I/O for real descriptors.

Signed-off-by: Daniel Cavalcante <dcavalcante@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66548
Fixes: https://github.com/nodejs/node/issues/66532
Reviewed-By: Philipp Dunkel <pip@pipobscure.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Daniel Cavalcante authored and GitHub committed 2026-11-14 16:01:59 +00:00
1 parent 3f8e1f5a36
commit 0b4d0ac5a2
2 files changed
+47

No files matched your search

+12
View File
@@ -658,12 +658,24 @@ function createVfsHandlers() {
return vfd.entry.read(buffer, offset, length, position)
.then(({ bytesRead }) => bytesRead);
},
readv(fd, buffers, position) {
const vfd = getVirtualFd(fd);
if (!vfd) return undefined;
return vfd.entry.readv(buffers, position)
.then(({ bytesRead }) => bytesRead);
},
write(fd, buffer, offset, length, position) {
const vfd = getVirtualFd(fd);
if (!vfd) return undefined;
return vfd.entry.write(buffer, offset, length, position)
.then(({ bytesWritten }) => bytesWritten);
},
writev(fd, buffers, position) {
const vfd = getVirtualFd(fd);
if (!vfd) return undefined;
return vfd.entry.writev(buffers, position)
.then(({ bytesWritten }) => bytesWritten);
},
fstat(fd, options) {
const vfd = getVirtualFd(fd);
if (!vfd) return undefined;
+35
View File
@@ -0,0 +1,35 @@
// Flags: --experimental-vfs
'use strict';
const common = require('../common');
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const tmpdir = require('../common/tmpdir');
const vfs = require('node:vfs');
tmpdir.refresh();
const mounted = vfs.create();
mounted.mkdirSync('/files', { recursive: true });
const mountPoint = mounted.mount();
const realFd = fs.openSync(tmpdir.resolve('real.txt'), 'w+');
const virtualFd = fs.openSync(path.join(mountPoint, 'files/virtual.txt'), 'w+');
let remaining = 2;
for (const fd of [realFd, virtualFd]) {
const chunks = [Buffer.from('hello'), Buffer.from('world')];
fs.writev(fd, chunks, null, common.mustSucceed((bytesWritten, buffers) => {
assert.strictEqual(bytesWritten, 10);
assert.strictEqual(buffers, chunks);
const received = [Buffer.alloc(5), Buffer.alloc(5)];
fs.readv(fd, received, 0, common.mustSucceed((bytesRead, readBuffers) => {
assert.strictEqual(bytesRead, 10);
assert.strictEqual(readBuffers, received);
assert.strictEqual(Buffer.concat(received).toString(), 'helloworld');
fs.closeSync(fd);
if (--remaining === 0) mounted.unmount();
}));
}));
}