Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0710775
Squashed commit of the following:
jameshu15869 Jul 10, 2023
5b79521
more clean up
jameshu15869 Jul 10, 2023
7cbbcbb
clean up and add more ci tests
jameshu15869 Jul 10, 2023
56478ad
uncomment
jameshu15869 Jul 10, 2023
82cede3
remove extra include
jameshu15869 Jul 10, 2023
e23e1ad
rename and refactor
jameshu15869 Jul 10, 2023
069f629
Merge branch 'main' into library-wasmfs-mount-acct
jameshu15869 Jul 11, 2023
95cfd17
before merge
jameshu15869 Jul 12, 2023
a7aeef1
Merge branch 'main' into library-wasmfs-mount-acct
jameshu15869 Jul 12, 2023
830a150
add library_* mirrors and fixes
jameshu15869 Jul 12, 2023
4c5224c
Merge branch 'main' into library-wasmfs-mount-acct
jameshu15869 Jul 12, 2023
2a13102
ci
jameshu15869 Jul 12, 2023
0997caf
uncomment
jameshu15869 Jul 12, 2023
9741d47
Merge branch 'main' into library-wasmfs-mount-acct
jameshu15869 Jul 25, 2023
3ee5bd2
add link checks
jameshu15869 Jul 25, 2023
5e3661c
add removed FS asserts
jameshu15869 Jul 25, 2023
2c862c0
Merge branch 'main' into library-wasmfs-mount-acct
jameshu15869 Jul 25, 2023
87412b5
Merge branch 'main' into library-wasmfs-mount-acct
jameshu15869 Jul 25, 2023
6cf9a9b
fix header and unmount
jameshu15869 Jul 26, 2023
d6e3168
Merge branch 'main' into library-wasmfs-mount-acct
jameshu15869 Jul 26, 2023
bedaeaf
use namespace in get_backend
jameshu15869 Jul 26, 2023
9f974c2
Merge branch 'main' into library-wasmfs-mount-acct
jameshu15869 Jul 26, 2023
babf15a
clean up
jameshu15869 Jul 26, 2023
5c89b3f
clean up
jameshu15869 Jul 26, 2023
650e784
Merge branch 'main' into library-wasmfs-mount-acct
jameshu15869 Jul 27, 2023
2b6b01c
rename wasmfs_unmountat to wasmfs_mount
jameshu15869 Jul 27, 2023
8616a70
Merge branch 'main' into library-wasmfs-mount-acct
jameshu15869 Jul 31, 2023
275afdf
copyright and formatting
jameshu15869 Aug 1, 2023
2649933
Merge branch 'main' into library-wasmfs-mount-acct
jameshu15869 Aug 1, 2023
8a950aa
Merge branch 'library-wasmfs-mount-acct' of https://github.com/jamesh…
jameshu15869 Aug 1, 2023
dc262e9
remove extra character
jameshu15869 Aug 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,29 @@ jobs:
wasmfs.test_readdir_unlink
wasmfs.test_unistd_pipe
wasmfs.test_fs_write
wasmfs.test_fs_writev
wasmfs.test_fs_writev_rawfs
wasmfs.test_fs_writeFile
wasmfs.test_fs_writeFile_rawfs
wasmfs.test_fs_readv
wasmfs.test_fs_write
wasmfs.test_fs_readv_rawfs
wasmfs.test_fs_nodefs_nofollow
wasmfs.test_fs_nodefs_readdir
wasmfs.test_fs_nodefs_home
wasmfs.test_fs_nodefs_cloexec
wasmfs.test_fs_nodefs_cloexec_rawfs
wasmfs.test_fs_errorstack
wasmfs.test_fs_errorstack_rawfs
wasmfs.test_fs_emptyPath

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 put wasmfs.test_fs_* here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not all the test_fs_* tests are passing yet, since some are failing because the functions haven't been implemented yet.

