Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
62 changes: 47 additions & 15 deletions src/lib/libfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,24 @@ FS.staticInit();
stream.stream_ops?.dup?.(stream);
return stream;
},
streamGetAttr(stream) {
var node = stream.node;
var res = stream.stream_ops?.getattr?.(stream) ?? node.node_ops?.getattr?.(node);
if (res) {
return res;
}
throw new FS.ErrnoError({{{ cDefs.EPERM }}});
},
streamSetAttr(stream, attr) {
var node = stream.node;
var set;
if (set = stream.stream_ops.setattr) {
return set(stream, attr);
} else if (set = node.node_ops.setattr) {
return set(node, attr);
}
throw new FS.ErrnoError({{{ cDefs.EPERM }}});
},

//
// devices
Expand Down Expand Up @@ -966,7 +984,8 @@ FS.staticInit();
return getattr(node);
},
fstat(fd) {
return FS.stat(FS.getStreamChecked(fd).path);
var stream = FS.getStreamChecked(fd);
return FS.streamGetAttr(stream);
},
lstat(path) {
return FS.stat(path, true);
Expand All @@ -991,7 +1010,10 @@ FS.staticInit();
},
fchmod(fd, mode) {
var stream = FS.getStreamChecked(fd);
FS.chmod(stream.node, mode);
FS.streamSetAttr(stream, {
mode: (mode & {{{ cDefs.S_IALLUGO }}}) | (stream.node.mode & ~{{{ cDefs.S_IALLUGO }}}),
ctime: Date.now()
});
},
chown(path, uid, gid, dontFollow) {
var node;
Expand All @@ -1013,7 +1035,22 @@ FS.staticInit();
},
fchown(fd, uid, gid) {
var stream = FS.getStreamChecked(fd);
FS.chown(stream.node, uid, gid);
FS.streamSetAttr(stream, {
timestamp: Date.now()
// we ignore the uid / gid for now
});
},
truncateChecks(node) {
if (FS.isDir(node.mode)) {
throw new FS.ErrnoError({{{ cDefs.EISDIR }}});
}
if (!FS.isFile(node.mode)) {
throw new FS.ErrnoError({{{ cDefs.EINVAL }}});
}
var errCode = FS.nodePermissions(node, 'w');
if (errCode) {
throw new FS.ErrnoError(errCode);
}
},
truncate(path, len) {
if (len < 0) {
Expand All @@ -1026,16 +1063,7 @@ FS.staticInit();
} else {
node = path;
}
if (FS.isDir(node.mode)) {
throw new FS.ErrnoError({{{ cDefs.EISDIR }}});
}
if (!FS.isFile(node.mode)) {
throw new FS.ErrnoError({{{ cDefs.EINVAL }}});
}
var errCode = FS.nodePermissions(node, 'w');
if (errCode) {
throw new FS.ErrnoError(errCode);
}
FS.truncateChecks(node);
var setattr = FS.checkOpExists(node.node_ops.setattr, {{{ cDefs.EPERM }}});
setattr(node, {
size: len,
Expand All @@ -1044,10 +1072,14 @@ FS.staticInit();
},
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}}}) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a separate fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah

throw new FS.ErrnoError({{{ cDefs.EINVAL }}});
}
FS.truncate(stream.node, len);
FS.truncateChecks(stream.node);
FS.streamSetAttr(stream, {
size: len,
timestamp: Date.now()
});
},
utime(path, atime, mtime) {
var lookup = FS.lookupPath(path, { follow: true });
Expand Down
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors1.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129218
129211
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors2.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128630
128623
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170886
170879
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except_wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
144715
144708
Original file line number Diff line number Diff line change
@@ -1 +1 @@
142169
142162
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_mangle.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
232731
232724
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_noexcept.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131781
131774
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_wasmfs.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
169188
169181
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O0.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15113
15101
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_pthreads.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19405
19394
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size.wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15113
15101
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_no_asserts.wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12194
12182
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_strict.wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15113
15101
7 changes: 3 additions & 4 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5845,10 +5845,9 @@ 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')
nodefs = '-DNODEFS' in self.emcc_args
if nodefs:
self.skipTest('TODO: doesnt work in nodefs')
self.do_runf('fs/test_stat_unnamed_file_descriptor.c', 'success')

@requires_node
Expand Down
Loading