Created
September 16, 2017 23:41
-
-
Save nh2/6ebd9d5befe130fd6faacd1024ead3d7 to your computer and use it in GitHub Desktop.
Test getdents() program for debugging https://bugzilla.redhat.com/show_bug.cgi?id=1478411
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include <dirent.h> /* Defines DT_* constants */ | |
#include <fcntl.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <sys/stat.h> | |
#include <sys/syscall.h> | |
#define handle_error(msg) \ | |
do { perror(msg); exit(EXIT_FAILURE); } while (0) | |
struct linux_dirent { | |
long d_ino; | |
off_t d_off; | |
unsigned short d_reclen; | |
char d_name[]; | |
}; | |
#define BUF_SIZE 131072 | |
// #define BUF_SIZE 32768 | |
int | |
main(int argc, char *argv[]) | |
{ | |
int fd, nread; | |
char buf[BUF_SIZE]; | |
struct linux_dirent *d; | |
int bpos; | |
char d_type; | |
fd = open(argc > 1 ? argv[1] : ".", O_RDONLY | O_DIRECTORY); | |
if (fd == -1) | |
handle_error("open"); | |
for ( ; ; ) { | |
nread = syscall(SYS_getdents, fd, buf, BUF_SIZE); | |
if (nread == -1) | |
handle_error("getdents"); | |
if (nread == 0) | |
break; | |
} | |
exit(EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment