2 * Copyright (c) 2011 GraÅžvydas Ignotas
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write the Free Software Foundation,
15 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * This test checks if no duplicate d_off values are returned and
20 * that these offsets are seekable to entry with the right inode.
29 #include <sys/syscall.h>
31 struct linux_dirent64 {
34 unsigned short d_reclen;
40 #define HISTORY_LEN 1024
42 static uint64_t d_off_history[HISTORY_LEN];
43 static uint64_t d_ino_history[HISTORY_LEN];
46 main(int argc, char *argv[])
50 struct linux_dirent64 *d;
53 int retval = EXIT_SUCCESS;
55 fd = open(argv[1], O_RDONLY | O_DIRECTORY);
63 nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE);
72 for (bpos = 0; bpos < nread; total++) {
73 d = (struct linux_dirent64 *) (buf + bpos);
75 if (total >= HISTORY_LEN) {
76 fprintf(stderr, "too many files\n");
80 for (i = 0; i < total; i++)
82 if (d_off_history[i] == d->d_off) {
83 fprintf(stderr, "entries %d and %d have duplicate d_off %lld\n",
84 i, total, (long long int)d->d_off);
85 retval = EXIT_FAILURE;
88 d_off_history[total] = d->d_off;
89 d_ino_history[total] = d->d_ino;
94 /* check if seek works correctly */
95 d = (struct linux_dirent64 *)buf;
96 for (i = total - 1; i >= 0; i--)
98 lret = lseek(fd, i > 0 ? d_off_history[i - 1] : 0, SEEK_SET);
104 nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE);
111 fprintf(stderr, "getdents returned 0 on entry %d\n", i);
112 retval = EXIT_FAILURE;
115 if (d->d_ino != d_ino_history[i]) {
116 fprintf(stderr, "entry %d has inode %lld, expected %lld\n",
117 i, (long long int)d->d_ino, (long long int)d_ino_history[i]);
118 retval = EXIT_FAILURE;