Skip to content
Open
2 changes: 2 additions & 0 deletions system/lib/wasmfs/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Backend {
virtual std::shared_ptr<Directory> createDirectory(mode_t mode) = 0;
virtual std::shared_ptr<Symlink> createSymlink(std::string target) = 0;

virtual bool shouldPopulateRoot() { return true; }

virtual ~Backend() = default;
};

Expand Down
2 changes: 2 additions & 0 deletions system/lib/wasmfs/backends/node_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ class NodeBackend : public Backend {
std::shared_ptr<Symlink> createSymlink(std::string target) override {
WASMFS_UNREACHABLE("TODO: implement NodeBackend::createSymlink");
}

virtual bool shouldPopulateRoot() override { return false; }
};

// TODO: symlink
Expand Down
8 changes: 7 additions & 1 deletion system/lib/wasmfs/wasmfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ std::shared_ptr<Directory> WasmFS::initRootDirectory() {
// The root directory is its own parent.
lockedRoot.setParent(rootDirectory);

// Skip setting up the root directory when not needed (e.g. in NODERAWFS
// mode).
if (!rootBackend->shouldPopulateRoot()) {
return rootDirectory;
}

// If the /dev/ directory does not already exist, create it. (It may already
// exist in NODERAWFS mode, or if those files have been preloaded.)
// exist if those files have been preloaded.)
auto devDir = lockedRoot.insertDirectory("dev", S_IRUGO | S_IXUGO);
if (devDir) {
auto lockedDev = devDir->locked();
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_wasmfs.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 7056,
"a.out.js.gz": 3322,
"a.out.nodebug.wasm": 172695,
"a.out.nodebug.wasm.gz": 63383,
"total": 179751,
"total_gz": 66705,
"a.out.nodebug.wasm": 172722,
"a.out.nodebug.wasm.gz": 63393,
"total": 179778,
"total_gz": 66715,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_files_wasmfs.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 5487,
"a.out.js.gz": 2586,
"a.out.nodebug.wasm": 58324,
"a.out.nodebug.wasm.gz": 18215,
"total": 63811,
"total_gz": 20801,
"a.out.nodebug.wasm": 58349,
"a.out.nodebug.wasm.gz": 18247,
"total": 63836,
"total_gz": 20833,
"sent": [
"a (emscripten_date_now)",
"b (emscripten_err)",
Expand Down
4 changes: 4 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -5554,6 +5554,8 @@ def test_fsync(self, args):
def test_fs_dev_random(self):
if WINDOWS and self.get_setting('NODERAWFS'):
self.skipTest('Crashes on Windows and NodeFS')
if self.get_setting('NODERAWFS') and self.get_setting('WASMFS'):
self.skipTest('https://github.com/emscripten-core/emscripten/issues/24830')
self.do_runf('fs/test_fs_dev_random.c', 'done\n')

@parameterized({
Expand Down Expand Up @@ -13274,6 +13276,8 @@ def test_unistd_chown(self):

@wasmfs_all_backends
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this?

Does wasmfs_getdents.c need to get re-written to handle the rawfs mabye?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just skip under NODERAWFS rather than removing wasmfs_all_backends completely?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-added the @wasmfs_all_backends decorator and skipped this only under NODERAWFS with commit f3b85c9.

See for details:

------------- Reading from /dev Directory via JS -------------
.
..
null
random
stderr
stdin
stdout
urandom

def test_wasmfs_getdents(self):
if self.get_setting('NODERAWFS'):
self.skipTest('test expectations assumes /dev is virtualized')
# Run only in WASMFS for now.
self.set_setting('FORCE_FILESYSTEM')
self.do_run_in_out_file_test('wasmfs/wasmfs_getdents.c')
Expand Down
Loading