-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Make fstat work on file descriptor with no name #23058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
f3f36d5
260278f
f865bdb
cac8b19
cad0ddf
8b1711e
c961354
bebfc6b
7f4533e
2c41571
6a4dfc2
9d0c79a
baadd84
3aa358f
04192f0
989cf22
ad02402
84bcf30
ba35730
4e67e7f
9399402
7593dc1
efff804
20de480
e83ac75
b509358
8c556c8
4ed8004
bdfca83
4fdc681
ddb3fab
bfd07c7
5d4c6d2
ac100ab
d1f1962
02e0b69
910b824
37f8ee9
5eef321
ad6f42a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -938,6 +938,16 @@ FS.staticInit(); | |
} | ||
return node.node_ops.getattr(node); | ||
}, | ||
fstat(fd) { | ||
var stream = FS.getStreamChecked(fd); | ||
var node = stream.node; | ||
if (stream.stream_ops.getattr) { | ||
return stream.stream_ops.getattr(stream); | ||
} else if (node.node_ops.getattr) { | ||
return node.node_ops.getattr(node); | ||
} | ||
throw new FS.ErrnoError({{{ cDefs.EPERM }}}); | ||
}, | ||
lstat(path) { | ||
return FS.stat(path, true); | ||
}, | ||
|
@@ -962,7 +972,17 @@ FS.staticInit(); | |
}, | ||
fchmod(fd, mode) { | ||
var stream = FS.getStreamChecked(fd); | ||
FS.chmod(stream.node, mode); | ||
var node = stream.node; | ||
var attrs = { | ||
mode: (mode & {{{ cDefs.S_IALLUGO }}}) | (node.mode & ~{{{ cDefs.S_IALLUGO }}}), | ||
ctime: Date.now() | ||
}; | ||
if (stream.stream_ops.getattr) { | ||
return stream.stream_ops.setattr(stream, attrs); | ||
} else if (node.node_ops.getattr) { | ||
return node.node_ops.setattr(node, attrs); | ||
} | ||
throw new FS.ErrnoError({{{ cDefs.EPERM }}}); | ||
}, | ||
chown(path, uid, gid, dontFollow) { | ||
var node; | ||
|
@@ -985,20 +1005,37 @@ FS.staticInit(); | |
}, | ||
fchown(fd, uid, gid) { | ||
var stream = FS.getStreamChecked(fd); | ||
FS.chown(stream.node, uid, gid); | ||
var node = stream.node; | ||
var attrs = { | ||
timestamp: Date.now() | ||
// we ignore the uid / gid for now | ||
}; | ||
if (stream.stream_ops.getattr) { | ||
return stream.stream_ops.setattr(stream, attrs); | ||
} else if (node.node_ops.getattr) { | ||
return node.node_ops.setattr(node, attrs); | ||
} | ||
throw new FS.ErrnoError({{{ cDefs.EPERM }}}); | ||
}, | ||
truncate(path, len) { | ||
truncateCommon(arg, len, ftruncate) { | ||
if (len < 0) { | ||
throw new FS.ErrnoError({{{ cDefs.EINVAL }}}); | ||
} | ||
var node; | ||
if (typeof path == 'string') { | ||
var lookup = FS.lookupPath(path, { follow: true }); | ||
var stream; | ||
if (ftruncate) { | ||
stream = FS.getStreamChecked(arg); | ||
if ((stream.flags & {{{ cDefs.O_ACCMODE }}}) === {{{ cDefs.O_RDONLY}}}) { | ||
throw new FS.ErrnoError({{{ cDefs.EINVAL }}}); | ||
} | ||
node = stream.node; | ||
} else if (typeof arg == 'string') { | ||
var lookup = FS.lookupPath(arg, { follow: true }); | ||
node = lookup.node; | ||
} else { | ||
node = path; | ||
node = arg; | ||
} | ||
if (!node.node_ops.setattr) { | ||
if (!node.node_ops.setattr && !stream?.stream_ops.setattr) { | ||
throw new FS.ErrnoError({{{ cDefs.EPERM }}}); | ||
} | ||
if (FS.isDir(node.mode)) { | ||
|
@@ -1011,17 +1048,21 @@ FS.staticInit(); | |
if (errCode) { | ||
throw new FS.ErrnoError(errCode); | ||
} | ||
node.node_ops.setattr(node, { | ||
var attrs = { | ||
size: len, | ||
timestamp: Date.now() | ||
}); | ||
}; | ||
if (stream?.stream_ops.setattr) { | ||
stream.stream_ops.setattr(stream, attrs); | ||
} else { | ||
node.node_ops.setattr(node, attrs); | ||
|
||
} | ||
hoodmane marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
}, | ||
truncate(path, len) { | ||
FS.truncateCommon(path, len, false); | ||
}, | ||
ftruncate(fd, len) { | ||
var stream = FS.getStreamChecked(fd); | ||
if ((stream.flags & {{{ cDefs.O_ACCMODE }}}) === {{{ cDefs.O_RDONLY}}}) { | ||
throw new FS.ErrnoError({{{ cDefs.EINVAL }}}); | ||
} | ||
FS.truncate(stream.node, len); | ||
FS.truncateCommon(fd, len, true); | ||
}, | ||
utime(path, atime, mtime) { | ||
var lookup = FS.lookupPath(path, { follow: true }); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <sys/stat.h> | ||
#include <assert.h> | ||
#include "stdio.h" | ||
|
||
#ifdef __EMSCRIPTEN__ | ||
#include <emscripten.h> | ||
#endif | ||
|
||
void makedir(const char *dir) { | ||
int rtn = mkdir(dir, 0777); | ||
assert(rtn == 0); | ||
} | ||
|
||
void changedir(const char *dir) { | ||
int rtn = chdir(dir); | ||
assert(rtn == 0); | ||
} | ||
|
||
void setup() { | ||
#if defined(__EMSCRIPTEN__) && defined(NODEFS) | ||
makedir("working"); | ||
EM_ASM(FS.mount(NODEFS, { root: '.' }, 'working')); | ||
changedir("working"); | ||
#endif | ||
} | ||
hoodmane marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
|
||
int main() { | ||
setup(); | ||
int fd = open("file.txt", O_RDWR | O_CREAT, 0666); | ||
unlink("file.txt"); | ||
int res; | ||
struct stat buf; | ||
res = fstat(fd, &buf); | ||
assert(res == 0); | ||
assert(buf.st_atime > 1000000000); | ||
res = fchmod(fd, 0777); | ||
assert(res == 0); | ||
res = ftruncate(fd, 10); | ||
assert(res == 0); | ||
printf("success\n"); | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5874,6 +5874,20 @@ def test_fs_64bit(self): | |||||
self.set_setting('FORCE_FILESYSTEM') | ||||||
self.do_runf('fs/test_64bit.c', 'success') | ||||||
|
||||||
@requires_node | ||||||
@parameterized({ | ||||||
'': ([],), | ||||||
'nodefs': (['-DNODEFS', '-lnodefs.js'],), | ||||||
'noderawfs': (['-sNODERAWFS'],), | ||||||
}) | ||||||
hoodmane marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
def test_fs_stat_unnamed_file_descriptor(self, args): | ||||||
|
def test_fs_stat_unnamed_file_descriptor(self, args): | |
def test_fs_stat_unnamed_file_descriptor(self): |
Uh oh!
There was an error while loading. Please reload this page.