tst: test case insensitivity

sys: FspFileNameIsValid: $DATA is case insensitive
This commit is contained in:
Bill Zissimopoulos 2016-10-15 19:49:56 -07:00
parent 5773c6eab7
commit 3ed7847d84
14 changed files with 239 additions and 90 deletions

View File

@ -186,7 +186,6 @@
<ClCompile Include="..\..\..\tst\winfsp-tests\eventlog-test.c" /> <ClCompile Include="..\..\..\tst\winfsp-tests\eventlog-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\flush-test.c" /> <ClCompile Include="..\..\..\tst\winfsp-tests\flush-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\fuse-opt-test.c" /> <ClCompile Include="..\..\..\tst\winfsp-tests\fuse-opt-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\hook.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\info-test.c" /> <ClCompile Include="..\..\..\tst\winfsp-tests\info-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\lock-test.c" /> <ClCompile Include="..\..\..\tst\winfsp-tests\lock-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\memfs-test.c" /> <ClCompile Include="..\..\..\tst\winfsp-tests\memfs-test.c" />

View File

@ -64,9 +64,6 @@
<ClCompile Include="..\..\..\tst\winfsp-tests\reparse-test.c"> <ClCompile Include="..\..\..\tst\winfsp-tests\reparse-test.c">
<Filter>Source</Filter> <Filter>Source</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\tst\winfsp-tests\hook.c">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="..\..\..\tst\winfsp-tests\stream-tests.c"> <ClCompile Include="..\..\..\tst\winfsp-tests\stream-tests.c">
<Filter>Source</Filter> <Filter>Source</Filter>
</ClCompile> </ClCompile>

View File

