vfs: make the reserved root readable through fs · nodejs/node@afb61d6 · GitHub
Skip to content

Commit afb61d6

Browse files
pipobscureaduh95
authored andcommitted
vfs: make the reserved root readable through fs
The reserved root `${os.devNull}/vfs`, which holds the mount points of all virtual file systems, could not be read: fs calls on it fell through to the real file system, so nothing could list what was mounted. While any file system is mounted, serve the root as a read-only directory. It lists every mount point by the last segment of its path, a recursive listing descends into each mounted file system, and paths under it that no mount serves report ENOENT. Creating, removing or changing entries in it fails with EROFS. When nothing is mounted it does not exist, as before. Add vfs.vfsBase(), which returns the path of that directory, so that a program can read it without spelling the path out. A mount point cannot be removed or renamed, nor replaced by a rename: rmdir() and rename() fail with EBUSY, and a recursive rm() empties the file system and then fails the same way. Before, rmdir() of an empty mount point reported success without doing anything. The callback and promise forms of readdir() with `withFileTypes` now report each Dirent's parentPath as a host path, as readdirSync() did, instead of the provider-relative one, and split recursive names such as `dir/file.txt` into their directory and base name. A recursive listing joins subdirectories with the host separator rather than `/`, which mixed separators on Windows. realpath() of a mount point no longer returns it with a trailing separator. Signed-off-by: Philipp Dunkel <pip@pipobscure.com> PR-URL: #66140 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 83c0e30 commit afb61d6

8 files changed

Lines changed: 645 additions & 39 deletions

File tree

‎doc/api/vfs.md‎

Lines changed: 64 additions & 3 deletions

‎lib/internal/vfs/errors.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const {
1919
UV_EINVAL,
2020
UV_ELOOP,
2121
UV_EACCES,
22+
UV_EBUSY,
2223
UV_EXDEV,
2324
} = internalBinding('uv');
2425

@@ -180,6 +181,16 @@ function createEACCES(syscall, path) {
180181
return err;
181182
}
182183

184+
function createEBUSY(syscall, path) {
185+
const err = new UVException({
186+
errno: UV_EBUSY,
187+
syscall,
188+
path,
189+
});
190+
ErrorCaptureStackTrace(err, createEBUSY);
191+
return err;
192+
}
193+
183194
function createEXDEV(syscall, path) {
184195
const err = new UVException({
185196
errno: UV_EXDEV,
@@ -201,5 +212,6 @@ module.exports = {
201212
createEINVAL,
202213
createELOOP,
203214
createEACCES,
215+
createEBUSY,
204216
createEXDEV,
205217
};

‎lib/internal/vfs/file_system.js‎

Lines changed: 64 additions & 22 deletions

0 commit comments

Comments
 (0)