Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion src/library_nodefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ addToLibrary({
}
return {
dev: stat.dev,
ino: stat.ino,
ino: node.id,
mode: stat.mode,
nlink: stat.nlink,
uid: stat.uid,
Expand Down
76 changes: 76 additions & 0 deletions test/fs/test_fs_readdir_ino_matches_stat_ino.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <dirent.h>


#if defined(__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");
emscripten_debugger();
EM_ASM(FS.mount(NODEFS, { root: '.' }, 'working'));
changedir("working");
#endif
mkdir("sub", 0775);
changedir("sub");
}

int main() {
setup();
int res = open("b", O_CREAT, 0777);
assert(res >= 0);
assert(close(res) == 0);
assert(symlink("b", "a") == 0);
int dirfd = open(".", O_RDONLY);
assert(dirfd > 0);
DIR *dirp;
dirp = fdopendir(dirfd);
assert(dirp != NULL);
struct dirent *ep;
struct stat sta, stb;
assert(lstat("a", &sta) == 0);
assert(lstat("b", &stb) == 0);
// Remove execute permission from directory. This prevents us from stat'ing
// files in the directory in the implementation of readdir which we tried to
// use to fix this.
assert(chmod(".", 0675) == 0);
int a_ino = -1;
int b_ino = -1;
while ((ep = readdir(dirp))) {
if (strcmp(ep->d_name, "a") == 0) {
a_ino = ep->d_ino;
}
if (strcmp(ep->d_name, "b") == 0) {
b_ino = ep->d_ino;
}
}
assert(errno == 0);
assert(a_ino >= 0);
assert(b_ino >= 0);
assert(chmod(".", 0775) == 0);
printf("readdir a_ino: %d, b_ino: %d\n", a_ino, b_ino);
printf("stat a_ino: %llu, b_ino: %llu\n", sta.st_ino, stb.st_ino);
assert(a_ino == sta.st_ino);
assert(b_ino == stb.st_ino);
printf("success\n");
}
10 changes: 10 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5900,6 +5900,16 @@ def test_fs_rename_on_existing(self, args):
self.set_setting('FORCE_FILESYSTEM')
self.do_runf('fs/test_fs_rename_on_existing.c', 'success', emcc_args=args)

@parameterized({
'': ([],),
'nodefs': (['-DNODEFS', '-lnodefs.js'],),
'noderawfs': (['-sNODERAWFS'],)
})
def test_fs_readdir_ino_matches_stat_ino(self, args):
if self.get_setting('WASMFS'):
self.set_setting('FORCE_FILESYSTEM')
self.do_runf('fs/test_fs_readdir_ino_matches_stat_ino.c', 'success', emcc_args=args)

def test_sigalrm(self):
self.do_runf('test_sigalrm.c', 'Received alarm!')
self.set_setting('EXIT_RUNTIME')
Expand Down
Loading