mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
src/t_dir_offset2: Add an option to limit of buffer size
Will be used to force readdir in several getdents calls. Signed-off-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: Eryu Guan <guaneryu@gmail.com>
This commit is contained in:
committed by
Eryu Guan
parent
1c18b9ec2f
commit
d8772f925f
+21
-5
@@ -30,16 +30,32 @@ struct linux_dirent64 {
|
||||
static uint64_t d_off_history[HISTORY_LEN];
|
||||
static uint64_t d_ino_history[HISTORY_LEN];
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
void usage()
|
||||
{
|
||||
int fd, nread;
|
||||
fprintf(stderr, "usage: t_dir_offset2: <dir> [bufsize]\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fd;
|
||||
char buf[BUF_SIZE];
|
||||
int nread, bufsize = BUF_SIZE;
|
||||
struct linux_dirent64 *d;
|
||||
int bpos, total, i;
|
||||
off_t lret;
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
if (argc > 2) {
|
||||
bufsize = atoi(argv[2]);
|
||||
if (!bufsize)
|
||||
usage();
|
||||
if (bufsize > BUF_SIZE)
|
||||
bufsize = BUF_SIZE;
|
||||
} else if (argc < 2) {
|
||||
usage();
|
||||
}
|
||||
|
||||
fd = open(argv[1], O_RDONLY | O_DIRECTORY);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
@@ -48,7 +64,7 @@ main(int argc, char *argv[])
|
||||
|
||||
total = 0;
|
||||
for ( ; ; ) {
|
||||
nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE);
|
||||
nread = syscall(SYS_getdents64, fd, buf, bufsize);
|
||||
if (nread == -1) {
|
||||
perror("getdents");
|
||||
exit(EXIT_FAILURE);
|
||||
@@ -89,7 +105,7 @@ main(int argc, char *argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE);
|
||||
nread = syscall(SYS_getdents64, fd, buf, bufsize);
|
||||
if (nread == -1) {
|
||||
perror("getdents");
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
Reference in New Issue
Block a user