1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2011 GraÅžvydas Ignotas
7 * This test checks if no duplicate d_off values are returned and
8 * that these offsets are seekable to entry with the right inode.
17 #include <sys/syscall.h>
19 struct linux_dirent64 {
22 unsigned short d_reclen;
28 #define HISTORY_LEN 1024
30 static uint64_t d_off_history[HISTORY_LEN];
31 static uint64_t d_ino_history[HISTORY_LEN];
34 main(int argc, char *argv[])
38 struct linux_dirent64 *d;
41 int retval = EXIT_SUCCESS;
43 fd = open(argv[1], O_RDONLY | O_DIRECTORY);
51 nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE);
60 for (bpos = 0; bpos < nread; total++) {
61 d = (struct linux_dirent64 *) (buf + bpos);
63 if (total >= HISTORY_LEN) {
64 fprintf(stderr, "too many files\n");
68 for (i = 0; i < total; i++)
70 if (d_off_history[i] == d->d_off) {
71 fprintf(stderr, "entries %d and %d have duplicate d_off %lld\n",
72 i, total, (long long int)d->d_off);
73 retval = EXIT_FAILURE;
76 d_off_history[total] = d->d_off;
77 d_ino_history[total] = d->d_ino;
82 /* check if seek works correctly */
83 d = (struct linux_dirent64 *)buf;
84 for (i = total - 1; i >= 0; i--)
86 lret = lseek(fd, i > 0 ? d_off_history[i - 1] : 0, SEEK_SET);
92 nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE);
99 fprintf(stderr, "getdents returned 0 on entry %d\n", i);
100 retval = EXIT_FAILURE;
103 if (d->d_ino != d_ino_history[i]) {
104 fprintf(stderr, "entry %d has inode %lld, expected %lld\n",
105 i, (long long int)d->d_ino, (long long int)d_ino_history[i]);
106 retval = EXIT_FAILURE;