libgocryptfs/contrib/getdents-debug/getdents_c/getdents.c
Jakob Unterwurzacher 22e3eec153 getdents-debug: loop and stop on first error
Also try to improve and unify output a little.

$ ./getdents /usr/share/man/man1
  1: unix.Getdents: n=9984; n=9984; n=9968; n=9976; n=9984; n=9968; n=10000; n=9976; n=9992; n=10000; n=9976; n=9992; n=2312; n=0; err=<nil>; total 122112 bytes
  2: unix.Getdents: n=9984; n=48; n=9976; n=9968; n=9976; n=9976; n=9992; n=9984; n=9992; n=10000; n=9976; n=9968; n=10000; n=2272; n=0; err=<nil>; total 122112 bytes
  3: unix.Getdents: n=9984; n=9984; n=9968; n=704; n=10000; n=10000; n=9968; n=9968; n=9992; n=10000; n=9960; n=9992; n=9992; n=1600; n=0; err=<nil>; total 122112 bytes
  4: unix.Getdents: n=9984; n=9984; n=9968; n=9976; n=9984; n=32; n=9992; n=9984; n=9992; n=10000; n=9976; n=9968; n=10000; n=2272; n=0; err=<nil>; total 122112 bytes

$ ./getdents_c /usr/share/man/man1
  1: getdents64: n=9984; n=9984; n=9968; n=9976; n=9984; n=9968; n=10000; n=9976; n=9992; n=10000; n=9976; n=9992; n=2312; n=0; errno=0 total 122112 bytes
  2: getdents64: n=9984; n=9984; n=9968; n=9976; n=9984; n=9968; n=10000; n=9976; n=9992; n=10000; n=9976; n=9992; n=2312; n=0; errno=0 total 122112 bytes
  3: getdents64: n=9984; n=9984; n=9968; n=9976; n=9984; n=9968; n=10000; n=9976; n=9992; n=10000; n=9976; n=9992; n=2312; n=0; errno=0 total 122112 bytes
  4: getdents64: n=9984; n=9984; n=9968; n=9976; n=9984; n=9968; n=10000; n=9976; n=9992; n=10000; n=9976; n=9992; n=2312; n=0; errno=0 total 122112 bytes
2020-05-28 23:23:53 +02:00

49 lines
1.1 KiB
C

// See ../getdents/getdents.go for some info on why
// this exists.
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <errno.h>
int main(int argc, char *argv[])
{
if(argc != 2) {
printf("Usage: %s PATH\n", argv[0]);
printf("Run getdents(2) on PATH in a 100ms loop\n");
exit(1);
}
const char *path = argv[1];
for (int i = 1 ; ; i ++ ) {
int fd = open(path, O_RDONLY);
if (fd == -1) {
perror("open");
exit(1);
}
char tmp[10000];
int sum = 0;
printf("%3d: getdents64: ", i);
for ( ; ; ) {
int n = syscall(SYS_getdents64, fd, tmp, sizeof(tmp));
printf("n=%d; ", n);
if (n <= 0) {
printf("errno=%d total %d bytes\n", errno, sum);
if (n < 0) {
exit(1);
}
break;
}
sum += n;
}
close(fd);
usleep(100000);
}
}