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