diff --git a/build/VStudio/testing/winfsp-tests.vcxproj b/build/VStudio/testing/winfsp-tests.vcxproj
index 34cea334..1d51effe 100644
--- a/build/VStudio/testing/winfsp-tests.vcxproj
+++ b/build/VStudio/testing/winfsp-tests.vcxproj
@@ -186,7 +186,6 @@
-
diff --git a/build/VStudio/testing/winfsp-tests.vcxproj.filters b/build/VStudio/testing/winfsp-tests.vcxproj.filters
index 1f73d6a2..6d26ad3f 100644
--- a/build/VStudio/testing/winfsp-tests.vcxproj.filters
+++ b/build/VStudio/testing/winfsp-tests.vcxproj.filters
@@ -64,9 +64,6 @@
Source
-
- Source
-
Source
diff --git a/src/sys/name.c b/src/sys/name.c
index 45ecc2b6..56695e45 100644
--- a/src/sys/name.c
+++ b/src/sys/name.c
@@ -121,10 +121,10 @@ BOOLEAN FspFileNameIsValid(PUNICODE_STRING Path, PUNICODE_STRING StreamPart, PUL
/* if we had a stream type the path is valid if the stream type was "$DATA" only */
if (StreamTypeStr + 5 == PathEnd &&
L'$' == StreamTypeStr[0] &&
- L'D' == StreamTypeStr[1] &&
- L'A' == StreamTypeStr[2] &&
- L'T' == StreamTypeStr[3] &&
- L'A' == StreamTypeStr[4])
+ L'd' == (StreamTypeStr[1] | 0x20) &&
+ L'a' == (StreamTypeStr[2] | 0x20) &&
+ L't' == (StreamTypeStr[3] | 0x20) &&
+ L'a' == (StreamTypeStr[4] | 0x20))
{
*StreamType = FspFileNameStreamTypeData;
return TRUE;
diff --git a/tst/memfs/memfs-main.c b/tst/memfs/memfs-main.c
index 5fdcd1c8..8cb1fd98 100644
--- a/tst/memfs/memfs-main.c
+++ b/tst/memfs/memfs-main.c
@@ -39,6 +39,7 @@ NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
wchar_t **argp, **arge;
ULONG DebugFlags = 0;
PWSTR DebugLogFile = 0;
+ ULONG CaseInsensitiveFlags = 0;
ULONG Flags = MemfsDisk;
ULONG FileInfoTimeout = INFINITE;
ULONG MaxFileNodes = 1024;
@@ -64,6 +65,9 @@ NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
case L'D':
argtos(DebugLogFile);
break;
+ case L'i':
+ CaseInsensitiveFlags = MemfsCaseInsensitive;
+ break;
case L'm':
argtos(MountPoint);
break;
@@ -117,7 +121,13 @@ NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
FspDebugLogSetHandle(DebugLogHandle);
}
- Result = MemfsCreate(Flags, FileInfoTimeout, MaxFileNodes, MaxFileSize, VolumePrefix, RootSddl,
+ Result = MemfsCreate(
+ CaseInsensitiveFlags | Flags,
+ FileInfoTimeout,
+ MaxFileNodes,
+ MaxFileSize,
+ VolumePrefix,
+ RootSddl,
&Memfs);
if (!NT_SUCCESS(Result))
{
@@ -170,6 +180,7 @@ usage:
"options:\n"
" -d DebugFlags [-1: enable all debug logs]\n"
" -D DebugLogFile [file path; use - for stdout]\n"
+ " -i [case insensitive file system]\n"
" -t FileInfoTimeout [millis]\n"
" -n MaxFileNodes\n"
" -s MaxFileSize [bytes]\n"
diff --git a/tst/memfs/memfs.cpp b/tst/memfs/memfs.cpp
index 636bfbac..0fc41b66 100644
--- a/tst/memfs/memfs.cpp
+++ b/tst/memfs/memfs.cpp
@@ -47,18 +47,42 @@ UINT64 MemfsGetSystemTime(VOID)
}
static inline
-int MemfsFileNameCompare(PWSTR a, PWSTR b)
+int MemfsCompareString(PWSTR a, int alen, PWSTR b, int blen, BOOLEAN CaseInsensitive)
{
- return wcscmp(a, b);
+ int len, res;
+
+ if (-1 == alen)
+ alen = (int)wcslen(a);
+ if (-1 == blen)
+ blen = (int)wcslen(b);
+
+ len = alen < blen ? alen : blen;
+
+ /* we should still be in the C locale */
+ if (CaseInsensitive)
+ res = _wcsnicmp(a, b, len);
+ else
+ res = wcsncmp(a, b, len);
+
+ if (0 == res)
+ res = alen - blen;
+
+ return res;
}
static inline
-BOOLEAN MemfsFileNameHasPrefix(PWSTR a, PWSTR b)
+int MemfsFileNameCompare(PWSTR a, PWSTR b, BOOLEAN CaseInsensitive)
{
- size_t alen = wcslen(a);
- size_t blen = wcslen(b);
+ return MemfsCompareString(a, -1, b, -1, CaseInsensitive);
+}
- return alen >= blen && 0 == memcmp(a, b, blen * sizeof(WCHAR)) &&
+static inline
+BOOLEAN MemfsFileNameHasPrefix(PWSTR a, PWSTR b, BOOLEAN CaseInsensitive)
+{
+ int alen = (int)wcslen(a);
+ int blen = (int)wcslen(b);
+
+ return alen >= blen && 0 == MemfsCompareString(a, blen, b, blen, CaseInsensitive) &&
(alen == blen || (1 == blen && L'\\' == b[0]) ||
#if defined(MEMFS_NAMED_STREAMS)
(L'\\' == a[blen] || L':' == a[blen]));
@@ -84,10 +108,14 @@ typedef struct _MEMFS_FILE_NODE
struct MEMFS_FILE_NODE_LESS
{
+ MEMFS_FILE_NODE_LESS(BOOLEAN CaseInsensitive) : CaseInsensitive(CaseInsensitive)
+ {
+ }
bool operator()(PWSTR a, PWSTR b) const
{
- return 0 > MemfsFileNameCompare(a, b);
+ return 0 > MemfsFileNameCompare(a, b, CaseInsensitive);
}
+ BOOLEAN CaseInsensitive;
};
typedef std::map MEMFS_FILE_NODE_MAP;
@@ -169,12 +197,18 @@ VOID MemfsFileNodeMapDump(MEMFS_FILE_NODE_MAP *FileNodeMap)
}
static inline
-NTSTATUS MemfsFileNodeMapCreate(MEMFS_FILE_NODE_MAP **PFileNodeMap)
+BOOLEAN MemfsFileNodeMapIsCaseInsensitive(MEMFS_FILE_NODE_MAP *FileNodeMap)
+{
+ return FileNodeMap->key_comp().CaseInsensitive;
+}
+
+static inline
+NTSTATUS MemfsFileNodeMapCreate(BOOLEAN CaseInsensitive, MEMFS_FILE_NODE_MAP **PFileNodeMap)
{
*PFileNodeMap = 0;
try
{
- *PFileNodeMap = new MEMFS_FILE_NODE_MAP;
+ *PFileNodeMap = new MEMFS_FILE_NODE_MAP(MEMFS_FILE_NODE_LESS(CaseInsensitive));
return STATUS_SUCCESS;
}
catch (...)
@@ -287,7 +321,8 @@ BOOLEAN MemfsFileNodeMapHasChild(MEMFS_FILE_NODE_MAP *FileNodeMap, MEMFS_FILE_NO
continue;
#endif
FspPathSuffix(iter->second->FileName, &Remain, &Suffix, Root);
- Result = 0 == MemfsFileNameCompare(Remain, FileNode->FileName);
+ Result = 0 == MemfsFileNameCompare(Remain, FileNode->FileName,
+ MemfsFileNodeMapIsCaseInsensitive(FileNodeMap));
FspPathCombine(iter->second->FileName, Suffix);
break;
}
@@ -304,10 +339,12 @@ BOOLEAN MemfsFileNodeMapEnumerateChildren(MEMFS_FILE_NODE_MAP *FileNodeMap, MEMF
BOOLEAN IsDirectoryChild;
for (; FileNodeMap->end() != iter; ++iter)
{
- if (!MemfsFileNameHasPrefix(iter->second->FileName, FileNode->FileName))
+ if (!MemfsFileNameHasPrefix(iter->second->FileName, FileNode->FileName,
+ MemfsFileNodeMapIsCaseInsensitive(FileNodeMap)))
break;
FspPathSuffix(iter->second->FileName, &Remain, &Suffix, Root);
- IsDirectoryChild = 0 == MemfsFileNameCompare(Remain, FileNode->FileName);
+ IsDirectoryChild = 0 == MemfsFileNameCompare(Remain, FileNode->FileName,
+ MemfsFileNodeMapIsCaseInsensitive(FileNodeMap));
#if defined(MEMFS_NAMED_STREAMS)
IsDirectoryChild = IsDirectoryChild && 0 == wcschr(Suffix, L':');
#endif
@@ -329,7 +366,8 @@ BOOLEAN MemfsFileNodeMapEnumerateNamedStreams(MEMFS_FILE_NODE_MAP *FileNodeMap,
MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->upper_bound(FileNode->FileName);
for (; FileNodeMap->end() != iter; ++iter)
{
- if (!MemfsFileNameHasPrefix(iter->second->FileName, FileNode->FileName))
+ if (!MemfsFileNameHasPrefix(iter->second->FileName, FileNode->FileName,
+ MemfsFileNodeMapIsCaseInsensitive(FileNodeMap)))
break;
if (L':' != iter->second->FileName[wcslen(FileNode->FileName)])
break;
@@ -348,7 +386,8 @@ BOOLEAN MemfsFileNodeMapEnumerateDescendants(MEMFS_FILE_NODE_MAP *FileNodeMap, M
MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->lower_bound(FileNode->FileName);
for (; FileNodeMap->end() != iter; ++iter)
{
- if (!MemfsFileNameHasPrefix(iter->second->FileName, FileNode->FileName))
+ if (!MemfsFileNameHasPrefix(iter->second->FileName, FileNode->FileName,
+ MemfsFileNodeMapIsCaseInsensitive(FileNodeMap)))
break;
if (!EnumFn(iter->second, Context))
return FALSE;
@@ -615,7 +654,6 @@ static VOID Cleanup(FSP_FILE_SYSTEM *FileSystem,
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
MEMFS_FILE_NODE *FileNode = (MEMFS_FILE_NODE *)FileNode0;
- assert(0 == FileName || 0 == wcscmp(FileNode->FileName, FileName));
assert(Delete); /* the new FSP_FSCTL_VOLUME_PARAMS::PostCleanupOnDeleteOnly ensures this */
if (Delete && !MemfsFileNodeMapHasChild(Memfs->FileNodeMap, FileNode))
@@ -828,8 +866,6 @@ static NTSTATUS CanDelete(FSP_FILE_SYSTEM *FileSystem,
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
MEMFS_FILE_NODE *FileNode = (MEMFS_FILE_NODE *)FileNode0;
- assert(0 == FileName || 0 == wcscmp(FileNode->FileName, FileName));
-
if (MemfsFileNodeMapHasChild(Memfs->FileNodeMap, FileNode))
return STATUS_DIRECTORY_NOT_EMPTY;
@@ -865,8 +901,6 @@ static NTSTATUS Rename(FSP_FILE_SYSTEM *FileSystem,
BOOLEAN Inserted;
NTSTATUS Result;
- assert(0 == FileName || 0 == wcscmp(FileNode->FileName, FileName));
-
NewFileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, NewFileName);
if (0 != NewFileNode)
{
@@ -897,7 +931,6 @@ static NTSTATUS Rename(FSP_FILE_SYSTEM *FileSystem,
for (Index = 0; Context.Count > Index; Index++)
{
DescendantFileNode = Context.FileNodes[Index];
- assert(MemfsFileNameHasPrefix(DescendantFileNode->FileName, FileNode->FileName));
if (MAX_PATH <= wcslen(DescendantFileNode->FileName) - FileNameLen + NewFileNameLen)
{
Result = STATUS_OBJECT_NAME_INVALID;
@@ -1339,6 +1372,7 @@ NTSTATUS MemfsCreate(
{
NTSTATUS Result;
FSP_FSCTL_VOLUME_PARAMS VolumeParams;
+ BOOLEAN CaseInsensitive = !!(Flags & MemfsCaseInsensitive);
PWSTR DevicePath = (Flags & MemfsNet) ?
L"" FSP_FSCTL_NET_DEVICE_NAME : L"" FSP_FSCTL_DISK_DEVICE_NAME;
UINT64 AllocationUnit;
@@ -1368,7 +1402,7 @@ NTSTATUS MemfsCreate(
AllocationUnit = MEMFS_SECTOR_SIZE * MEMFS_SECTORS_PER_ALLOCATION_UNIT;
Memfs->MaxFileSize = (ULONG)((MaxFileSize + AllocationUnit - 1) / AllocationUnit * AllocationUnit);
- Result = MemfsFileNodeMapCreate(&Memfs->FileNodeMap);
+ Result = MemfsFileNodeMapCreate(CaseInsensitive, &Memfs->FileNodeMap);
if (!NT_SUCCESS(Result))
{
free(Memfs);
@@ -1382,7 +1416,7 @@ NTSTATUS MemfsCreate(
VolumeParams.VolumeCreationTime = MemfsGetSystemTime();
VolumeParams.VolumeSerialNumber = (UINT32)(MemfsGetSystemTime() / (10000 * 1000));
VolumeParams.FileInfoTimeout = FileInfoTimeout;
- VolumeParams.CaseSensitiveSearch = 1;
+ VolumeParams.CaseSensitiveSearch = !CaseInsensitive;
VolumeParams.CasePreservedNames = 1;
VolumeParams.UnicodeOnDisk = 1;
VolumeParams.PersistentAcls = 1;
diff --git a/tst/memfs/memfs.h b/tst/memfs/memfs.h
index aceb1eef..2ee70cec 100644
--- a/tst/memfs/memfs.h
+++ b/tst/memfs/memfs.h
@@ -30,6 +30,7 @@ enum
{
MemfsDisk = 0x00,
MemfsNet = 0x01,
+ MemfsCaseInsensitive = 0x80,
};
NTSTATUS MemfsCreate(
diff --git a/tst/winfsp-tests/dirctl-test.c b/tst/winfsp-tests/dirctl-test.c
index bd6c31eb..a8753a0f 100644
--- a/tst/winfsp-tests/dirctl-test.c
+++ b/tst/winfsp-tests/dirctl-test.c
@@ -64,12 +64,12 @@ static void querydir_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout, UL
FileCount++;
ASSERT(0 != (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
ASSERT(FileCount == wcslen(FindData.cFileName));
- ASSERT(0 == wcsncmp(FindData.cFileName, L"..", FileCount));
+ ASSERT(0 == mywcscmp(FindData.cFileName, FileCount, L"..", FileCount));
continue;
}
ASSERT(0 == (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
- ASSERT(0 == wcsncmp(FindData.cFileName, L"file", 4));
+ ASSERT(0 == mywcscmp(FindData.cFileName, 4, L"file", 4));
ul = wcstoul(FindData.cFileName + 4, &endp, 10);
ASSERT(0 != ul);
ASSERT(L'\0' == *endp);
@@ -100,7 +100,7 @@ static void querydir_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout, UL
wchar_t *endp;
ASSERT(0 != (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
- ASSERT(0 == wcsncmp(FindData.cFileName, L"dir", 3));
+ ASSERT(0 == mywcscmp(FindData.cFileName, 3, L"dir", 3));
ul = wcstoul(FindData.cFileName + 3, &endp, 10);
ASSERT(0 != ul);
ASSERT(L'\0' == *endp);
@@ -132,7 +132,8 @@ static void querydir_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout, UL
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));
+ ASSERT(0 == mywcscmp(FindData.cFileName, (int)wcscnt,
+ L"fileABCDEFGHIJKLMNOPQRSTUVXWYZfile", (int)wcscnt));
ul = wcstoul(FindData.cFileName + wcscnt, &endp, 10);
ASSERT(0 != ul);
ASSERT(L'\0' == *endp);
@@ -413,7 +414,7 @@ static void dirnotify_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout, U
ASSERT(FILE_ACTION_ADDED == NotifyInfo->Action);
ASSERT(wcslen(L"file0") * sizeof(WCHAR) == NotifyInfo->FileNameLength);
- ASSERT(0 == memcmp(L"file0", NotifyInfo->FileName, NotifyInfo->FileNameLength));
+ ASSERT(0 == mywcscmp(L"file0", -1, NotifyInfo->FileName, NotifyInfo->FileNameLength / sizeof(WCHAR)));
if (0 == NotifyInfo->NextEntryOffset)
{
@@ -427,7 +428,7 @@ static void dirnotify_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout, U
ASSERT(FILE_ACTION_REMOVED == NotifyInfo->Action);
ASSERT(wcslen(L"file0") * sizeof(WCHAR) == NotifyInfo->FileNameLength);
- ASSERT(0 == memcmp(L"file0", NotifyInfo->FileName, NotifyInfo->FileNameLength));
+ ASSERT(0 == mywcscmp(L"file0", -1, NotifyInfo->FileName, NotifyInfo->FileNameLength / sizeof(WCHAR)));
ASSERT(0 == NotifyInfo->NextEntryOffset);
diff --git a/tst/winfsp-tests/hook.c b/tst/winfsp-tests/hook.c
deleted file mode 100644
index 8e1c8fd2..00000000
--- a/tst/winfsp-tests/hook.c
+++ /dev/null
@@ -1,34 +0,0 @@
-#include
-
-HANDLE HookCreateFileW(
- LPCWSTR lpFileName,
- DWORD dwDesiredAccess,
- DWORD dwShareMode,
- LPSECURITY_ATTRIBUTES lpSecurityAttributes,
- DWORD dwCreationDisposition,
- DWORD dwFlagsAndAttributes,
- HANDLE hTemplateFile)
-{
- HANDLE h = CreateFileW(
- lpFileName,
- dwDesiredAccess,
- dwShareMode,
- lpSecurityAttributes,
- dwCreationDisposition,
- dwFlagsAndAttributes,
- hTemplateFile);
-
- DWORD LastError = GetLastError();
- FspDebugLog("CreateFileW(\"%S\", %#lx, %#lx, %p, %#lx, %#lx, %p) = %p[%#lx]\n",
- lpFileName,
- dwDesiredAccess,
- dwShareMode,
- lpSecurityAttributes,
- dwCreationDisposition,
- dwFlagsAndAttributes,
- hTemplateFile,
- h, INVALID_HANDLE_VALUE != h ? 0 : LastError);
- SetLastError(LastError);
-
- return h;
-}
diff --git a/tst/winfsp-tests/info-test.c b/tst/winfsp-tests/info-test.c
index 6ceed98a..4be1e1da 100644
--- a/tst/winfsp-tests/info-test.c
+++ b/tst/winfsp-tests/info-test.c
@@ -84,11 +84,11 @@ void getfileinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout)
else
ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR));
if (-1 == Flags)
- ASSERT(0 == memcmp(FilePath + 6, PNameInfo->FileName, PNameInfo->FileNameLength));
+ ASSERT(0 == mywcscmp(FilePath + 6, -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
else if (0 == Prefix)
- ASSERT(0 == memcmp(L"\\file0", PNameInfo->FileName, PNameInfo->FileNameLength));
+ ASSERT(0 == mywcscmp(L"\\file0", -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
else
- ASSERT(0 == memcmp(FilePath + 1, PNameInfo->FileName, PNameInfo->FileNameLength));
+ ASSERT(0 == mywcscmp(FilePath + 1, -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
Success = GetFileInformationByHandle(Handle, &FileInfo);
ASSERT(Success);
diff --git a/tst/winfsp-tests/memfs-test.c b/tst/winfsp-tests/memfs-test.c
index 208d8aed..2e740328 100644
--- a/tst/winfsp-tests/memfs-test.c
+++ b/tst/winfsp-tests/memfs-test.c
@@ -13,8 +13,14 @@ void *memfs_start_ex(ULONG Flags, ULONG FileInfoTimeout)
MEMFS *Memfs;
NTSTATUS Result;
- Result = MemfsCreate(Flags, FileInfoTimeout, 1024, 1024 * 1024,
- MemfsNet == Flags ? L"\\memfs\\share" : 0, 0, &Memfs);
+ Result = MemfsCreate(
+ (OptCaseInsensitive ? MemfsCaseInsensitive : 0) | Flags,
+ FileInfoTimeout,
+ 1024,
+ 1024 * 1024,
+ MemfsNet == Flags ? L"\\memfs\\share" : 0,
+ 0,
+ &Memfs);
ASSERT(NT_SUCCESS(Result));
ASSERT(0 != Memfs);
diff --git a/tst/winfsp-tests/mount-test.c b/tst/winfsp-tests/mount-test.c
index c5303078..24922456 100644
--- a/tst/winfsp-tests/mount-test.c
+++ b/tst/winfsp-tests/mount-test.c
@@ -213,7 +213,7 @@ void mount_volume_transact_dotest(PWSTR DeviceName, PWSTR Prefix)
ASSERT(!Request->Req.Create.CaseSensitive);
ASSERT(0 == Request->FileName.Offset);
ASSERT((wcslen((PVOID)Request->Buffer) + 1) * sizeof(WCHAR) == Request->FileName.Size);
- ASSERT(0 == wcscmp((PVOID)Request->Buffer, L"\\file0"));
+ ASSERT(0 == mywcscmp((PVOID)Request->Buffer, -1, L"\\file0", -1));
}
ASSERT(FspFsctlTransactCanProduceResponse(Response, ResponseBufEnd));
diff --git a/tst/winfsp-tests/stream-tests.c b/tst/winfsp-tests/stream-tests.c
index 03a5824f..5ec3988f 100644
--- a/tst/winfsp-tests/stream-tests.c
+++ b/tst/winfsp-tests/stream-tests.c
@@ -876,11 +876,11 @@ static void stream_getfileinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoT
else
ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR));
if (-1 == Flags)
- ASSERT(0 == memcmp(FilePath + 6, PNameInfo->FileName, PNameInfo->FileNameLength));
+ ASSERT(0 == mywcscmp(FilePath + 6, -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
else if (0 == Prefix)
- ASSERT(0 == memcmp(L"\\file0:foo", PNameInfo->FileName, PNameInfo->FileNameLength));
+ ASSERT(0 == mywcscmp(L"\\file0:foo", -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
else
- ASSERT(0 == memcmp(FilePath + 1, PNameInfo->FileName, PNameInfo->FileNameLength));
+ ASSERT(0 == mywcscmp(FilePath + 1, -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
Success = GetFileInformationByHandle(Handle, &FileInfo);
ASSERT(Success);
@@ -963,11 +963,11 @@ static void stream_getfileinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoT
else
ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR));
if (-1 == Flags)
- ASSERT(0 == memcmp(FilePath + 6, PNameInfo->FileName, PNameInfo->FileNameLength));
+ ASSERT(0 == mywcscmp(FilePath + 6, -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
else if (0 == Prefix)
- ASSERT(0 == memcmp(L"\\file0", PNameInfo->FileName, PNameInfo->FileNameLength));
+ ASSERT(0 == mywcscmp(L"\\file0", -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
else
- ASSERT(0 == memcmp(FilePath + 1, PNameInfo->FileName, PNameInfo->FileNameLength));
+ ASSERT(0 == mywcscmp(FilePath + 1, -1, PNameInfo->FileName, PNameInfo->FileNameLength / sizeof(WCHAR)));
Success = GetFileInformationByHandle(Handle, &FileInfo);
ASSERT(Success);
@@ -1837,11 +1837,11 @@ static void stream_getstreaminfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInf
if (1 > FileCount)
{
FileCount++;
- ASSERT(0 == wcscmp(FindData.cStreamName, L"::$DATA"));
+ ASSERT(0 == mywcscmp(FindData.cStreamName, -1, L"::$DATA", -1));
continue;
}
- ASSERT(0 == wcsncmp(FindData.cStreamName, L":s", 2));
+ ASSERT(0 == mywcscmp(FindData.cStreamName, 2, L":s", 2));
ul = wcstoul(FindData.cStreamName + 2, &endp, 10);
ASSERT(0 != ul);
ASSERT(L':' == *endp);
@@ -1878,7 +1878,7 @@ static void stream_getstreaminfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInf
continue;
}
- ASSERT(0 == wcsncmp(FindData.cStreamName, L":s", 2));
+ ASSERT(0 == mywcscmp(FindData.cStreamName, 2, L":s", 2));
ul = wcstoul(FindData.cStreamName + 2, &endp, 10);
ASSERT(0 != ul);
ASSERT(L':' == *endp);
@@ -1914,7 +1914,7 @@ static void stream_getstreaminfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInf
unsigned long ul;
wchar_t *endp;
- ASSERT(0 == wcsncmp(FindData.cStreamName, L":s", 2));
+ ASSERT(0 == mywcscmp(FindData.cStreamName, 2, L":s", 2));
ul = wcstoul(FindData.cStreamName + 2, &endp, 10);
ASSERT(0 != ul);
ASSERT(L':' == *endp);
@@ -2048,7 +2048,7 @@ static void stream_dirnotify_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTim
ASSERT(6/*FILE_ACTION_ADDED_STREAM*/ == NotifyInfo->Action);
ASSERT(wcslen(L"file0:foo") * sizeof(WCHAR) == NotifyInfo->FileNameLength);
- ASSERT(0 == memcmp(L"file0:foo", NotifyInfo->FileName, NotifyInfo->FileNameLength));
+ ASSERT(0 == mywcscmp(L"file0:foo", -1, NotifyInfo->FileName, NotifyInfo->FileNameLength / sizeof(WCHAR)));
/*
* NTFS never seems to send FILE_ACTION_REMOVED_STREAM notification. So don't do this test on it.
@@ -2070,7 +2070,7 @@ static void stream_dirnotify_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTim
ASSERT(7/*FILE_ACTION_REMOVED_STREAM*/ == NotifyInfo->Action);
ASSERT(wcslen(L"file0:foo") * sizeof(WCHAR) == NotifyInfo->FileNameLength);
- ASSERT(0 == memcmp(L"file0:foo", NotifyInfo->FileName, NotifyInfo->FileNameLength));
+ ASSERT(0 == mywcscmp(L"file0:foo", -1, NotifyInfo->FileName, NotifyInfo->FileNameLength / sizeof(WCHAR)));
ASSERT(0 == NotifyInfo->NextEntryOffset);
}
diff --git a/tst/winfsp-tests/winfsp-tests.c b/tst/winfsp-tests/winfsp-tests.c
index 4ee77d29..41a5fa81 100644
--- a/tst/winfsp-tests/winfsp-tests.c
+++ b/tst/winfsp-tests/winfsp-tests.c
@@ -1,4 +1,5 @@
#include
+#include
#include "winfsp-tests.h"
@@ -6,6 +7,113 @@ int NtfsTests = 0;
int WinFspDiskTests = 1;
int WinFspNetTests = 1;
+BOOLEAN OptCaseInsensitive = FALSE;
+BOOLEAN OptCaseRandomize = FALSE;
+
+int mywcscmp(PWSTR a, int alen, PWSTR b, int blen)
+{
+ int len, res;
+
+ if (-1 == alen)
+ alen = (int)wcslen(a);
+ if (-1 == blen)
+ blen = (int)wcslen(b);
+
+ len = alen < blen ? alen : blen;
+
+ /* we should still be in the C locale */
+ if (OptCaseRandomize)
+ res = _wcsnicmp(a, b, len);
+ else
+ res = wcsncmp(a, b, len);
+
+ if (0 == res)
+ res = alen - blen;
+
+ return res;
+}
+
+#define testalpha(c) ('a' <= ((c) | 0x20) && ((c) | 0x20) <= 'z')
+#define togglealpha(c) ((c) ^ 0x20)
+#undef CreateFileW
+static unsigned myrandseed = 1;
+static int myrand(void)
+{
+ /*
+ * This mimics MSVCRT rand(); we need our own version
+ * as to not interfere with the program's rand().
+ */
+
+ myrandseed = myrandseed * 214013 + 2531011;
+ return (myrandseed >> 16) & RAND_MAX;
+}
+HANDLE HookCreateFileW(
+ LPCWSTR lpFileName,
+ DWORD dwDesiredAccess,
+ DWORD dwShareMode,
+ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
+ DWORD dwCreationDisposition,
+ DWORD dwFlagsAndAttributes,
+ HANDLE hTemplateFile)
+{
+ static WCHAR DevicePrefix[] =
+ L"\\\\?\\GLOBALROOT\\Device\\Volume{01234567-0123-0123-0101-010101010101}\\";
+ static const TogglePercent = 25;
+ WCHAR FileNameBuf[1024];
+ PWSTR P, EndP;
+
+ wcscpy_s(FileNameBuf, sizeof FileNameBuf / sizeof(WCHAR), lpFileName);
+ if (OptCaseRandomize)
+ {
+ if (L'\\' == FileNameBuf[0] && L'\\' == FileNameBuf[1] &&
+ L'?' == FileNameBuf[2] && L'\\' == FileNameBuf[3] &&
+ testalpha(FileNameBuf[4]) && L':' == FileNameBuf[5] && L'\\' == FileNameBuf[6])
+ P = FileNameBuf + 7;
+ else if (0 == wcsncmp(FileNameBuf, DevicePrefix, wcschr(DevicePrefix, L'{') - DevicePrefix))
+ P = FileNameBuf + wcslen(DevicePrefix);
+ else if (L'\\' == FileNameBuf[0] && L'\\' == FileNameBuf[1])
+ P = FileNameBuf + 2;
+ else if (testalpha(FileNameBuf[0]) && L':' == FileNameBuf[1] && L'\\' == FileNameBuf[2])
+ P = FileNameBuf + 3;
+ else
+ abort();
+
+ for (EndP = P + wcslen(P); EndP > P; P++)
+ if (testalpha(*P) && myrand() <= (TogglePercent) * 0x7fff / 100)
+ *P = togglealpha(*P);
+ }
+
+ HANDLE h = CreateFileW(
+ FileNameBuf,
+ dwDesiredAccess,
+ dwShareMode,
+ lpSecurityAttributes,
+ dwCreationDisposition,
+ dwFlagsAndAttributes,
+ hTemplateFile);
+
+#if 0
+ DWORD LastError = GetLastError();
+ FspDebugLog("CreateFileW(\"%S\", %#lx, %#lx, %p, %#lx, %#lx, %p) = %p[%#lx]\n",
+ FileNameBuf,
+ dwDesiredAccess,
+ dwShareMode,
+ lpSecurityAttributes,
+ dwCreationDisposition,
+ dwFlagsAndAttributes,
+ hTemplateFile,
+ h, INVALID_HANDLE_VALUE != h ? 0 : LastError);
+ SetLastError(LastError);
+#endif
+
+ return h;
+}
+
+#define rmarg(argv, argc, argi) \
+ argc--,\
+ memmove(argv + argi, argv + argi + 1, (argc - argi) * sizeof(char *)),\
+ argi--,\
+ argv[argc] = 0
int main(int argc, char *argv[])
{
TESTSUITE(fuse_opt_tests);
@@ -25,6 +133,27 @@ int main(int argc, char *argv[])
TESTSUITE(reparse_tests);
TESTSUITE(stream_tests);
+ for (int argi = 1; argc > argi; argi++)
+ {
+ const char *a = argv[argi];
+ if ('-' == a[0])
+ {
+ if (0 == strcmp("--case-insensitive", a))
+ {
+ OptCaseInsensitive = TRUE;
+ rmarg(argv, argc, argi);
+ }
+ else if (0 == strcmp("--case-randomize", a))
+ {
+ OptCaseRandomize = TRUE;
+ OptCaseInsensitive = TRUE;
+ rmarg(argv, argc, argi);
+ }
+ }
+ }
+
+ myrandseed = (unsigned)time(0);
+
tlib_run_tests(argc, argv);
return 0;
}
diff --git a/tst/winfsp-tests/winfsp-tests.h b/tst/winfsp-tests/winfsp-tests.h
index 8a3c886d..16952d03 100644
--- a/tst/winfsp-tests/winfsp-tests.h
+++ b/tst/winfsp-tests/winfsp-tests.h
@@ -9,7 +9,12 @@ extern int NtfsTests;
extern int WinFspDiskTests;
extern int WinFspNetTests;
-//#define CreateFileW HookCreateFileW
+extern BOOLEAN OptCaseInsensitive;
+extern BOOLEAN OptCaseRandomize;
+
+int mywcscmp(PWSTR a, int alen, PWSTR b, int blen);
+
+#define CreateFileW HookCreateFileW
HANDLE HookCreateFileW(
LPCWSTR lpFileName,
DWORD dwDesiredAccess,