wasmfs.test_webidl
wasmfs.test_dlfcn_self
wasmfs.test_dlfcn_unique_sig
wasmfs.test_dylink_basics
wasmfs.test_exit_status
wasmfs.test_minimal_runtime_memorygrowth
wasmfs.test_mmap_anon*
wasmfs.test_mount
wasmfs.test_getcwd_with_non_ascii_name
wasmfs.test_stat
wasmfs.test_fstatat
Expand All @@ -559,6 +575,7 @@ jobs:
wasmfs.test_fcntl_open
wasmfs.test_fs_js_api
wasmfs.test_fs_llseek
wasmfs.test_fs_llseek_rawfs
wasmfs.test_freetype"
test-wasm2js1:
environment:
Expand Down
2 changes: 2 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2340,6 +2340,8 @@ def phase_linker_setup(options, state, newargs):
# included, as the entire JS library can refer to things that require
# these exports.)
settings.REQUIRED_EXPORTS += [
'_wasmfs_mount',
'_wasmfs_unmount',
'_wasmfs_read_file',
'_wasmfs_write_file',
'_wasmfs_open',
Expand Down
18 changes: 18 additions & 0 deletions src/library_fetchfs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright 2023 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/

mergeInto(LibraryManager.library, {
$FETCHFS__deps: ['$stringToUTF8OnStack', 'wasmfs_create_fetch_backend'],
$FETCHFS: {
createBackend(opts) {
return _wasmfs_create_fetch_backend(stringToUTF8OnStack(opts.base_url));
}
},
});

if (!WASMFS) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should these checks be #if preprocessor checks?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did consider using #if, but was a little unsure how to trigger the error if the library_fetchfs.js file actually got linked in. Does calling error() inside a top-level #if (As below) have the potential to cause any problems?

#if !WASMFS
error("using -lfetchfs is not currently supported in WasmFS."
#endif

@kripken kripken Jul 26, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is ok as normal JS. We use the preprocessor to filter what code is emitted in the output JS, but this code is not in the output JS - unlike say preamble.js which is in the output, this is a JS library file which is executed. So it's ok to use normal JS execution to check things like if (..) {..

error("using -lfetchfs.js requires using WasmFS (-sWASMFS)");
}
22 changes: 22 additions & 0 deletions src/library_icasefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @license
* Copyright 2023 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/

mergeInto(LibraryManager.library, {
$ICASEFS__deps: ['wasmfs_create_icase_backend'],
$ICASEFS: {
createBackend(opts) {
if (typeof opts.backend === "undefined") {
throw new Error("Underlying backend is not valid.");
}
var underlyingBackend = opts.backend.createBackend(opts);
return _wasmfs_create_icase_backend(underlyingBackend);
}
},
});

if (!WASMFS) {
error("using -licasefs.js requires using WasmFS (-sWASMFS)");
}
4 changes: 4 additions & 0 deletions src/library_idbfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,7 @@ mergeInto(LibraryManager.library, {
}
}
});

if (WASMFS) {
error("using -lidbfs is not currently supported in WasmFS.");
}
18 changes: 18 additions & 0 deletions src/library_jsfilefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright 2023 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/

mergeInto(LibraryManager.library, {
$JSFILEFS__deps: ['wasmfs_create_js_file_backend'],
$JSFILEFS: {
createBackend(opts) {
return _wasmfs_create_js_file_backend();
}
},
});

if (!WASMFS) {
error("using -ljsfile.js requires using WasmFS (-sWASMFS)");
}
9 changes: 9 additions & 0 deletions src/library_nodefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
*/

mergeInto(LibraryManager.library, {
#if WASMFS
$NODEFS__deps: ['$stringToUTF8OnStack', 'wasmfs_create_node_backend'],
$NODEFS: {
createBackend(opts) {
return _wasmfs_create_node_backend(stringToUTF8OnStack(opts.root));
Comment thread
kripken marked this conversation as resolved.
Resolved
}
}
#else
$NODEFS__deps: ['$FS', '$PATH', '$ERRNO_CODES', '$mmapAlloc'],
$NODEFS__postset: 'if (ENVIRONMENT_IS_NODE) { NODEFS.staticInit(); }',
$NODEFS: {
Expand Down Expand Up @@ -314,4 +322,5 @@ mergeInto(LibraryManager.library, {
}
}
}
#endif
});
18 changes: 18 additions & 0 deletions src/library_opfs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright 2023 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/

mergeInto(LibraryManager.library, {
$OPFS__deps: ['wasmfs_create_opfs_backend'],
$OPFS: {
createBackend(opts) {
return _wasmfs_create_opfs_backend();
}
},
});

if (!WASMFS) {
error("using -lopfs.js requires using WasmFS (-sWASMFS)");
}
4 changes: 4 additions & 0 deletions src/library_proxyfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,7 @@ mergeInto(LibraryManager.library, {
}
}
});

if (WASMFS) {
error("using -lproxyfs is not currently supported in WasmFS.");
}
38 changes: 36 additions & 2 deletions src/library_wasmfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
*/

