Skip to content

Commit 9d4abe8

Browse files
authored
[FS] Make fstat work on file descriptors with no name in node rawfs (#23364)
This fixes fstat on "anonymous" file descriptors in node rawfs. It is split off from #23058.
1 parent 61c9bd2 commit 9d4abe8

18 files changed

+50
-15
lines changed

src/lib/libfs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,9 @@ FS.staticInit();
965965
var getattr = FS.checkOpExists(node.node_ops.getattr, {{{ cDefs.EPERM }}});
966966
return getattr(node);
967967
},
968+
fstat(fd) {
969+
return FS.stat(FS.getStreamChecked(fd).path);
970+
},
968971
lstat(path) {
969972
return FS.stat(path, true);
970973
},

src/lib/libnoderawfs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ addToLibrary({
8080
}
8181
return stat;
8282
},
83+
fstat(fd) {
84+
var stream = FS.getStreamChecked(fd);
85+
return fs.fstatSync(stream.nfd);
86+
},
8387
statfsStream(stream) {
8488
return fs.statfsSync(stream.path);
8589
},

src/lib/libsyscall.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,7 @@ var SyscallsLibrary = {
690690
return SYSCALLS.writeStat(buf, FS.lstat(path));
691691
},
692692
__syscall_fstat64: (fd, buf) => {
693-
var stream = SYSCALLS.getStreamFromFD(fd);
694-
return SYSCALLS.writeStat(buf, FS.stat(stream.path));
693+
return SYSCALLS.writeStat(buf, FS.fstat(fd));
695694
},
696695
__syscall_fchown32: (fd, owner, group) => {
697696
FS.fchown(fd, owner, group);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <fcntl.h>
2+
#include <unistd.h>
3+
#include <sys/stat.h>
4+
#include <assert.h>
5+
#include "stdio.h"
6+
7+
int main() {
8+
int fd = open("file.txt", O_RDWR | O_CREAT, 0666);
9+
unlink("file.txt");
10+
int res;
11+
struct stat buf;
12+
res = fstat(fd, &buf);
13+
assert(res == 0);
14+
assert(buf.st_atime > 1000000000);
15+
res = fchmod(fd, 0777);
16+
assert(res == 0);
17+
res = ftruncate(fd, 10);
18+
assert(res == 0);
19+
printf("success\n");
20+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
129211
1+
129218
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
128623
1+
128630
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
170879
1+
170886
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
144708
1+
144715
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
142162
1+
142169
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
232724
1+
232731

0 commit comments

Comments
 (0)