@ -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 we had a stream type the path is valid if the stream type was "$DATA" only */
if (StreamTypeStr + 5 == PathEnd && if (StreamTypeStr + 5 == PathEnd &&
L'$' == StreamTypeStr[0] && L'$' == StreamTypeStr[0] &&
L'D' == StreamTypeStr[1] && L'd' == (StreamTypeStr[1] | 0x20) &&
L'A' == StreamTypeStr[2] && L'a' == (StreamTypeStr[2] | 0x20) &&
L'T' == StreamTypeStr[3] && L't' == (StreamTypeStr[3] | 0x20) &&
L'A' == StreamTypeStr[4]) L'a' == (StreamTypeStr[4] | 0x20))
{ {
*StreamType = FspFileNameStreamTypeData; *StreamType = FspFileNameStreamTypeData;
return TRUE; return TRUE;

View File

@ -39,6 +39,7 @@ NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
wchar_t **argp, **arge; wchar_t **argp, **arge;
ULONG DebugFlags = 0; ULONG DebugFlags = 0;
PWSTR DebugLogFile = 0; PWSTR DebugLogFile = 0;
ULONG CaseInsensitiveFlags = 0;
ULONG Flags = MemfsDisk; ULONG Flags = MemfsDisk;
ULONG FileInfoTimeout = INFINITE; ULONG FileInfoTimeout = INFINITE;
ULONG MaxFileNodes = 1024; ULONG MaxFileNodes = 1024;
@ -64,6 +65,9 @@ NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
case L'D': case L'D':
argtos(DebugLogFile); argtos(DebugLogFile);
break; break;
case L'i':
CaseInsensitiveFlags = MemfsCaseInsensitive;
break;
case L'm': case L'm':
argtos(MountPoint); argtos(MountPoint);
break; break;
@ -117,7 +121,13 @@ NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
FspDebugLogSetHandle(DebugLogHandle); FspDebugLogSetHandle(DebugLogHandle);
} }
Result = MemfsCreate(Flags, FileInfoTimeout, MaxFileNodes, MaxFileSize, VolumePrefix, RootSddl, Result = MemfsCreate(
CaseInsensitiveFlags | Flags,
FileInfoTimeout,
MaxFileNodes,
MaxFileSize,
VolumePrefix,
RootSddl,
&Memfs); &Memfs);
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Result))
{ {
@ -170,6 +180,7 @@ usage:
"options:\n" "options:\n"
" -d DebugFlags [-1: enable all debug logs]\n" " -d DebugFlags [-1: enable all debug logs]\n"
" -D DebugLogFile [file path; use - for stdout]\n" " -D DebugLogFile [file path; use - for stdout]\n"
" -i [case insensitive file system]\n"
" -t FileInfoTimeout [millis]\n" " -t FileInfoTimeout [millis]\n"
" -n MaxFileNodes\n" " -n MaxFileNodes\n"
" -s MaxFileSize [bytes]\n" " -s MaxFileSize [bytes]\n"

View File

@ -47,18 +47,42 @@ UINT64 MemfsGetSystemTime(VOID)
} }
static inline 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 static inline
BOOLEAN MemfsFileNameHasPrefix(PWSTR a, PWSTR b) int MemfsFileNameCompare(PWSTR a, PWSTR b, BOOLEAN CaseInsensitive)
{ {
size_t alen = wcslen(a); return MemfsCompareString(a, -1, b, -1, CaseInsensitive);
size_t blen = wcslen(b); }
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]) || (alen == blen || (1 == blen && L'\\' == b[0]) ||
#if defined(MEMFS_NAMED_STREAMS) #if defined(MEMFS_NAMED_STREAMS)
(L'\\' == a[blen] || L':' == a[blen])); (L'\\' == a[blen] || L':' == a[blen]));
@ -84,10 +108,14 @@ typedef struct _MEMFS_FILE_NODE
struct MEMFS_FILE_NODE_LESS struct MEMFS_FILE_NODE_LESS
{ {
MEMFS_FILE_NODE_LESS(BOOLEAN CaseInsensitive) : CaseInsensitive(CaseInsensitive)
{
}
bool operator()(PWSTR a, PWSTR b) const bool operator()(PWSTR a, PWSTR b) const
{ {
return 0 > MemfsFileNameCompare(a, b); return 0 > MemfsFileNameCompare(a, b, CaseInsensitive);
} }
BOOLEAN CaseInsensitive;
}; };
typedef std::map<PWSTR, MEMFS_FILE_NODE *, MEMFS_FILE_NODE_LESS> MEMFS_FILE_NODE_MAP; typedef std::map<PWSTR, MEMFS_FILE_NODE *, MEMFS_FILE_NODE_LESS> MEMFS_FILE_NODE_MAP;
@ -169,12 +197,18 @@ VOID MemfsFileNodeMapDump(MEMFS_FILE_NODE_MAP *FileNodeMap)
} }
static inline 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; *PFileNodeMap = 0;
try try
{ {
*PFileNodeMap = new MEMFS_FILE_NODE_MAP; *PFileNodeMap = new MEMFS_FILE_NODE_MAP(MEMFS_FILE_NODE_LESS(CaseInsensitive));
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
catch (...) catch (...)
@ -287,7 +321,8 @@ BOOLEAN MemfsFileNodeMapHasChild(MEMFS_FILE_NODE_MAP *FileNodeMap, MEMFS_FILE_NO
continue; continue;
#endif #endif
FspPathSuffix(iter->second->FileName, &Remain, &Suffix, Root); 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); FspPathCombine(iter->second->FileName, Suffix);
break; break;
} }
@ -304,10 +339,12 @@ BOOLEAN MemfsFileNodeMapEnumerateChildren(MEMFS_FILE_NODE_MAP *FileNodeMap, MEMF
BOOLEAN IsDirectoryChild; BOOLEAN IsDirectoryChild;
for (; FileNodeMap->end() != iter; ++iter) for (; FileNodeMap->end() != iter; ++iter)
{ {
if (!MemfsFileNameHasPrefix(iter->second->FileName, FileNode->FileName)) if (!MemfsFileNameHasPrefix(iter->second->FileName, FileNode->FileName,
MemfsFileNodeMapIsCaseInsensitive(FileNodeMap)))
break; break;
FspPathSuffix(iter->second->FileName, &Remain, &Suffix, Root); 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) #if defined(MEMFS_NAMED_STREAMS)
IsDirectoryChild = IsDirectoryChild && 0 == wcschr(Suffix, L':'); IsDirectoryChild = IsDirectoryChild && 0 == wcschr(Suffix, L':');
#endif #endif
@ -329,7 +366,8 @@ BOOLEAN MemfsFileNodeMapEnumerateNamedStreams(MEMFS_FILE_NODE_MAP *FileNodeMap,
MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->upper_bound(FileNode->FileName); MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->upper_bound(FileNode->FileName);
for (; FileNodeMap->end() != iter; ++iter) for (; FileNodeMap->end() != iter; ++iter)
{ {
if (!MemfsFileNameHasPrefix(iter->second->FileName, FileNode->FileName)) if (!MemfsFileNameHasPrefix(iter->second->FileName, FileNode->FileName,
MemfsFileNodeMapIsCaseInsensitive(FileNodeMap)))
break; break;
if (L':' != iter->second->FileName[wcslen(FileNode->FileName)]) if (L':' != iter->second->FileName[wcslen(FileNode->FileName)])
break; break;
@ -348,7 +386,8 @@ BOOLEAN MemfsFileNodeMapEnumerateDescendants(MEMFS_FILE_NODE_MAP *FileNodeMap, M
MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->lower_bound(FileNode->FileName); MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->lower_bound(FileNode->FileName);
for (; FileNodeMap->end() != iter; ++iter) for (; FileNodeMap->end() != iter; ++iter)
{ {
if (!MemfsFileNameHasPrefix(iter->second->FileName, FileNode->FileName)) if (!MemfsFileNameHasPrefix(iter->second->FileName, FileNode->FileName,
MemfsFileNodeMapIsCaseInsensitive(FileNodeMap)))
break; break;
if (!EnumFn(iter->second, Context)) if (!EnumFn(iter->second, Context))
return FALSE; return FALSE;
@ -615,7 +654,6 @@ static VOID Cleanup(FSP_FILE_SYSTEM *FileSystem,
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext; MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
MEMFS_FILE_NODE *FileNode = (MEMFS_FILE_NODE *)FileNode0; 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 */ assert(Delete); /* the new FSP_FSCTL_VOLUME_PARAMS::PostCleanupOnDeleteOnly ensures this */
if (Delete && !MemfsFileNodeMapHasChild(Memfs->FileNodeMap, FileNode)) if (Delete && !MemfsFileNodeMapHasChild(Memfs->FileNodeMap, FileNode))
@ -828,8 +866,6 @@ static NTSTATUS CanDelete(FSP_FILE_SYSTEM *FileSystem,
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext; MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
MEMFS_FILE_NODE *FileNode = (MEMFS_FILE_NODE *)FileNode0; MEMFS_FILE_NODE *FileNode = (MEMFS_FILE_NODE *)FileNode0;
assert(0 == FileName || 0 == wcscmp(FileNode->FileName, FileName));
if (MemfsFileNodeMapHasChild(Memfs->FileNodeMap, FileNode)) if (MemfsFileNodeMapHasChild(Memfs->FileNodeMap, FileNode))
return STATUS_DIRECTORY_NOT_EMPTY; return STATUS_DIRECTORY_NOT_EMPTY;
@ -865,8 +901,6 @@ static NTSTATUS Rename(FSP_FILE_SYSTEM *FileSystem,
BOOLEAN Inserted; BOOLEAN Inserted;
NTSTATUS Result; NTSTATUS Result;
assert(0 == FileName || 0 == wcscmp(FileNode->FileName, FileName));
NewFileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, NewFileName); NewFileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, NewFileName);
if (0 != NewFileNode) if (0 != NewFileNode)
{ {
@ -897,7 +931,6 @@ static NTSTATUS Rename(FSP_FILE_SYSTEM *FileSystem,
for (Index = 0; Context.Count > Index; Index++) for (Index = 0; Context.Count > Index; Index++)
{ {
DescendantFileNode = Context.FileNodes[Index]; DescendantFileNode = Context.FileNodes[Index];
assert(MemfsFileNameHasPrefix(DescendantFileNode->FileName, FileNode->FileName));
if (MAX_PATH <= wcslen(DescendantFileNode->FileName) - FileNameLen + NewFileNameLen) if (MAX_PATH <= wcslen(DescendantFileNode->FileName) - FileNameLen + NewFileNameLen)
{ {
Result = STATUS_OBJECT_NAME_INVALID; Result = STATUS_OBJECT_NAME_INVALID;
@ -1339,6 +1372,7 @@ NTSTATUS MemfsCreate(
{ {
NTSTATUS Result; NTSTATUS Result;
FSP_FSCTL_VOLUME_PARAMS VolumeParams; FSP_FSCTL_VOLUME_PARAMS VolumeParams;
BOOLEAN CaseInsensitive = !!(Flags & MemfsCaseInsensitive);
PWSTR DevicePath = (Flags & MemfsNet) ? PWSTR DevicePath = (Flags & MemfsNet) ?
L"" FSP_FSCTL_NET_DEVICE_NAME : L"" FSP_FSCTL_DISK_DEVICE_NAME; L"" FSP_FSCTL_NET_DEVICE_NAME : L"" FSP_FSCTL_DISK_DEVICE_NAME;
UINT64 AllocationUnit; UINT64 AllocationUnit;
@ -1368,7 +1402,7 @@ NTSTATUS MemfsCreate(
AllocationUnit = MEMFS_SECTOR_SIZE * MEMFS_SECTORS_PER_ALLOCATION_UNIT; AllocationUnit = MEMFS_SECTOR_SIZE * MEMFS_SECTORS_PER_ALLOCATION_UNIT;
Memfs->MaxFileSize = (ULONG)((MaxFileSize + AllocationUnit - 1) / AllocationUnit * AllocationUnit); Memfs->MaxFileSize = (ULONG)((MaxFileSize + AllocationUnit - 1) / AllocationUnit * AllocationUnit);
Result = MemfsFileNodeMapCreate(&Memfs->FileNodeMap); Result = MemfsFileNodeMapCreate(CaseInsensitive, &Memfs->FileNodeMap);
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Result))
{ {
free(Memfs); free(Memfs);
@ -1382,7 +1416,7 @@ NTSTATUS MemfsCreate(
VolumeParams.VolumeCreationTime = MemfsGetSystemTime(); VolumeParams.VolumeCreationTime = MemfsGetSystemTime();
VolumeParams.VolumeSerialNumber = (UINT32)(MemfsGetSystemTime() / (10000 * 1000)); VolumeParams.VolumeSerialNumber = (UINT32)(MemfsGetSystemTime() / (10000 * 1000));
VolumeParams.FileInfoTimeout = FileInfoTimeout; VolumeParams.FileInfoTimeout = FileInfoTimeout;
VolumeParams.CaseSensitiveSearch = 1; VolumeParams.CaseSensitiveSearch = !CaseInsensitive;
VolumeParams.CasePreservedNames = 1; VolumeParams.CasePreservedNames = 1;
VolumeParams.UnicodeOnDisk = 1; VolumeParams.UnicodeOnDisk = 1;
VolumeParams.PersistentAcls = 1; VolumeParams.PersistentAcls = 1;

View File

@ -30,6 +30,7 @@ enum
{ {
MemfsDisk = 0x00, MemfsDisk = 0x00,
MemfsNet = 0x01, MemfsNet = 0x01,
MemfsCaseInsensitive = 0x80,
}; };
NTSTATUS MemfsCreate( NTSTATUS MemfsCreate(

View File

@ -64,12 +64,12 @@ static void querydir_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout, UL
FileCount++; FileCount++;
ASSERT(0 != (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)); ASSERT(0 != (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
ASSERT(FileCount == wcslen(FindData.cFileName)); ASSERT(FileCount == wcslen(FindData.cFileName));
ASSERT(0 == wcsncmp(FindData.cFileName, L"..", FileCount)); ASSERT(0 == mywcscmp(FindData.cFileName, FileCount, L"..", FileCount));
continue; continue;
} }
ASSERT(0 == (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)); 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); ul = wcstoul(FindData.cFileName + 4, &endp, 10);
ASSERT(0 != ul); ASSERT(0 != ul);
ASSERT(L'\0' == *endp); ASSERT(L'\0' == *endp);
@ -100,7 +100,7 @@ static void querydir_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout, UL
wchar_t *endp; wchar_t *endp;
ASSERT(0 != (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)); 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); ul = wcstoul(FindData.cFileName + 3, &endp, 10);
ASSERT(0 != ul); ASSERT(0 != ul);
ASSERT(L'\0' == *endp); 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*/; size_t wcscnt = sizeof "fileABCDEFGHIJKLMNOPQRSTUVXWYZfile" - 1/* count of wchar_t*/;
ASSERT(0 == (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)); 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); ul = wcstoul(FindData.cFileName + wcscnt, &endp, 10);
ASSERT(0 != ul); ASSERT(0 != ul);
ASSERT(L'\0' == *endp); 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(FILE_ACTION_ADDED == NotifyInfo->Action);
ASSERT(wcslen(L"file0") * sizeof(WCHAR) == NotifyInfo->FileNameLength); 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) 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(FILE_ACTION_REMOVED == NotifyInfo->Action);
ASSERT(wcslen(L"file0") * sizeof(WCHAR) == NotifyInfo->FileNameLength); 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); ASSERT(0 == NotifyInfo->NextEntryOffset);

View File

@ -1,34 +0,0 @@
#include <winfsp/winfsp.h>
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;
}

View File

@ -84,11 +84,11 @@ void getfileinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout)
else else
ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR)); ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR));
if (-1 == Flags) 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) 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 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); Success = GetFileInformationByHandle(Handle, &FileInfo);
ASSERT(Success); ASSERT(Success);

View File

@ -13,8 +13,14 @@ void *memfs_start_ex(ULONG Flags, ULONG FileInfoTimeout)
MEMFS *Memfs; MEMFS *Memfs;
NTSTATUS Result; NTSTATUS Result;
Result = MemfsCreate(Flags, FileInfoTimeout, 1024, 1024 * 1024, Result = MemfsCreate(
MemfsNet == Flags ? L"\\memfs\\share" : 0, 0, &Memfs); (OptCaseInsensitive ? MemfsCaseInsensitive : 0) | Flags,
FileInfoTimeout,
1024,
1024 * 1024,
MemfsNet == Flags ? L"\\memfs\\share" : 0,
0,
&Memfs);
ASSERT(NT_SUCCESS(Result)); ASSERT(NT_SUCCESS(Result));
ASSERT(0 != Memfs); ASSERT(0 != Memfs);

View File

@ -213,7 +213,7 @@ void mount_volume_transact_dotest(PWSTR DeviceName, PWSTR Prefix)
ASSERT(!Request->Req.Create.CaseSensitive); ASSERT(!Request->Req.Create.CaseSensitive);
ASSERT(0 == Request->FileName.Offset); ASSERT(0 == Request->FileName.Offset);
ASSERT((wcslen((PVOID)Request->Buffer) + 1) * sizeof(WCHAR) == Request->FileName.Size); 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)); ASSERT(FspFsctlTransactCanProduceResponse(Response, ResponseBufEnd));

View File

@ -876,11 +876,11 @@ static void stream_getfileinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoT
else else
ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR)); ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR));
if (-1 == Flags) 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) 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 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); Success = GetFileInformationByHandle(Handle, &FileInfo);
ASSERT(Success); ASSERT(Success);
@ -963,11 +963,11 @@ static void stream_getfileinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoT
else else
ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR)); ASSERT(PNameInfo->FileNameLength == wcslen(FilePath + 1) * sizeof(WCHAR));
if (-1 == Flags) 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) 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 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); Success = GetFileInformationByHandle(Handle, &FileInfo);
ASSERT(Success); ASSERT(Success);
@ -1837,11 +1837,11 @@ static void stream_getstreaminfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInf
if (1 > FileCount) if (1 > FileCount)
{ {
FileCount++; FileCount++;
ASSERT(0 == wcscmp(FindData.cStreamName, L"::$DATA")); ASSERT(0 == mywcscmp(FindData.cStreamName, -1, L"::$DATA", -1));
continue; 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); ul = wcstoul(FindData.cStreamName + 2, &endp, 10);
ASSERT(0 != ul); ASSERT(0 != ul);
ASSERT(L':' == *endp); ASSERT(L':' == *endp);
@ -1878,7 +1878,7 @@ static void stream_getstreaminfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInf
continue; 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); ul = wcstoul(FindData.cStreamName + 2, &endp, 10);
ASSERT(0 != ul); ASSERT(0 != ul);
ASSERT(L':' == *endp); ASSERT(L':' == *endp);
@ -1914,7 +1914,7 @@ static void stream_getstreaminfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInf
unsigned long ul; unsigned long ul;
wchar_t *endp; 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); ul = wcstoul(FindData.cStreamName + 2, &endp, 10);
ASSERT(0 != ul); ASSERT(0 != ul);
ASSERT(L':' == *endp); 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(6/*FILE_ACTION_ADDED_STREAM*/ == NotifyInfo->Action);
ASSERT(wcslen(L"file0:foo") * sizeof(WCHAR) == NotifyInfo->FileNameLength); 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. * 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(7/*FILE_ACTION_REMOVED_STREAM*/ == NotifyInfo->Action);
ASSERT(wcslen(L"file0:foo") * sizeof(WCHAR) == NotifyInfo->FileNameLength); 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); ASSERT(0 == NotifyInfo->NextEntryOffset);
} }

View File

@ -1,4 +1,5 @@
#include <tlib/testsuite.h> #include <tlib/testsuite.h>
#include <time.h>
#include "winfsp-tests.h" #include "winfsp-tests.h"
@ -6,6 +7,113 @@ int NtfsTests = 0;
int WinFspDiskTests = 1; int WinFspDiskTests = 1;
int WinFspNetTests = 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[]) int main(int argc, char *argv[])
{ {
TESTSUITE(fuse_opt_tests); TESTSUITE(fuse_opt_tests);
@ -25,6 +133,27 @@ int main(int argc, char *argv[])
TESTSUITE(reparse_tests); TESTSUITE(reparse_tests);
TESTSUITE(stream_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); tlib_run_tests(argc, argv);
return 0; return 0;
} }

View File

@ -9,7 +9,12 @@ extern int NtfsTests;
extern int WinFspDiskTests; extern int WinFspDiskTests;
extern int WinFspNetTests; 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( HANDLE HookCreateFileW(
LPCWSTR lpFileName, LPCWSTR lpFileName,
DWORD dwDesiredAccess, DWORD dwDesiredAccess,