mergeInto(LibraryManager.library, {
$MEMFS__deps: ['wasmfs_create_memory_backend'],
$MEMFS: {
createBackend(opts) {
return _wasmfs_create_memory_backend();
}
},
$wasmFSPreloadedFiles: [],
$wasmFSPreloadedDirs: [],
// We must note when preloading has been "flushed", that is, the time at which
Expand All @@ -18,6 +24,7 @@ FS.init();
FS.createPreloadedFile = FS_createPreloadedFile;
`,
$FS__deps: [
'$MEMFS',
'$wasmFSPreloadedFiles',
'$wasmFSPreloadedDirs',
'$wasmFSPreloadingFlushed',
Expand All @@ -35,6 +42,21 @@ FS.createPreloadedFile = FS_createPreloadedFile;
// up requiring all of our code
// here.
'$FS_modeStringToFlags',
#if LibraryManager.has('library_icasefs.js')
'$ICASEFS',
#endif
#if LibraryManager.has('library_nodefs.js')
'$NODEFS',
#endif
#if LibraryManager.has('library_opfs.js')
'$OPFS',
#endif
#if LibraryManager.has('library_jsfilefs.js')
'$JSFILEFS',
#endif
#if LibraryManager.has('library_fetchfs.js')
'$FETCHFS',
#endif
'malloc',
'free',
#endif
Expand Down Expand Up @@ -349,8 +371,20 @@ FS.createPreloadedFile = FS_createPreloadedFile;
__wasmfs_readdir_finish(state);
return entries;
}),
// TODO: mount
// TODO: unmount
mount: (type, opts, mountpoint) => {
#if ASSERTIONS
if (typeof type == 'string') {
// The filesystem was not included, and instead we have an error
// message stored in the variable.
throw type;
Comment on lines +377 to +379

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Where does the error message stored in type come from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think parseTools.js (Specifically makeRemovedFSAssert()) will scan through and try to find any usages of globals like NODEFS that are used when library_nodefs.js isn't linked in and convert the variable value to a string.

}
#endif
var backendPointer = type.createBackend(opts);
return FS.handleError(withStackSave(() => __wasmfs_mount(stringToUTF8OnStack(mountpoint), backendPointer)));
},
unmount: (mountpoint) => (
FS.handleError(withStackSave(() => __wasmfs_unmount(stringToUTF8OnStack(mountpoint))))
Comment thread
kripken marked this conversation as resolved.
Resolved
),
// TODO: lookup
mknod(path, mode, dev) {
return FS.handleError(withStackSave(() => {
Expand Down
4 changes: 4 additions & 0 deletions src/library_workerfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,7 @@ mergeInto(LibraryManager.library, {
},
},
});

if (WASMFS) {
error("using -lworkerfs is not currently supported in WasmFS.");
}
5 changes: 5 additions & 0 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ assert(typeof Module['TOTAL_MEMORY'] == 'undefined', 'Module.TOTAL_MEMORY has be
{{{ makeRemovedFSAssert('IDBFS') }}}
{{{ makeRemovedFSAssert('PROXYFS') }}}
{{{ makeRemovedFSAssert('WORKERFS') }}}
{{{ makeRemovedFSAssert('FETCHFS') }}}
{{{ makeRemovedFSAssert('ICASEFS') }}}
{{{ makeRemovedFSAssert('JSFILEFS') }}}
{{{ makeRemovedFSAssert('OPFS') }}}

#if !NODERAWFS
{{{ makeRemovedFSAssert('NODEFS') }}}
#endif
Expand Down
9 changes: 7 additions & 2 deletions system/include/emscripten/wasmfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ backend_t wasmfs_get_backend_by_fd(int fd);
// Returns the file descriptor for the new file like `open`. Returns a negative
// value on error. TODO: It might be worth returning a more specialized type
// like __wasi_fd_t here.
// TODO: Remove this function so that only directories can be mounted.
int wasmfs_create_file(const char* pathname __attribute__((nonnull)), mode_t mode, backend_t backend);

// Creates a new directory in the new file system under a specific backend.
// Returns 0 on success like `mkdir`, or a negative value on error.
// TODO: Add an alias with wasmfs_mount.
int wasmfs_create_directory(const char* path __attribute__((nonnull)), mode_t mode, backend_t backend);

// Unmounts the directory (Which must be a valid mountpoint) at a specific path.
// Returns 0 on success, or a negative value on error.
int wasmfs_unmount(intptr_t path);

// Backend creation

// Creates a JSFile Backend in the new file system.
Expand Down Expand Up @@ -66,8 +72,7 @@ backend_t wasmfs_create_node_backend(const char* root __attribute__((nonnull)));
// thread.
backend_t wasmfs_create_opfs_backend(void);

backend_t wasmfs_create_icase_backend(backend_constructor_t create_backend,
void* arg);
backend_t wasmfs_create_icase_backend(backend_t backend);

// Similar to fflush(0), but also flushes all internal buffers inside WasmFS.
// This is necessary because in a Web environment we must buffer at an
Expand Down
8 changes: 4 additions & 4 deletions system/lib/wasmfs/backends/ignore_case_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ backend_t createIgnoreCaseBackend(std::function<backend_t()> createBackend) {

extern "C" {

// C API for creating ignore case backend.
backend_t wasmfs_create_icase_backend(backend_constructor_t create_backend,
void* arg) {
// C API FOR creating an ignore case backend by supplying a pointer to another backend.
backend_t wasmfs_create_icase_backend(backend_t backend) {
return createIgnoreCaseBackend(
[create_backend, arg]() { return create_backend(arg); });
[backend]() { return backend; }
);
}

} // extern "C"
Expand Down
25 changes: 24 additions & 1 deletion system/lib/wasmfs/js_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ using namespace wasmfs;

extern "C" {

// TODO: Replace forward declarations with #include <emscripten/wasmfs.h> and
// resolve wasmfs::backend_t namespace conflicts.
__wasi_fd_t wasmfs_create_file(char* pathname, mode_t mode, backend_t backend);
int wasmfs_create_directory(char* path, int mode, backend_t backend);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should probably include emscripten/wasmfs.h rather than forward-declaring functions here. Including the header will make sure that the function definitions and function users are always working with the same signature. Having this standalone forward declarations runs the risk of the signatures getting out of sync.

We can add wasmfs_unmount to emscripten/wasmfs.h as well.

@jameshu15869 jameshu15869 Jul 12, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Directly using #include <emscripten/wasmfs.h> ends up giving me a few weird errors like

C:\Users\james\Documents\GitHub\emscripten\system\lib\wasmfs\js_api.cpp:266:31: error: reference to 'backend_t' is
      ambiguous
  266 | int _wasmfs_mount(char* path, backend_t created_backend) {
      |                               ^
C:\Users\james\Documents\GitHub\emscripten\cache\sysroot/include\emscripten/wasmfs.h:17:25: note: candidate found by
      name lookup is 'backend_t'
   17 | typedef struct Backend* backend_t;
      |                         ^
C:\Users\james\Documents\GitHub\emscripten\system\lib\wasmfs/file.h:35:7: note: candidate found by name lookup is
      'wasmfs::backend_t'
   35 | using backend_t = Backend*;
      |       ^
C:\Users\james\Documents\GitHub\emscripten\system\lib\wasmfs\js_api.cpp:292:10: error: no matching function for call to
      'wasmfs_create_directory'
  292 |   return wasmfs_create_directory(path, 0777, created_backend);
      |          ^~~~~~~~~~~~~~~~~~~~~~~
C:\Users\james\Documents\GitHub\emscripten\cache\sysroot/include\emscripten/wasmfs.h:33:5: note: candidate function not
      viable: no known conversion from 'backend_t' (aka 'wasmfs::Backend *') to 'backend_t' (aka 'Backend *') for 3rd
      argument
   33 | int wasmfs_create_directory(const char* path __attribute__((nonnull)), mode_t mode, backend_t backend);
      |     ^
2 errors generated..

It seems like backend_t is redefined in emscripten/wasmfs.h using typedef struct Backend* backend_t without a namespace, while there is using namespace wasmfs in js_api.cpp. Would it make sense to change all the usages of backend_t in emscripten/wasmfs.h to wasmfs::backend_t? I'm still new to C++ so this might not be the best approach.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, adding the namespace in emscripten/wasmfs.h would fix this. Unfortunately emscripten/wasmfs.h also has to work as a plain C header, though, so it's not entirely straightforward. You would have to insert namespace wasmfs { ... } around the typedef only when using C++ and not when using C by using the preprocessor. You can see an example of this in emscripten/proxying.h.

But for this PR, keeping the forward declarations in this file to avoid all these issues seems fine as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've tried using the ifdef as shown below

#ifdef __cplusplus
namespace wasmfs {
#endif
typedef struct Backend* backend_t;
#ifdef __cplusplus
} // namespace wasmfs
#endif

However, it still looks like I'm getting an error with backend_t being ambiguous.

candidate function not
      viable: no known conversion from 'wasmfs::backend_t' (aka 'wasmfs::Backend *') to 'backend_t' (aka 'Backend *') for
      3rd argument
   35 | int wasmfs_create_directory(const char* path __attribute__((nonnull)), mode_t mode, backend_t backend);

Am I using the preprocessor incorrectly? Would it make more sense to use something like typedef wasmfs::backend_t backend_t inside the C++ ifdef, then typedef struct Backend* backend_t if C++ is not defined? Based on my understanding, doesn't the problem come from having one backend_t defined inside the namespace and one that isn't (Instead defined in wasmfs.h)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was able to solve the problem by wrapping namespace wasmfs {} around the entire section, although I'm not sure if this might cause any problems in the future.

int wasmfs_unmount(intptr_t path);

// Copy the file specified by the pathname into JS.
// Return a pointer to the JS buffer in HEAPU8.
// The buffer will also contain the file length.
// TODO: Use WasmFS ErrnoError handling instead of aborting on failure.
void* _wasmfs_read_file(char* path) {
static_assert(sizeof(off_t) == 8, "File offset type must be 64-bit");

Expand Down Expand Up @@ -207,7 +212,7 @@ int _wasmfs_llseek(int fd, off_t offset, int whence) {

int _wasmfs_rename(char* oldpath, char* newpath) {
return __syscall_renameat(AT_FDCWD, (intptr_t)oldpath, AT_FDCWD, (intptr_t)newpath);
};
}

int _wasmfs_read(int fd, void *buf, size_t count) {
__wasi_iovec_t iovs[1];
Expand Down Expand Up @@ -265,6 +270,24 @@ int _wasmfs_lstat(char* path, struct stat* statBuf) {
return __syscall_lstat64((intptr_t)path, (intptr_t)statBuf);
}

// The legacy JS API requires a mountpoint to already exist, so WasmFS will attempt to remove
// the target directory if it exists before replacing it with a mounted directory.
int _wasmfs_mount(char* path, wasmfs::backend_t created_backend) {
int err = __syscall_rmdir((intptr_t)path);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be good to add a comment explaining that we do this for compatibility with the legacy JS API, because otherwise this seems like nonsense.


// The legacy JS API mount requires the directory to already exist, but we will also allow it to be missing.
if (err && err != -ENOENT) {
return err;
}

return wasmfs_create_directory(path, 0777, created_backend);
}

// WasmFS will always remove the mounted directory, regardless of if the directory existed before.
int _wasmfs_unmount(char* path) {
return wasmfs_unmount((intptr_t)path);
}

// Helper method that identifies what a path is:
// ENOENT - if nothing exists there
// EISDIR - if it is a directory
Expand Down
33 changes: 33 additions & 0 deletions system/lib/wasmfs/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,39 @@ int __syscall_rmdir(intptr_t path) {
return __syscall_unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
}

// wasmfs_unmount is similar to __syscall_unlinkat, but assumes AT_REMOVEDIR is true
// and will only unlink mountpoints (Empty and nonempty).
int wasmfs_unmount(intptr_t path) {
auto parsed = path::parseParent((char*)path, AT_FDCWD);
if (auto err = parsed.getError()) {
return err;
}
auto& [parent, childNameView] = parsed.getParentChild();
std::string childName(childNameView);
auto lockedParent = parent->locked();
auto file = lockedParent.getChild(childName);
if (!file) {
return -ENOENT;
}
// Disallow removing the root directory, even if it is empty.
if (file == wasmFS.getRootDirectory()) {
return -EBUSY;
}

if (auto dir = file->dynCast<Directory>()) {
if (parent->getBackend() == dir->getBackend()) {
// The child is not a valid mountpoint.
return -EINVAL;
}
} else {
// A normal file or symlink.
return -ENOTDIR;
}

// Input is valid, perform the unlink.
return lockedParent.removeChild(childName);
}

int __syscall_getdents64(int fd, intptr_t dirp, size_t count) {
dirent* result = (dirent*)dirp;

Expand Down
7 changes: 7 additions & 0 deletions test/fs/test_fs_js_api.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright 2023 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*/

#include <emscripten/emscripten.h>
#include <stdio.h>
#include <unistd.h>
Expand Down
Loading