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