mirror of
https://github.com/winfsp/winfsp.git
synced 2025-06-15 00:02:46 -05:00
dll: FspPathPrefix(), FspPathSuffix(): better root handling
This commit is contained in:
@ -133,10 +133,11 @@ static inline
|
||||
MEMFS_FILE_NODE *MemfsFileNodeMapGetParent(MEMFS_FILE_NODE_MAP *FileNodeMap, PWSTR FileName,
|
||||
PNTSTATUS PResult)
|
||||
{
|
||||
WCHAR Root[2] = L"\\";
|
||||
PWSTR Remain, Suffix;
|
||||
FspPathSuffix(FileName, &Remain, &Suffix);
|
||||
FspPathSuffix(FileName, &Remain, &Suffix, Root);
|
||||
MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->find(Remain);
|
||||
FspPathCombine(Remain, Suffix);
|
||||
FspPathCombine(FileName, Suffix);
|
||||
if (iter == FileNodeMap->end())
|
||||
{
|
||||
*PResult = STATUS_OBJECT_PATH_NOT_FOUND;
|
||||
@ -179,13 +180,14 @@ static inline
|
||||
BOOLEAN MemfsFileNodeMapHasChild(MEMFS_FILE_NODE_MAP *FileNodeMap, MEMFS_FILE_NODE *FileNode)
|
||||
{
|
||||
BOOLEAN Result;
|
||||
WCHAR Root[2] = L"\\";
|
||||
PWSTR Remain, Suffix;
|
||||
MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->upper_bound(FileNode->FileName);
|
||||
if (iter == FileNodeMap->end())
|
||||
return FALSE;
|
||||
FspPathSuffix(iter->second->FileName, &Remain, &Suffix);
|
||||
FspPathSuffix(iter->second->FileName, &Remain, &Suffix, Root);
|
||||
Result = 0 == MemfsFileNameCompare(Remain, FileNode->FileName);
|
||||
FspPathCombine(Remain, Suffix);
|
||||
FspPathCombine(iter->second->FileName, Suffix);
|
||||
return Result;
|
||||
}
|
||||
|
||||
@ -196,7 +198,7 @@ static NTSTATUS GetVolumeInfo(FSP_FILE_SYSTEM *FileSystem,
|
||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
||||
MEMFS_FILE_NODE *RootNode;
|
||||
|
||||
RootNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, L"");
|
||||
RootNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, L"\\");
|
||||
if (0 == RootNode)
|
||||
return STATUS_DISK_CORRUPT_ERROR;
|
||||
|
||||
@ -218,9 +220,6 @@ static NTSTATUS GetSecurity(FSP_FILE_SYSTEM *FileSystem,
|
||||
MEMFS_FILE_NODE *FileNode;
|
||||
NTSTATUS Result;
|
||||
|
||||
if (L'\\' == FileName[0] && L'\0' == FileName[1])
|
||||
FileName = L"";
|
||||
|
||||
FileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, FileName);
|
||||
if (0 == FileNode)
|
||||
{
|
||||
@ -259,9 +258,6 @@ static NTSTATUS Create(FSP_FILE_SYSTEM *FileSystem,
|
||||
NTSTATUS Result;
|
||||
BOOLEAN Inserted;
|
||||
|
||||
if (L'\\' == FileName[0] && L'\0' == FileName[1])
|
||||
FileName = L"";
|
||||
|
||||
if (CreateOptions & FILE_DIRECTORY_FILE)
|
||||
AllocationSize = 0;
|
||||
|
||||
@ -332,9 +328,6 @@ static NTSTATUS Open(FSP_FILE_SYSTEM *FileSystem,
|
||||
MEMFS_FILE_NODE *FileNode;
|
||||
NTSTATUS Result;
|
||||
|
||||
if (L'\\' == FileName[0] && L'\0' == FileName[1])
|
||||
FileName = L"";
|
||||
|
||||
FileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, FileName);
|
||||
if (0 == FileNode)
|
||||
{
|
||||
@ -635,7 +628,7 @@ NTSTATUS MemfsCreate(ULONG Flags, ULONG FileInfoTimeout,
|
||||
* Create root directory.
|
||||
*/
|
||||
|
||||
Result = MemfsFileNodeCreate(L"", &RootNode);
|
||||
Result = MemfsFileNodeCreate(L"\\", &RootNode);
|
||||
if (!NT_SUCCESS(Result))
|
||||
{
|
||||
MemfsDelete(Memfs);
|
||||
|
@ -19,16 +19,17 @@ void path_prefix_test(void)
|
||||
L"foo\\\\\\bar\\\\baz",
|
||||
L"foo\\\\\\bar\\\\baz\\",
|
||||
L"foo\\\\\\bar\\\\baz\\\\",
|
||||
L"foo",
|
||||
};
|
||||
PWSTR opaths[] =
|
||||
{
|
||||
L"", L"",
|
||||
L"", L"",
|
||||
L"", L"",
|
||||
L"", L"a",
|
||||
L"", L"a",
|
||||
L"", L"a\\",
|
||||
L"", L"a\\\\",
|
||||
L"ROOT", L"",
|
||||
L"ROOT", L"",
|
||||
L"ROOT", L"a",
|
||||
L"ROOT", L"a",
|
||||
L"ROOT", L"a\\",
|
||||
L"ROOT", L"a\\\\",
|
||||
L"a", L"",
|
||||
L"a", L"",
|
||||
L"a", L"b",
|
||||
@ -36,6 +37,7 @@ void path_prefix_test(void)
|
||||
L"foo", L"bar\\\\baz",
|
||||
L"foo", L"bar\\\\baz\\",
|
||||
L"foo", L"bar\\\\baz\\\\",
|
||||
L"foo", L"",
|
||||
};
|
||||
|
||||
for (size_t i = 0; sizeof ipaths / sizeof ipaths[0] > i; i++)
|
||||
@ -43,10 +45,10 @@ void path_prefix_test(void)
|
||||
PWSTR Prefix, Remain;
|
||||
WCHAR buf[32];
|
||||
wcscpy_s(buf, 32, ipaths[i]);
|
||||
FspPathPrefix(buf, &Prefix, &Remain);
|
||||
FspPathPrefix(buf, &Prefix, &Remain, L"ROOT");
|
||||
ASSERT(0 == wcscmp(opaths[2 * i + 0], Prefix));
|
||||
ASSERT(0 == wcscmp(opaths[2 * i + 1], Remain));
|
||||
FspPathCombine(Prefix, Remain);
|
||||
FspPathCombine(buf, Remain);
|
||||
ASSERT(0 == wcscmp(ipaths[i], buf));
|
||||
}
|
||||
}
|
||||
@ -69,14 +71,15 @@ void path_suffix_test(void)
|
||||
L"foo\\\\\\bar\\\\baz",
|
||||
L"foo\\\\\\bar\\\\baz\\",
|
||||
L"foo\\\\\\bar\\\\baz\\\\",
|
||||
L"foo",
|
||||
};
|
||||
PWSTR opaths[] =
|
||||
{
|
||||
L"", L"",
|
||||
L"", L"",
|
||||
L"", L"",
|
||||
L"", L"a",
|
||||
L"", L"a",
|
||||
L"ROOT", L"",
|
||||
L"ROOT", L"",
|
||||
L"ROOT", L"a",
|
||||
L"ROOT", L"a",
|
||||
L"\\\\a", L"",
|
||||
L"\\\\a", L"",
|
||||
L"a", L"",
|
||||
@ -86,6 +89,7 @@ void path_suffix_test(void)
|
||||
L"foo\\\\\\bar", L"baz",
|
||||
L"foo\\\\\\bar\\\\baz", L"",
|
||||
L"foo\\\\\\bar\\\\baz", L"",
|
||||
L"foo", L"",
|
||||
};
|
||||
|
||||
for (size_t i = 0; sizeof ipaths / sizeof ipaths[0] > i; i++)
|
||||
@ -93,10 +97,10 @@ void path_suffix_test(void)
|
||||
PWSTR Remain, Suffix;
|
||||
WCHAR buf[32];
|
||||
wcscpy_s(buf, 32, ipaths[i]);
|
||||
FspPathSuffix(buf, &Remain, &Suffix);
|
||||
FspPathSuffix(buf, &Remain, &Suffix, L"ROOT");
|
||||
ASSERT(0 == wcscmp(opaths[2 * i + 0], Remain));
|
||||
ASSERT(0 == wcscmp(opaths[2 * i + 1], Suffix));
|
||||
FspPathCombine(Remain, Suffix);
|
||||
FspPathCombine(buf, Suffix);
|
||||
ASSERT(0 == wcscmp(ipaths[i], buf));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user