Skip to content

Commit 11725fa

Browse files
authored
[WasmFS] Consistent use of const char* in wasmfs API (#23775)
1 parent ff58722 commit 11725fa

File tree

5 files changed

+8
-13
lines changed

5 files changed

+8
-13
lines changed

src/lib/libwasmfs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ addToLibrary({
351351
return FS.handleError(withStackSave(() => __wasmfs_mount(stringToUTF8OnStack(mountpoint), backendPointer)));
352352
},
353353
unmount: (mountpoint) => (
354-
FS.handleError(withStackSave(() => __wasmfs_unmount(stringToUTF8OnStack(mountpoint))))
354+
FS.handleError(withStackSave(() => _wasmfs_unmount(stringToUTF8OnStack(mountpoint))))
355355
),
356356
// TODO: lookup
357357
mknod: (path, mode, dev) => FS_mknod(path, mode, dev),

system/include/emscripten/wasmfs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern "C" {
1717
typedef struct Backend* backend_t;
1818

1919
// Obtains the backend_t of a specified path.
20-
backend_t wasmfs_get_backend_by_path(char* path __attribute__((nonnull)));
20+
backend_t wasmfs_get_backend_by_path(const char* path __attribute__((nonnull)));
2121

2222
// Obtains the backend_t of a specified fd.
2323
backend_t wasmfs_get_backend_by_fd(int fd);
@@ -36,7 +36,7 @@ int wasmfs_create_directory(const char* path __attribute__((nonnull)), mode_t mo
3636

3737
// Unmounts the directory (Which must be a valid mountpoint) at a specific path.
3838
// Returns 0 on success, or a negative value on error.
39-
int wasmfs_unmount(intptr_t path);
39+
int wasmfs_unmount(const char* path __attribute__((nonnull)));
4040

4141
// Backend creation
4242

system/lib/wasmfs/js_api.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ extern "C" {
2424

2525
// TODO: Replace forward declarations with #include <emscripten/wasmfs.h> and
2626
// resolve wasmfs::backend_t namespace conflicts.
27-
__wasi_fd_t wasmfs_create_file(char* pathname, mode_t mode, backend_t backend);
28-
int wasmfs_create_directory(char* path, int mode, backend_t backend);
29-
int wasmfs_unmount(intptr_t path);
27+
__wasi_fd_t wasmfs_create_file(const char* pathname, mode_t mode, backend_t backend);
28+
int wasmfs_create_directory(const char* path, int mode, backend_t backend);
3029

3130
// Copy the file specified by the pathname into JS.
3231
// Return a pointer to the JS buffer in HEAPU8.
@@ -298,10 +297,6 @@ int _wasmfs_mount(char* path, wasmfs::backend_t created_backend) {
298297
return wasmfs_create_directory(path, 0777, created_backend);
299298
}
300299

301-
// WasmFS will always remove the mounted directory, regardless of if the
302-
// directory existed before.
303-
int _wasmfs_unmount(char* path) { return wasmfs_unmount((intptr_t)path); }
304-
305300
// Helper method that identifies what a path is:
306301
// ENOENT - if nothing exists there
307302
// EISDIR - if it is a directory

system/lib/wasmfs/syscalls.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,8 @@ int __syscall_rmdir(intptr_t path) {
867867

868868
// wasmfs_unmount is similar to __syscall_unlinkat, but assumes AT_REMOVEDIR is
869869
// true and will only unlink mountpoints (Empty and nonempty).
870-
int wasmfs_unmount(intptr_t path) {
871-
auto parsed = path::parseParent((char*)path, AT_FDCWD);
870+
int wasmfs_unmount(const char* path) {
871+
auto parsed = path::parseParent(path, AT_FDCWD);
872872
if (auto err = parsed.getError()) {
873873
return err;
874874
}

tools/link.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,8 @@ def phase_linker_setup(options, linker_args): # noqa: C901, PLR0912, PLR0915
12601260
settings.REQUIRED_EXPORTS += [
12611261
'emscripten_builtin_memalign',
12621262
'wasmfs_create_file',
1263+
'wasmfs_unmount',
12631264
'_wasmfs_mount',
1264-
'_wasmfs_unmount',
12651265
'_wasmfs_read_file',
12661266
'_wasmfs_write_file',
12671267
'_wasmfs_open',

0 commit comments

Comments
 (0)