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