Skip to content

Commit

Permalink
Add tests to ensure that d_ino matches st_ino.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode authored and loganek committed Dec 9, 2022
1 parent 344cd18 commit c0f595b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/c/testsuite/fdopendir-with-access.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
DIR *d;
struct dirent *dp;
int dfd;
int expected[2] = {0};
ino_t inodes[2];

dfd = open("fs-tests.dir/fopendir.dir", O_RDONLY | O_DIRECTORY);
assert(dfd != -1);
Expand All @@ -23,16 +25,26 @@ int main(int argc, char *argv[]) {
}
if (strncmp(dp->d_name, "file-0", 6) == 0) {
expected[0] = 1;
inodes[0] = dp->d_ino;
} else if (strncmp(dp->d_name, "file-1", 6) == 0) {
expected[1] = 1;
inodes[1] = dp->d_ino;
} else {
assert(0); // unexpected file
}

// Ensure that `d_ino` matches what `fstatat`'s `st_ino` tells us.
struct stat statbuf;
if (fstatat(dfd, dp->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) != 0) {
assert(0);
}
assert(statbuf.st_ino == dp->d_ino);
}
closedir(d);

assert(expected[0] == 1);
assert(expected[1] == 1);
assert(inodes[0] != inodes[1]);

return EXIT_SUCCESS;
}

0 comments on commit c0f595b

Please sign in to comment.