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