2020-05-24 23:28:23 +02:00
|
|
|
// 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>
|
2020-07-29 20:35:59 +02:00
|
|
|
#include <string.h>
|
2020-05-24 23:28:23 +02:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2020-05-28 23:21:35 +02:00
|
|
|
if(argc != 2) {
|
2020-05-24 23:28:23 +02:00
|
|
|
printf("Usage: %s PATH\n", argv[0]);
|
2020-05-28 23:21:35 +02:00
|
|
|
printf("Run getdents(2) on PATH in a 100ms loop\n");
|
2020-05-24 23:28:23 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *path = argv[1];
|
|
|
|
|
2020-05-28 23:21:35 +02:00
|
|
|
for (int i = 1 ; ; i ++ ) {
|
|
|
|
int fd = open(path, O_RDONLY);
|
|
|
|
if (fd == -1) {
|
2020-07-29 20:35:59 +02:00
|
|
|
printf("%3d: open: %s\n", i, strerror(errno));
|
|
|
|
if(errno == EINTR) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-28 23:21:35 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2020-07-29 20:29:24 +02:00
|
|
|
|
|
|
|
char tmp[10000];
|
|
|
|
int sum = 0;
|
|
|
|
printf("%3d: getdents64: ", i);
|
|
|
|
for ( ; ; ) {
|
2020-07-29 20:35:59 +02:00
|
|
|
errno = 0;
|
2020-07-29 20:29:24 +02:00
|
|
|
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;
|
|
|
|
}
|
2020-05-28 23:21:35 +02:00
|
|
|
close(fd);
|
|
|
|
usleep(100000);
|
2020-05-24 23:28:23 +02:00
|
|
|
}
|
|
|
|
}
|