diff --git a/src/lib/libfs.js b/src/lib/libfs.js index e446b5791d060..024629adf6df1 100644 --- a/src/lib/libfs.js +++ b/src/lib/libfs.js @@ -487,6 +487,13 @@ FS.staticInit(); stream.stream_ops?.dup?.(stream); return stream; }, + doSetAttr(stream, node, attr) { + var setattr = stream?.stream_ops.setattr; + var arg = setattr ? stream : node; + setattr ??= node.node_ops.setattr; + FS.checkOpExists(setattr, {{{ cDefs.EPERM }}}) + setattr(arg, attr); + }, // // devices @@ -966,11 +973,24 @@ FS.staticInit(); return getattr(node); }, fstat(fd) { - return FS.stat(FS.getStreamChecked(fd).path); + var stream = FS.getStreamChecked(fd); + var node = stream.node; + var getattr = stream.stream_ops.getattr; + var arg = getattr ? stream : node; + getattr ??= node.node_ops.getattr; + FS.checkOpExists(getattr, {{{ cDefs.EPERM }}}) + return getattr(arg); }, lstat(path) { return FS.stat(path, true); }, + doChmod(stream, node, mode, dontFollow) { + FS.doSetAttr(stream, node, { + mode: (mode & {{{ cDefs.S_IALLUGO }}}) | (node.mode & ~{{{ cDefs.S_IALLUGO }}}), + ctime: Date.now(), + dontFollow + }); + }, chmod(path, mode, dontFollow) { var node; if (typeof path == 'string') { @@ -979,19 +999,21 @@ FS.staticInit(); } else { node = path; } - var setattr = FS.checkOpExists(node.node_ops.setattr, {{{ cDefs.EPERM }}}); - setattr(node, { - mode: (mode & {{{ cDefs.S_IALLUGO }}}) | (node.mode & ~{{{ cDefs.S_IALLUGO }}}), - ctime: Date.now(), - dontFollow - }); + FS.doChmod(null, node, mode, dontFollow); }, lchmod(path, mode) { FS.chmod(path, mode, true); }, fchmod(fd, mode) { var stream = FS.getStreamChecked(fd); - FS.chmod(stream.node, mode); + FS.doChmod(stream, stream.node, mode, false); + }, + doChown(stream, node, dontFollow) { + FS.doSetAttr(stream, node, { + timestamp: Date.now(), + dontFollow + // we ignore the uid / gid for now + }); }, chown(path, uid, gid, dontFollow) { var node; @@ -1001,31 +1023,16 @@ FS.staticInit(); } else { node = path; } - var setattr = FS.checkOpExists(node.node_ops.setattr, {{{ cDefs.EPERM }}}); - setattr(node, { - timestamp: Date.now(), - dontFollow - // we ignore the uid / gid for now - }); + FS.doChown(null, node, dontFollow); }, lchown(path, uid, gid) { FS.chown(path, uid, gid, true); }, fchown(fd, uid, gid) { var stream = FS.getStreamChecked(fd); - FS.chown(stream.node, uid, gid); + FS.doChown(stream, stream.node, false); }, - truncate(path, len) { - if (len < 0) { - throw new FS.ErrnoError({{{ cDefs.EINVAL }}}); - } - var node; - if (typeof path == 'string') { - var lookup = FS.lookupPath(path, { follow: true }); - node = lookup.node; - } else { - node = path; - } + doTruncate(stream, node, len) { if (FS.isDir(node.mode)) { throw new FS.ErrnoError({{{ cDefs.EISDIR }}}); } @@ -1036,18 +1043,30 @@ FS.staticInit(); if (errCode) { throw new FS.ErrnoError(errCode); } - var setattr = FS.checkOpExists(node.node_ops.setattr, {{{ cDefs.EPERM }}}); - setattr(node, { + FS.doSetAttr(stream, node, { size: len, timestamp: Date.now() }); }, + truncate(path, len) { + if (len < 0) { + throw new FS.ErrnoError({{{ cDefs.EINVAL }}}); + } + var node; + if (typeof path == 'string') { + var lookup = FS.lookupPath(path, { follow: true }); + node = lookup.node; + } else { + node = path; + } + FS.doTruncate(null, node, len); + }, ftruncate(fd, len) { var stream = FS.getStreamChecked(fd); - if ((stream.flags & {{{ cDefs.O_ACCMODE }}}) === {{{ cDefs.O_RDONLY}}}) { + if (len < 0 || (stream.flags & {{{ cDefs.O_ACCMODE }}}) === {{{ cDefs.O_RDONLY}}}) { throw new FS.ErrnoError({{{ cDefs.EINVAL }}}); } - FS.truncate(stream.node, len); + FS.doTruncate(stream, stream.node, len); }, utime(path, atime, mtime) { var lookup = FS.lookupPath(path, { follow: true }); diff --git a/test/other/codesize/test_codesize_cxx_ctors1.gzsize b/test/other/codesize/test_codesize_cxx_ctors1.gzsize index cbcd6490a2762..665f0801b8460 100644 --- a/test/other/codesize/test_codesize_cxx_ctors1.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors1.gzsize @@ -1 +1 @@ -8343 +8359 diff --git a/test/other/codesize/test_codesize_cxx_ctors1.jssize b/test/other/codesize/test_codesize_cxx_ctors1.jssize index cfadcdff8168b..dcd85c88b6894 100644 --- a/test/other/codesize/test_codesize_cxx_ctors1.jssize +++ b/test/other/codesize/test_codesize_cxx_ctors1.jssize @@ -1 +1 @@ -20273 +20296 diff --git a/test/other/codesize/test_codesize_cxx_ctors2.gzsize b/test/other/codesize/test_codesize_cxx_ctors2.gzsize index 09ccded12e2c4..66e7b083aee8d 100644 --- a/test/other/codesize/test_codesize_cxx_ctors2.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors2.gzsize @@ -1 +1 @@ -8327 +8341 diff --git a/test/other/codesize/test_codesize_cxx_ctors2.jssize b/test/other/codesize/test_codesize_cxx_ctors2.jssize index 27ff70803812b..6ddb211dca615 100644 --- a/test/other/codesize/test_codesize_cxx_ctors2.jssize +++ b/test/other/codesize/test_codesize_cxx_ctors2.jssize @@ -1 +1 @@ -20241 +20264 diff --git a/test/other/codesize/test_codesize_cxx_except.gzsize b/test/other/codesize/test_codesize_cxx_except.gzsize index a14be756fbbb7..1e8ce7e708846 100644 --- a/test/other/codesize/test_codesize_cxx_except.gzsize +++ b/test/other/codesize/test_codesize_cxx_except.gzsize @@ -1 +1 @@ -9343 +9358 diff --git a/test/other/codesize/test_codesize_cxx_except.jssize b/test/other/codesize/test_codesize_cxx_except.jssize index 37b5c20b7dff5..0e228646c0b6b 100644 --- a/test/other/codesize/test_codesize_cxx_except.jssize +++ b/test/other/codesize/test_codesize_cxx_except.jssize @@ -1 +1 @@ -24041 +24064 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize index 116ecc04e8d72..fdfce512935fd 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize @@ -1 +1 @@ -8294 +8303 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.jssize b/test/other/codesize/test_codesize_cxx_except_wasm.jssize index e2819c5beac21..d5ae56906ffd8 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.jssize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.jssize @@ -1 +1 @@ -20166 +20189 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_legacy.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm_legacy.gzsize index 116ecc04e8d72..fdfce512935fd 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm_legacy.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm_legacy.gzsize @@ -1 +1 @@ -8294 +8303 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_legacy.jssize b/test/other/codesize/test_codesize_cxx_except_wasm_legacy.jssize index e2819c5beac21..d5ae56906ffd8 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm_legacy.jssize +++ b/test/other/codesize/test_codesize_cxx_except_wasm_legacy.jssize @@ -1 +1 @@ -20166 +20189 diff --git a/test/other/codesize/test_codesize_cxx_lto.gzsize b/test/other/codesize/test_codesize_cxx_lto.gzsize index b57252391c66a..838456015747a 100644 --- a/test/other/codesize/test_codesize_cxx_lto.gzsize +++ b/test/other/codesize/test_codesize_cxx_lto.gzsize @@ -1 +1 @@ -8357 +8372 diff --git a/test/other/codesize/test_codesize_cxx_lto.jssize b/test/other/codesize/test_codesize_cxx_lto.jssize index e5351bb2b3ec6..6525ff13db521 100644 --- a/test/other/codesize/test_codesize_cxx_lto.jssize +++ b/test/other/codesize/test_codesize_cxx_lto.jssize @@ -1 +1 @@ -20348 +20371 diff --git a/test/other/codesize/test_codesize_cxx_mangle.gzsize b/test/other/codesize/test_codesize_cxx_mangle.gzsize index 217ff0cc7646e..703c19eb3e692 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.gzsize +++ b/test/other/codesize/test_codesize_cxx_mangle.gzsize @@ -1 +1 @@ -9349 +9364 diff --git a/test/other/codesize/test_codesize_cxx_mangle.jssize b/test/other/codesize/test_codesize_cxx_mangle.jssize index 37b5c20b7dff5..0e228646c0b6b 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.jssize +++ b/test/other/codesize/test_codesize_cxx_mangle.jssize @@ -1 +1 @@ -24041 +24064 diff --git a/test/other/codesize/test_codesize_cxx_noexcept.gzsize b/test/other/codesize/test_codesize_cxx_noexcept.gzsize index cbcd6490a2762..665f0801b8460 100644 --- a/test/other/codesize/test_codesize_cxx_noexcept.gzsize +++ b/test/other/codesize/test_codesize_cxx_noexcept.gzsize @@ -1 +1 @@ -8343 +8359 diff --git a/test/other/codesize/test_codesize_cxx_noexcept.jssize b/test/other/codesize/test_codesize_cxx_noexcept.jssize index cfadcdff8168b..dcd85c88b6894 100644 --- a/test/other/codesize/test_codesize_cxx_noexcept.jssize +++ b/test/other/codesize/test_codesize_cxx_noexcept.jssize @@ -1 +1 @@ -20273 +20296 diff --git a/test/other/codesize/test_codesize_files_js_fs.gzsize b/test/other/codesize/test_codesize_files_js_fs.gzsize index c9ebb127902ab..ba670482b35ee 100644 --- a/test/other/codesize/test_codesize_files_js_fs.gzsize +++ b/test/other/codesize/test_codesize_files_js_fs.gzsize @@ -1 +1 @@ -7647 +7669 diff --git a/test/other/codesize/test_codesize_files_js_fs.jssize b/test/other/codesize/test_codesize_files_js_fs.jssize index 1862f08cb9bd4..2b8c85f745e99 100644 --- a/test/other/codesize/test_codesize_files_js_fs.jssize +++ b/test/other/codesize/test_codesize_files_js_fs.jssize @@ -1 +1 @@ -18820 +18843 diff --git a/test/test_core.py b/test/test_core.py index ad64bda589ce2..0af90dd86f384 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -5845,10 +5845,8 @@ def test_fs_64bit(self): @crossplatform @with_all_fs def test_fs_stat_unnamed_file_descriptor(self): - noderawfs = '-DNODERAWFS' in self.emcc_args - wasmfs = self.get_setting('WASMFS') - if not (noderawfs or wasmfs): - self.skipTest('TODO: doesnt work in memfs or nodefs') + if '-DNODEFS' in self.emcc_args: + self.skipTest('TODO: doesnt work in nodefs') self.do_runf('fs/test_stat_unnamed_file_descriptor.c', 'success') @requires_node diff --git a/test/unistd/dup.c b/test/unistd/dup.c index 7447ac46dcb2b..dcc737c3b819c 100644 --- a/test/unistd/dup.c +++ b/test/unistd/dup.c @@ -102,8 +102,8 @@ int main() { printf("DUP truncate\n"); f = open("./blah.txt", O_RDWR, 0600); - f2 = dup(f); assert(f != -1); + f2 = dup(f); assert(f2 != -1); rtn = ftruncate(f2, 0); assert(rtn == 0);