Skip to content
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

Ensure the ino we give to readdir matches the ino we give to stat #23139

Merged
merged 19 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
15 changes: 2 additions & 13 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,27 +742,16 @@ def make_executable(name):


def make_dir_writeable(dirname):
# Ensure all files are readable and writable by the current user.
permission_bits = stat.S_IWRITE | stat.S_IREAD

def is_writable(path):
return (os.stat(path).st_mode & permission_bits) != permission_bits

def make_writable(path):
new_mode = os.stat(path).st_mode | permission_bits
os.chmod(path, new_mode)

# Some tests make files and subdirectories read-only, so rmtree/unlink will not delete
# them. Force-make everything writable in the subdirectory to make it
# removable and re-attempt.
if not is_writable(dirname):
make_writable(dirname)
os.chmod(dirname, 0o777)

for directory, subdirs, files in os.walk(dirname):
for item in files + subdirs:
i = os.path.join(directory, item)
if not os.path.islink(i):
make_writable(i)
os.chmod(i, 0o777)


def force_delete_dir(dirname):
Expand Down
50 changes: 50 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,50 @@
#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>


int main() {
int res = open("b", O_CREAT, 0777);
assert(res >= 0);
assert(close(res) == 0);
assert(symlink("b", "a") == 0);
sbc100 marked this conversation as resolved.
Show resolved Hide resolved
int dirfd = open(".", O_RDONLY);
assert(dirfd > 0);
DIR *dirp;
dirp = fdopendir(dirfd);
hoodmane marked this conversation as resolved.
Show resolved Hide resolved
assert(dirp != NULL);
struct dirent *ep;
hoodmane marked this conversation as resolved.
Show resolved Hide resolved
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.
hoodmane marked this conversation as resolved.
Show resolved Hide resolved
assert(chmod(".", 0675) == 0);
int a_ino = -1;
int b_ino = -1;
while ((ep = readdir(dirp))) {
hoodmane marked this conversation as resolved.
Show resolved Hide resolved
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);
hoodmane marked this conversation as resolved.
Show resolved Hide resolved
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");
}
4 changes: 4 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5858,6 +5858,10 @@ def test_fs_rename_on_existing(self):
self.set_setting('FORCE_FILESYSTEM')
self.do_runf('fs/test_fs_rename_on_existing.c', 'success')

@also_with_nodefs_both
def test_fs_readdir_ino_matches_stat_ino(self, args):
self.do_runf('fs/test_fs_readdir_ino_matches_stat_ino.c', 'success')

hoodmane marked this conversation as resolved.
Show resolved Hide resolved
def test_sigalrm(self):
self.do_runf('test_sigalrm.c', 'Received alarm!')
self.do_runf('test_sigalrm.c', 'Received alarm!', emcc_args=['-sEXIT_RUNTIME'])
Expand Down
Loading