From 7aed97850fc5bb385f4898686f172c95d71bc7f1 Mon Sep 17 00:00:00 2001 From: Jonathan Giroux Date: Wed, 1 Jun 2022 16:26:29 +0200 Subject: [PATCH] Library - Allow FindFilesWithPattern to return STATUS_NOT_IMPLEMENTED Reverts 9eb4d15bc4c533b73dd718b3114c0be758f874d9 --- dokan/directory.c | 23 +++++++++++++++-------- dokan/dokan.h | 6 +++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/dokan/directory.c b/dokan/directory.c index 784b7b4e..ae0d979c 100644 --- a/dokan/directory.c +++ b/dokan/directory.c @@ -692,21 +692,28 @@ VOID DispatchDirectoryInformation(PDOKAN_IO_EVENT IoEvent) { return; } - if ((!searchPattern || - !IoEvent->DokanInstance->DokanOperations->FindFilesWithPattern) && - IoEvent->DokanInstance->DokanOperations->FindFiles) { - status = IoEvent->DokanInstance->DokanOperations->FindFiles( - IoEvent->EventContext->Operation.Directory.DirectoryName, - DokanFillFileData, &IoEvent->DokanFileInfo); - EndFindFilesCommon(IoEvent, status); + status = STATUS_NOT_IMPLEMENTED; - } else if (IoEvent->DokanInstance->DokanOperations->FindFilesWithPattern) { + // Reminder: FindFilesWithPattern may not be implemented by returning STATUS_NOT_IMPLEMENTED. + if (IoEvent->DokanInstance->DokanOperations->FindFilesWithPattern) { status = IoEvent->DokanInstance->DokanOperations->FindFilesWithPattern( IoEvent->EventContext->Operation.Directory.DirectoryName, searchPattern ? searchPattern : L"*", DokanFillFileData, &IoEvent->DokanFileInfo); + } + + // And if not, try with FindFiles. + if (status == STATUS_NOT_IMPLEMENTED && + IoEvent->DokanInstance->DokanOperations->FindFiles) { + status = IoEvent->DokanInstance->DokanOperations->FindFiles( + IoEvent->EventContext->Operation.Directory.DirectoryName, + DokanFillFileData, &IoEvent->DokanFileInfo); + } + + if (status != STATUS_NOT_IMPLEMENTED) { EndFindFilesCommon(IoEvent, status); } else { + // Neither FindFilesWithPattern nor FindFiles are implemented. IoEvent->EventResult->Status = STATUS_NOT_IMPLEMENTED; EventCompletion(IoEvent); } diff --git a/dokan/dokan.h b/dokan/dokan.h index 1696d792..571c0981 100644 --- a/dokan/dokan.h +++ b/dokan/dokan.h @@ -400,8 +400,8 @@ typedef struct _DOKAN_OPERATIONS { * \brief FindFiles Dokan API callback * * List all files in the requested path. - * If this function is not implemented by not assigning the function pointer, - * \ref DOKAN_OPERATIONS.FindFilesWithPattern will instead be called with a wildcard as pattern. + * \ref DOKAN_OPERATIONS.FindFilesWithPattern is checked first. If it is not implemented or + * returns \c STATUS_NOT_IMPLEMENTED, then FindFiles is called, if assigned. * It is recommended to have this implemented for performance reason. * * \param FileName File path requested by the Kernel on the FileSystem. @@ -421,7 +421,7 @@ typedef struct _DOKAN_OPERATIONS { * The search pattern is a Windows MS-DOS-style expression. * It can contain wild cards and extended characters or none of them. See \ref DokanIsNameInExpression. * - * If the function is not implemented by not assigning the function pointer, \ref DOKAN_OPERATIONS.FindFiles + * If the function is not implemented, \ref DOKAN_OPERATIONS.FindFiles * will be called instead and the result will be filtered internally by the library. * It is recommended to have this implemented for performance reason. *