Skip to content

Commit

Permalink
Fix ReadDirectory marker bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceiridge committed Jan 1, 2023
1 parent e72426d commit a2c7dde
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 28 deletions.
4 changes: 0 additions & 4 deletions WinFsp-MemFs-Extended/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ FSP_FILE_SYSTEM* MemFs::GetRawFileSystem() const {
return this->fileSystem.get();
}

FileNodeMap& MemFs::GetRawFileMap() {
return this->fileMap;
}

std::wstring& MemFs::GetVolumeLabel() {
return this->volumeLabel;
}
Expand Down
9 changes: 5 additions & 4 deletions WinFsp-MemFs-Extended/comparisons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ namespace Memfs::Utils {
int v = 0;
for (const void* e = t + n; e > (const void*)t; ++s, ++t)
{
unsigned sc = *s, tc = *t;
const unsigned sc = *s;
const unsigned tc = *t;

if (0xffffff80 & (sc | tc))
{
v = CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, s0, n, t0, n);
Expand Down Expand Up @@ -83,7 +85,7 @@ namespace Memfs::Utils {

len = plen < qlen ? plen : qlen;

if (caseInsensitive) {
if (caseInsensitive) [[likely]] {
res = EfficientWcsnicmp(partp, partq, len);
} else
res = wcsncmp(partp, partq, len);
Expand All @@ -110,9 +112,8 @@ namespace Memfs::Utils {
int EaNameCompare(const PCSTR a, const PCSTR b) {
/* EA names are always case-insensitive in MEMFS (to be inline with NTFS) */

int res;
int res = CompareStringA(LOCALE_INVARIANT, NORM_IGNORECASE, a, -1, b, -1);

res = CompareStringA(LOCALE_INVARIANT, NORM_IGNORECASE, a, -1, b, -1);
if (0 != res)
res -= 2;
else
Expand Down
11 changes: 4 additions & 7 deletions WinFsp-MemFs-Extended/dirinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Memfs::Interface {
NTSTATUS ReadDirectory(FSP_FILE_SYSTEM* fileSystem,
PVOID fileNode0, PWSTR pattern, PWSTR marker,
PVOID buffer, ULONG length, PULONG pBytesTransferred) {
PVOID fileNode0, PWSTR pattern, PWSTR marker,
PVOID buffer, ULONG length, PULONG pBytesTransferred) {
assert(nullptr == pattern);

MemFs* memfs = GetMemFs(fileSystem);
Expand Down Expand Up @@ -33,10 +33,7 @@ namespace Memfs::Interface {
}
}

const std::wstring_view markerView = marker ? marker : L"";
const std::refoptional<const std::wstring_view> markerOpt = (marker == nullptr) ? std::nullopt : std::make_optional(markerView);

for (const auto& child : memfs->EnumerateDirChildren(*fileNode, markerOpt)) {
for (const auto& child : memfs->EnumerateDirChildren(*fileNode, marker)) {
if (!CompatAddDirInfo(child, nullptr, buffer, length, pBytesTransferred)) {
return STATUS_SUCCESS; // Without end
}
Expand All @@ -47,7 +44,7 @@ namespace Memfs::Interface {
}

NTSTATUS GetDirInfoByName(FSP_FILE_SYSTEM* fileSystem,
PVOID parentNode0, PWSTR fileName, FSP_FSCTL_DIR_INFO* dirInfo) {
PVOID parentNode0, PWSTR fileName, FSP_FSCTL_DIR_INFO* dirInfo) {
MemFs* memfs = GetMemFs(fileSystem);
FileNode* parentNode = GetFileNode(parentNode0);

Expand Down
15 changes: 6 additions & 9 deletions WinFsp-MemFs-Extended/filemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ bool MemFs::HasChild(const FileNode& node) {

std::pair<NTSTATUS, FileNode*> MemFs::InsertNode(FileNode* node) {
try {
std::wstring fileName = node->fileName;
const auto [iter, success] = this->fileMap.insert(FileNodeMap::value_type(fileName, node));
const auto [iter, success] = this->fileMap.emplace(node->fileName, node);

if (success) {
iter->second->Reference();
Expand All @@ -102,13 +101,10 @@ std::pair<NTSTATUS, FileNode&> MemFs::InsertNode(FileNode&& node) {
}

void MemFs::RemoveNode(FileNode& node, const bool reportDeletedSize) {
const auto iter = this->fileMap.find(node.fileName);
if (iter == this->fileMap.end()) {
if (!this->fileMap.erase(node.fileName)) {
return;
}

this->fileMap.erase(iter);

// memefs: Quickly report counter about deleted sectors
if (reportDeletedSize) {
// TODO: toBeDeleted stuff
Expand Down Expand Up @@ -152,12 +148,13 @@ std::vector<FileNode*> MemFs::EnumerateDescendants(const FileNode& node, const b
return descendants;
}

std::vector<FileNode*> MemFs::EnumerateDirChildren(const FileNode& node, const std::refoptional<const std::wstring_view> marker) {
std::vector<FileNode*> MemFs::EnumerateDirChildren(const FileNode& node, const wchar_t* marker) {
std::vector<FileNode*> children;
FileNodeMap::iterator iter;

if (marker.has_value()) {
iter = this->fileMap.upper_bound(node.fileName + L"\\" + std::wstring(marker.value()));
if (marker) {
const bool needsSlash = node.fileName.length() != 1 || node.fileName[0] != L'\\';
iter = this->fileMap.upper_bound(node.fileName + (needsSlash ? L"\\" : L"") + marker);
} else
iter = this->fileMap.upper_bound(node.fileName);

Expand Down
4 changes: 1 addition & 3 deletions WinFsp-MemFs-Extended/memfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ namespace Memfs {

std::vector<FileNode*> EnumerateNamedStreams(const FileNode& node, const bool references);
std::vector<FileNode*> EnumerateDescendants(const FileNode& node, const bool references);
std::vector<FileNode*> EnumerateDirChildren(const FileNode& node, const std::refoptional<const std::wstring_view> marker);

FileNodeMap& GetRawFileMap();
std::vector<FileNode*> EnumerateDirChildren(const FileNode& node, const wchar_t* marker);

private:
std::unique_ptr<FSP_FILE_SYSTEM> fileSystem;
Expand Down
2 changes: 1 addition & 1 deletion WinFsp-MemFs-Extended/nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ FileNodeEaMap& FileNode::GetEaMap() {
}

if (!this->eaMap.has_value()) {
this->eaMap = std::make_optional(FileNodeEaMap());
this->eaMap = FileNodeEaMap();
}

return this->eaMap.value();
Expand Down

0 comments on commit a2c7dde

Please sign in to comment.