xref: /xnu-8796.141.3/tests/extended_getdirentries64.c (revision 1b191cb58250d0705d8a51287127505aa4bc0789)
1 #ifdef T_NAMESPACE
2 #undef T_NAMESPACE
3 #endif
4 
5 #include <darwintest.h>
6 #include <darwintest_multiprocess.h>
7 
8 #define PRIVATE 1
9 #include "../bsd/sys/dirent.h"
10 
11 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
12 
13 ssize_t __getdirentries64(int fd, void *buf, size_t bufsize, off_t *basep);
14 
15 T_DECL(getdirentries64_extended, "check for GETDIRENTRIES64_EOF")
16 {
17 	char buf[GETDIRENTRIES64_EXTENDED_BUFSIZE];
18 	getdirentries64_flags_t *flags;
19 	ssize_t result;
20 	off_t offset;
21 	int fd;
22 	bool eof = false;
23 
24 	flags = (getdirentries64_flags_t *)(uintptr_t)(buf + sizeof(buf) -
25 	    sizeof(getdirentries64_flags_t));
26 	fd = open("/", O_DIRECTORY | O_RDONLY);
27 	T_ASSERT_POSIX_SUCCESS(fd, "open(/)");
28 
29 	for (;;) {
30 		*flags = (getdirentries64_flags_t)~0;
31 		result = __getdirentries64(fd, buf, sizeof(buf), &offset);
32 		T_ASSERT_POSIX_SUCCESS(result, "__getdirentries64()");
33 		T_ASSERT_LE((size_t)result, sizeof(buf) - sizeof(getdirentries64_flags_t),
34 		    "The kernel should have left space for the flags");
35 		T_ASSERT_NE(*flags, (getdirentries64_flags_t)~0,
36 		    "The kernel should have returned status");
37 		if (eof) {
38 			T_ASSERT_EQ(result, 0l, "At EOF, we really should be done");
39 			T_ASSERT_TRUE(*flags & GETDIRENTRIES64_EOF, "And EOF should still be set");
40 			T_END;
41 		}
42 		T_ASSERT_NE(result, 0l, "We're not at EOF, we should have an entry");
43 		eof = (*flags & GETDIRENTRIES64_EOF);
44 	}
45 }
46