From f78120ed54978b97a6858dc0e05aedf5f4ed05f0 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 18 Dec 2024 21:07:19 +0100 Subject: [PATCH 1/4] Opening a directory with O_CREAT should return EISDIR --- src/library_fs.js | 4 ++-- test/fcntl/test_fcntl_open.c | 2 +- test/fcntl/test_fcntl_open.out | 16 ++++++++-------- test/test_core.py | 1 + 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/library_fs.js b/src/library_fs.js index ada447d171c18..16cbe49629701 100644 --- a/src/library_fs.js +++ b/src/library_fs.js @@ -426,8 +426,8 @@ FS.staticInit(); if (FS.isLink(node.mode)) { return {{{ cDefs.ELOOP }}}; } else if (FS.isDir(node.mode)) { - if (FS.flagsToPermissionString(flags) !== 'r' || // opening for write - (flags & {{{ cDefs.O_TRUNC }}})) { // TODO: check for O_SEARCH? (== search for dir only) + if (FS.flagsToPermissionString(flags) !== 'r' // opening for write + || (flags & ({{{ cDefs.O_TRUNC }}} | {{{ cDefs.O_CREAT }}}))) { // TODO: check for O_SEARCH? (== search for dir only) return {{{ cDefs.EISDIR }}}; } } diff --git a/test/fcntl/test_fcntl_open.c b/test/fcntl/test_fcntl_open.c index 0f48c9c17a974..a34de9ea676a2 100644 --- a/test/fcntl/test_fcntl_open.c +++ b/test/fcntl/test_fcntl_open.c @@ -78,7 +78,7 @@ void test() { if ((flags & O_CREAT) && (flags & O_EXCL)) { assert(!success); assert(errno == EEXIST); - } else if ((flags & O_TRUNC) || i != 0 /*mode != O_RDONLY*/) { + } else if ((flags & O_TRUNC) || i != 0 /*mode != O_RDONLY*/ || (flags & O_CREAT)) { assert(!success); assert(errno == EISDIR); } else { diff --git a/test/fcntl/test_fcntl_open.out b/test/fcntl/test_fcntl_open.out index f510e40657a78..19938d6ca9642 100644 --- a/test/fcntl/test_fcntl_open.out +++ b/test/fcntl/test_fcntl_open.out @@ -19,8 +19,8 @@ errno: 0 st_mode: 0100000 EXISTING FOLDER 0,1 -success: 1 -errno: 0 +success: 0 +errno: 31 st_mode: 040000 NON-EXISTING 0,1 @@ -139,8 +139,8 @@ errno: 0 st_mode: 0100000 EXISTING FOLDER 0,9 -success: 1 -errno: 0 +success: 0 +errno: 31 st_mode: 040000 NON-EXISTING 0,9 @@ -259,8 +259,8 @@ errno: 0 st_mode: 0100000 EXISTING FOLDER 0,17 -success: 1 -errno: 0 +success: 0 +errno: 31 st_mode: 040000 NON-EXISTING 0,17 @@ -379,8 +379,8 @@ errno: 0 st_mode: 0100000 EXISTING FOLDER 0,25 -success: 1 -errno: 0 +success: 0 +errno: 31 st_mode: 040000 NON-EXISTING 0,25 diff --git a/test/test_core.py b/test/test_core.py index cbdf449ec1d0e..0197c4da991b9 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -5545,6 +5545,7 @@ def test_fcntl(self): self.add_pre_run("FS.createDataFile('/', 'test', 'abcdef', true, true, false);") self.do_run_in_out_file_test('fcntl/test_fcntl.c') + @also_with_nodefs_both def test_fcntl_open(self): self.do_run_in_out_file_test('fcntl/test_fcntl_open.c') From 109cd2ad14b6cf65440c2237019ab3cbdb109224 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 18 Dec 2024 23:25:17 +0100 Subject: [PATCH 2/4] Fix test on wasmfs too --- system/lib/wasmfs/syscalls.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/lib/wasmfs/syscalls.cpp b/system/lib/wasmfs/syscalls.cpp index 82e3e9d6e0324..94ad74b6595bd 100644 --- a/system/lib/wasmfs/syscalls.cpp +++ b/system/lib/wasmfs/syscalls.cpp @@ -520,7 +520,7 @@ static __wasi_fd_t doOpen(path::ParsedParent parsed, return -EEXIST; } - if (child->is() && accessMode != O_RDONLY) { + if (child->is() && (accessMode != O_RDONLY || (flags & O_CREAT))) { return -EISDIR; } From e5bb943bf41dad827993cbb1785896975c74422b Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 19 Dec 2024 11:11:48 +0100 Subject: [PATCH 3/4] Automatic rebaseline of codesize expectations. NFC This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (9) test expectation files were updated by running the tests with `--rebaseline`: ``` other/codesize/test_codesize_cxx_ctors1.gzsize: 8351 => 8355 [+4 bytes / +0.05%] other/codesize/test_codesize_cxx_ctors2.gzsize: 8334 => 8337 [+3 bytes / +0.04%] other/codesize/test_codesize_cxx_except.gzsize: 9356 => 9357 [+1 bytes / +0.01%] other/codesize/test_codesize_cxx_except_wasm.gzsize: 8321 => 8323 [+2 bytes / +0.02%] other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize: 8321 => 8323 [+2 bytes / +0.02%] other/codesize/test_codesize_cxx_lto.gzsize: 8347 => 8349 [+2 bytes / +0.02%] other/codesize/test_codesize_cxx_mangle.gzsize: 9359 => 9361 [+2 bytes / +0.02%] other/codesize/test_codesize_cxx_noexcept.gzsize: 8351 => 8355 [+4 bytes / +0.05%] other/codesize/test_codesize_files_js_fs.gzsize: 7654 => 7656 [+2 bytes / +0.03%] Average change: +0.03% (+0.01% - +0.05%) ``` --- test/other/codesize/test_codesize_cxx_ctors1.gzsize | 2 +- test/other/codesize/test_codesize_cxx_ctors2.gzsize | 2 +- test/other/codesize/test_codesize_cxx_except.gzsize | 2 +- test/other/codesize/test_codesize_cxx_except_wasm.gzsize | 2 +- test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize | 2 +- test/other/codesize/test_codesize_cxx_lto.gzsize | 2 +- test/other/codesize/test_codesize_cxx_mangle.gzsize | 2 +- test/other/codesize/test_codesize_cxx_noexcept.gzsize | 2 +- test/other/codesize/test_codesize_files_js_fs.gzsize | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/other/codesize/test_codesize_cxx_ctors1.gzsize b/test/other/codesize/test_codesize_cxx_ctors1.gzsize index 7c05c8455e746..3f69d1fa06d1e 100644 --- a/test/other/codesize/test_codesize_cxx_ctors1.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors1.gzsize @@ -1 +1 @@ -8351 +8355 diff --git a/test/other/codesize/test_codesize_cxx_ctors2.gzsize b/test/other/codesize/test_codesize_cxx_ctors2.gzsize index e7f2f2aa09e70..1d7bdf0051254 100644 --- a/test/other/codesize/test_codesize_cxx_ctors2.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors2.gzsize @@ -1 +1 @@ -8334 +8337 diff --git a/test/other/codesize/test_codesize_cxx_except.gzsize b/test/other/codesize/test_codesize_cxx_except.gzsize index 26f242e26fb55..0888a57fbd1bb 100644 --- a/test/other/codesize/test_codesize_cxx_except.gzsize +++ b/test/other/codesize/test_codesize_cxx_except.gzsize @@ -1 +1 @@ -9356 +9357 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize index f14ddc132870a..98bbca6500918 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize @@ -1 +1 @@ -8321 +8323 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize index f14ddc132870a..98bbca6500918 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize @@ -1 +1 @@ -8321 +8323 diff --git a/test/other/codesize/test_codesize_cxx_lto.gzsize b/test/other/codesize/test_codesize_cxx_lto.gzsize index a665dbc2e401e..c24db41a3eb53 100644 --- a/test/other/codesize/test_codesize_cxx_lto.gzsize +++ b/test/other/codesize/test_codesize_cxx_lto.gzsize @@ -1 +1 @@ -8347 +8349 diff --git a/test/other/codesize/test_codesize_cxx_mangle.gzsize b/test/other/codesize/test_codesize_cxx_mangle.gzsize index 886a28e6c91b7..be24a385bb8fd 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.gzsize +++ b/test/other/codesize/test_codesize_cxx_mangle.gzsize @@ -1 +1 @@ -9359 +9361 diff --git a/test/other/codesize/test_codesize_cxx_noexcept.gzsize b/test/other/codesize/test_codesize_cxx_noexcept.gzsize index 7c05c8455e746..3f69d1fa06d1e 100644 --- a/test/other/codesize/test_codesize_cxx_noexcept.gzsize +++ b/test/other/codesize/test_codesize_cxx_noexcept.gzsize @@ -1 +1 @@ -8351 +8355 diff --git a/test/other/codesize/test_codesize_files_js_fs.gzsize b/test/other/codesize/test_codesize_files_js_fs.gzsize index 309e97c7a9f6c..a6589474f60cb 100644 --- a/test/other/codesize/test_codesize_files_js_fs.gzsize +++ b/test/other/codesize/test_codesize_files_js_fs.gzsize @@ -1 +1 @@ -7654 +7656 From 0ddcca2bec632af53c4fa2a2ac6ea6be61f2d6a6 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 19 Dec 2024 14:52:26 +0100 Subject: [PATCH 4/4] Automatic rebaseline of codesize expectations. NFC This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (9) test expectation files were updated by running the tests with `--rebaseline`: ``` other/codesize/test_codesize_cxx_ctors1.gzsize: 8407 => 8408 [+1 bytes / +0.01%] other/codesize/test_codesize_cxx_ctors2.gzsize: 8390 => 8392 [+2 bytes / +0.02%] other/codesize/test_codesize_cxx_except.gzsize: 9411 => 9413 [+2 bytes / +0.02%] other/codesize/test_codesize_cxx_except_wasm.gzsize: 8373 => 8374 [+1 bytes / +0.01%] other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize: 8373 => 8374 [+1 bytes / +0.01%] other/codesize/test_codesize_cxx_lto.gzsize: 8404 => 8406 [+2 bytes / +0.02%] other/codesize/test_codesize_cxx_mangle.gzsize: 9416 => 9417 [+1 bytes / +0.01%] other/codesize/test_codesize_cxx_noexcept.gzsize: 8407 => 8408 [+1 bytes / +0.01%] other/codesize/test_codesize_files_js_fs.gzsize: 7702 => 7704 [+2 bytes / +0.03%] Average change: +0.02% (+0.01% - +0.03%) ``` --- test/other/codesize/test_codesize_cxx_ctors1.gzsize | 2 +- test/other/codesize/test_codesize_cxx_ctors2.gzsize | 2 +- test/other/codesize/test_codesize_cxx_except.gzsize | 2 +- test/other/codesize/test_codesize_cxx_except_wasm.gzsize | 2 +- test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize | 2 +- test/other/codesize/test_codesize_cxx_lto.gzsize | 2 +- test/other/codesize/test_codesize_cxx_mangle.gzsize | 2 +- test/other/codesize/test_codesize_cxx_noexcept.gzsize | 2 +- test/other/codesize/test_codesize_files_js_fs.gzsize | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/other/codesize/test_codesize_cxx_ctors1.gzsize b/test/other/codesize/test_codesize_cxx_ctors1.gzsize index 4be81cb9fb3af..b2fd8c7b992c7 100644 --- a/test/other/codesize/test_codesize_cxx_ctors1.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors1.gzsize @@ -1 +1 @@ -8407 +8408 diff --git a/test/other/codesize/test_codesize_cxx_ctors2.gzsize b/test/other/codesize/test_codesize_cxx_ctors2.gzsize index a559385da7f91..cdc91cd424110 100644 --- a/test/other/codesize/test_codesize_cxx_ctors2.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors2.gzsize @@ -1 +1 @@ -8390 +8392 diff --git a/test/other/codesize/test_codesize_cxx_except.gzsize b/test/other/codesize/test_codesize_cxx_except.gzsize index d2e5ea2910cc9..199a0b963f1ab 100644 --- a/test/other/codesize/test_codesize_cxx_except.gzsize +++ b/test/other/codesize/test_codesize_cxx_except.gzsize @@ -1 +1 @@ -9411 +9413 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize index 2a12540f0635f..0b2a5d20da7ef 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize @@ -1 +1 @@ -8373 +8374 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize index 2a12540f0635f..0b2a5d20da7ef 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize @@ -1 +1 @@ -8373 +8374 diff --git a/test/other/codesize/test_codesize_cxx_lto.gzsize b/test/other/codesize/test_codesize_cxx_lto.gzsize index 5f41444ba9dcc..9fa65500fcae8 100644 --- a/test/other/codesize/test_codesize_cxx_lto.gzsize +++ b/test/other/codesize/test_codesize_cxx_lto.gzsize @@ -1 +1 @@ -8404 +8406 diff --git a/test/other/codesize/test_codesize_cxx_mangle.gzsize b/test/other/codesize/test_codesize_cxx_mangle.gzsize index 54e18a6e2baed..b92fe18e229cc 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.gzsize +++ b/test/other/codesize/test_codesize_cxx_mangle.gzsize @@ -1 +1 @@ -9416 +9417 diff --git a/test/other/codesize/test_codesize_cxx_noexcept.gzsize b/test/other/codesize/test_codesize_cxx_noexcept.gzsize index 4be81cb9fb3af..b2fd8c7b992c7 100644 --- a/test/other/codesize/test_codesize_cxx_noexcept.gzsize +++ b/test/other/codesize/test_codesize_cxx_noexcept.gzsize @@ -1 +1 @@ -8407 +8408 diff --git a/test/other/codesize/test_codesize_files_js_fs.gzsize b/test/other/codesize/test_codesize_files_js_fs.gzsize index c3a0b57749871..3eb330568eb87 100644 --- a/test/other/codesize/test_codesize_files_js_fs.gzsize +++ b/test/other/codesize/test_codesize_files_js_fs.gzsize @@ -1 +1 @@ -7702 +7704