diff --git a/build/VStudio/testing/winfsp-tests.vcxproj b/build/VStudio/testing/winfsp-tests.vcxproj
index 62f4b3f2..612b7584 100644
--- a/build/VStudio/testing/winfsp-tests.vcxproj
+++ b/build/VStudio/testing/winfsp-tests.vcxproj
@@ -181,6 +181,7 @@
TurnOffAllWarnings
+
diff --git a/build/VStudio/testing/winfsp-tests.vcxproj.filters b/build/VStudio/testing/winfsp-tests.vcxproj.filters
index 5b5857fe..26bd0f48 100644
--- a/build/VStudio/testing/winfsp-tests.vcxproj.filters
+++ b/build/VStudio/testing/winfsp-tests.vcxproj.filters
@@ -43,6 +43,9 @@
Source
+
+ Source
+
diff --git a/tst/winfsp-tests/dirctl-test.c b/tst/winfsp-tests/dirctl-test.c
new file mode 100644
index 00000000..ee787f4a
--- /dev/null
+++ b/tst/winfsp-tests/dirctl-test.c
@@ -0,0 +1,201 @@
+#include
+#include
+#include
+#include
+#include "memfs.h"
+
+void *memfs_start_ex(ULONG Flags, ULONG FileInfoTimeout);
+void *memfs_start(ULONG Flags);
+void memfs_stop(void *data);
+PWSTR memfs_volumename(void *data);
+
+extern int NtfsTests;
+extern int WinFspDiskTests;
+extern int WinFspNetTests;
+
+void querydir_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout)
+{
+ void *memfs = memfs_start_ex(Flags, FileInfoTimeout);
+
+ HANDLE Handle;
+ BOOL Success;
+ WCHAR FilePath[MAX_PATH];
+ WIN32_FIND_DATAW FindData;
+ ULONG FileCount, FileTotal;
+
+ for (int i = 1; 10 >= i; i++)
+ {
+ StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir%d",
+ Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs), i);
+ Success = CreateDirectoryW(FilePath, 0);
+ ASSERT(Success);
+ }
+
+ for (int j = 1; 100 >= j; j++)
+ {
+ StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\fileABCDEFGHIJKLMNOPQRSTUVXWYZfile%d",
+ Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs), j);
+ Handle = CreateFileW(FilePath, GENERIC_ALL, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
+ ASSERT(INVALID_HANDLE_VALUE != Handle);
+ Success = CloseHandle(Handle);
+ ASSERT(Success);
+ }
+
+ for (int j = 1; 100 >= j; j++)
+ {
+ StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir5\\file%d",
+ Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs), j);
+ Handle = CreateFileW(FilePath, GENERIC_ALL, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
+ ASSERT(INVALID_HANDLE_VALUE != Handle);
+ Success = CloseHandle(Handle);
+ ASSERT(Success);
+ }
+
+ StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir5\\*",
+ Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
+ Handle = FindFirstFileW(FilePath, &FindData);
+ ASSERT(INVALID_HANDLE_VALUE != Handle);
+
+ FileCount = FileTotal = 0;
+ do
+ {
+ unsigned long ul;
+ wchar_t *endp;
+
+ ASSERT(0 == (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
+ ASSERT(0 == wcsncmp(FindData.cFileName, L"file", 4));
+ ul = wcstoul(FindData.cFileName + 4, &endp, 10);
+ ASSERT(0 != ul);
+ ASSERT(L'\0' == *endp);
+
+ FileCount++;
+ FileTotal += ul;
+ } while (FindNextFileW(Handle, &FindData));
+ ASSERT(ERROR_NO_MORE_FILES == GetLastError());
+
+ ASSERT(100 == FileCount);
+ ASSERT(101 * 100 / 2 == FileTotal);
+
+ Success = FindClose(Handle);
+ ASSERT(Success);
+
+ StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir*",
+ Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
+ Handle = FindFirstFileW(FilePath, &FindData);
+ ASSERT(INVALID_HANDLE_VALUE != Handle);
+
+ FileCount = FileTotal = 0;
+ do
+ {
+ unsigned long ul;
+ wchar_t *endp;
+
+ ASSERT(0 != (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
+ ASSERT(0 == wcsncmp(FindData.cFileName, L"dir", 3));
+ ul = wcstoul(FindData.cFileName + 3, &endp, 10);
+ ASSERT(0 != ul);
+ ASSERT(L'\0' == *endp);
+
+ FileCount++;
+ FileTotal += ul;
+ } while (FindNextFileW(Handle, &FindData));
+ ASSERT(ERROR_NO_MORE_FILES == GetLastError());
+
+ ASSERT(100 == FileCount);
+ ASSERT(101 * 100 / 2 == FileTotal);
+
+ Success = FindClose(Handle);
+ ASSERT(Success);
+
+ StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\file*",
+ Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
+ Handle = FindFirstFileW(FilePath, &FindData);
+ ASSERT(INVALID_HANDLE_VALUE != Handle);
+
+ FileCount = FileTotal = 0;
+ do
+ {
+ unsigned long ul;
+ wchar_t *endp;
+ size_t wcscnt = sizeof "fileABCDEFGHIJKLMNOPQRSTUVXWYZfile" - 1/* count of wchar_t*/;
+
+ ASSERT(0 == (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
+ ASSERT(0 == wcsncmp(FindData.cFileName, L"fileABCDEFGHIJKLMNOPQRSTUVXWYZfile", wcscnt));
+ ul = wcstoul(FindData.cFileName + wcscnt, &endp, 10);
+ ASSERT(0 != ul);
+ ASSERT(L'\0' == *endp);
+
+ FileCount++;
+ FileTotal += ul;
+ } while (FindNextFileW(Handle, &FindData));
+ ASSERT(ERROR_NO_MORE_FILES == GetLastError());
+
+ ASSERT(100 == FileCount);
+ ASSERT(101 * 100 / 2 == FileTotal);
+
+ Success = FindClose(Handle);
+ ASSERT(Success);
+
+ StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\DOES-NOT-EXIST",
+ Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
+ Handle = FindFirstFileW(FilePath, &FindData);
+ ASSERT(INVALID_HANDLE_VALUE == Handle);
+ ASSERT(ERROR_FILE_NOT_FOUND == GetLastError());
+
+ for (int j = 1; 100 >= j; j++)
+ {
+ StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir5\\file%d",
+ Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs), j);
+ Success = DeleteFileW(FilePath);
+ ASSERT(Success);
+ }
+
+ for (int j = 1; 100 >= j; j++)
+ {
+ StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\fileABCDEFGHIJKLMNOPQRSTUVXWYZfile%d",
+ Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs), j);
+ Success = DeleteFileW(FilePath);
+ ASSERT(Success);
+ }
+
+ for (int i = 1; 10 >= i; i++)
+ {
+ StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\dir%d",
+ Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs), i);
+ Success = RemoveDirectoryW(FilePath);
+ ASSERT(Success);
+ }
+
+ StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\file*",
+ Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
+ Handle = FindFirstFileW(FilePath, &FindData);
+ ASSERT(INVALID_HANDLE_VALUE == Handle);
+ ASSERT(ERROR_FILE_NOT_FOUND == GetLastError());
+
+ memfs_stop(memfs);
+}
+
+void querydir_test(void)
+{
+ if (NtfsTests)
+ {
+ WCHAR DirBuf[MAX_PATH] = L"\\\\?\\";
+ GetCurrentDirectoryW(MAX_PATH - 4, DirBuf + 4);
+ querydir_dotest(-1, DirBuf, 0);
+ }
+ if (WinFspDiskTests)
+ {
+ querydir_dotest(MemfsDisk, 0, 0);
+ querydir_dotest(MemfsDisk, 0, 1000);
+ }
+ if (WinFspNetTests)
+ {
+ querydir_dotest(MemfsNet, L"\\\\memfs\\share", 0);
+ querydir_dotest(MemfsNet, L"\\\\memfs\\share", 1000);
+ }
+}
+
+void dirctl_tests(void)
+{
+ TEST(querydir_test);
+}
diff --git a/tst/winfsp-tests/winfsp-tests.c b/tst/winfsp-tests/winfsp-tests.c
index 269585e1..9d7462e9 100644
--- a/tst/winfsp-tests/winfsp-tests.c
+++ b/tst/winfsp-tests/winfsp-tests.c
@@ -14,6 +14,7 @@ int main(int argc, char *argv[])
TESTSUITE(info_tests);
TESTSUITE(security_tests);
TESTSUITE(rdwr_tests);
+ TESTSUITE(dirctl_tests);
tlib_run_tests(argc, argv);
return 0;