btrfs: Add new test for qgroup assign functionality
[xfstests-dev.git] / src / t_dir_offset.c
1
2 #include <fcntl.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <stdint.h>
6 #include <stdlib.h>
7 #include <sys/stat.h>
8 #include <sys/syscall.h>
9
10 struct linux_dirent64 {
11         uint64_t        d_ino;
12         int64_t         d_off;
13         unsigned short  d_reclen;
14         unsigned char   d_type;
15         char            d_name[0];
16 };
17
18
19 #define BUF_SIZE 4096
20
21 int
22 main(int argc, char *argv[])
23 {
24         int fd, nread;
25         char buf[BUF_SIZE];
26         struct linux_dirent64 *d;
27         int bpos;
28
29         fd = open(argv[1], O_RDONLY | O_DIRECTORY);
30         if (fd < 0) {
31                 perror("open");
32                 exit(EXIT_FAILURE);
33         }
34
35         for ( ; ; ) {
36                 nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE);
37                 if (nread == -1) {
38                         perror("getdents");
39                         exit(EXIT_FAILURE);
40                 }
41
42                 if (nread == 0)
43                         break;
44
45                 for (bpos = 0; bpos < nread;) {
46                         d = (struct linux_dirent64 *) (buf + bpos);
47                         /*
48                          * Can't use off_t here xfsqa is compiled with
49                          * -D_FILE_OFFSET_BITS=64
50                          */
51                         if (d->d_off != (long)d->d_off) {
52                                 fprintf(stderr, "detected d_off truncation "
53                                                 "d_name = %s, d_off = %lld\n",
54                                                 d->d_name, (long long)d->d_off);
55                                 exit(EXIT_FAILURE);
56                         }
57                         bpos += d->d_reclen;
58                 }
59         }
60
61         exit(EXIT_SUCCESS);
62 }