Title: wasmfs_create_directory applies umask to an explicit OPFS mount mode
Emscripten 6.0.9 regresses OPFS directory creation compared with 5.0.2.
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 6.0.9 (37ba36c504c3223ed69f18d0584267134f3bfc8b)
clang version 24.0.0git (https:/github.com/llvm/llvm-project 510126255f89d693717c1ce7105b593f995f07c1)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /Users/richardgillaspy/GitHub/emsdk/upstream/bin
Failing command line in full:
This is a runtime failure. The standalone reproducer is
test/wasmfs/wasmfs_opfs_umask.c.
emcc test/wasmfs/wasmfs_opfs_umask.c -sWASMFS -pthread -sPROXY_TO_PTHREAD -o wasmfs_opfs_umask.html
emrun --no-browser --port 8889 wasmfs_opfs_umask.html
Steps to reproduce:
- Serve wasmfs_opfs_umask.html from localhost and open it in Chrome.
- The program sets umask to 0777.
- The program mounts OPFS at /opfs with wasmfs_create_directory("/opfs",
0777, wasmfs_create_opfs_backend()).
- The program restores its previous umask and creates /opfs/child.
Actual output in unpatched 6.0.9:
/opfs mode: 0
program exited (with status: 1)
Removing the mode assertion produces the underlying failing operation:
mkdir /opfs/child: Permission denied
program exited (with status: 2)
Expected result:
wasmfs_create_directory should preserve its explicit mode argument. /opfs
should have mode 0777, and mkdir("/opfs/child", 0777) should succeed.
Full link command and output with -v appended:
The command completes successfully. Its final link invocation is:
/Users/richardgillaspy/GitHub/emsdk/upstream/bin/wasm-ld -o /tmp/wasmfs_opfs_umask.wasm /var/folders/d8/08bv2b6s2b50q04__ln3cmbh0000gp/T/tmp6v7y7syolibemscripten_js_symbols.so -Bstatic --import-memory --shared-memory --strip-debug --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=wasmfs_flush --export=_emscripten_stack_alloc --export=_emscripten_thread_free_data --export=_emscripten_thread_crashed --export=__wasm_call_ctors --export=_emscripten_tls_init --export=_emscripten_thread_init --export=pthread_self --export=__set_thread_state --export=_emscripten_stack_restore --export=emscripten_stack_set_limits --export=_emscripten_thread_exit --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=65536 --no-growable-memory --initial-memory=16777216 --entry=_emscripten_proxy_main --stack-first --table-base=1 /var/folders/d8/08bv2b6s2b50q04__ln3cmbh0000gp/T/emscripten_temp_39r5o57r/wasmfs_opfs_umask.o -L/Users/richardgillaspy/GitHub/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -L/Users/richardgillaspy/GitHub/emsdk/upstream/emscripten/src/lib /Users/richardgillaspy/GitHub/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/crtbegin-mt.o /Users/richardgillaspy/GitHub/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/crt1_proxy_main.o -lGL-mt-getprocaddr -lal -lhtml5 -lstubs-debug -lnoexit -lc-mt-debug -ldlmalloc-mt-debug -lclang_rt.builtins-mt -lc++-debug-mt-noexcept -lc++abi-debug-mt-noexcept -lsockets-mt -lwasmfs_no_fs -lwasmfs-mt-debug -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr
Output:
No linker diagnostics. Exit status: 0.
The full command that produced this verbose link output is:
emcc -v test/wasmfs/wasmfs_opfs_umask.c -sWASMFS -pthread -sPROXY_TO_PTHREAD -o wasmfs_opfs_umask.html
Regression source:
Commit 94f825e ("Fix umask being ignored on file creation") began
applying the process umask in doMkdir. wasmfs_create_directory uses doMkdir
for backend mount points, so its explicit mode argument is now masked.
Proposed fix:
Continue applying umask to POSIX mkdir and mkdirat calls, but bypass it for
wasmfs_create_directory, whose mode is explicitly supplied by the caller.
wasmfs_opfs_umask_defect.txt
Title: wasmfs_create_directory applies umask to an explicit OPFS mount mode
Emscripten 6.0.9 regresses OPFS directory creation compared with 5.0.2.
Version of emscripten/emsdk:
Failing command line in full:
This is a runtime failure. The standalone reproducer is
test/wasmfs/wasmfs_opfs_umask.c.Steps to reproduce:
0777, wasmfs_create_opfs_backend()).
Actual output in unpatched 6.0.9:
Removing the mode assertion produces the underlying failing operation:
Expected result:
wasmfs_create_directory should preserve its explicit mode argument. /opfs
should have mode 0777, and mkdir("/opfs/child", 0777) should succeed.
Full link command and output with
-vappended:The command completes successfully. Its final link invocation is:
Output:
The full command that produced this verbose link output is:
Regression source:
Commit 94f825e ("Fix umask being ignored on file creation") began
applying the process umask in doMkdir. wasmfs_create_directory uses doMkdir
for backend mount points, so its explicit mode argument is now masked.
Proposed fix:
Continue applying umask to POSIX mkdir and mkdirat calls, but bypass it for
wasmfs_create_directory, whose mode is explicitly supplied by the caller.
wasmfs_opfs_umask_defect.txt