From aef92bcf23c0dea150e7864a4ef81984325fd6a5 Mon Sep 17 00:00:00 2001 From: Liryna Date: Sun, 18 Feb 2024 08:08:07 -0500 Subject: [PATCH] Kernel/Library - Fix ALLOW_IPC_BATCHING flag unset in kernel --- dokan/dokan.c | 10 ++++++++-- samples/dokan_mirror/mirror.c | 4 ++++ samples/mirror_test.ps1 | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/dokan/dokan.c b/dokan/dokan.c index f2363d48..65140911 100644 --- a/dokan/dokan.c +++ b/dokan/dokan.c @@ -809,7 +809,10 @@ int DOKANAPI DokanCreateFileSystem(_In_ PDOKAN_OPTIONS DokanOptions, DokanOptions->Options |= DOKAN_OPTION_ALLOW_IPC_BATCHING; mainPullThreadCount = DOKAN_MAIN_PULL_THREAD_COUNT_MAX; } - DbgPrintW(L"Dokan: Using %d main pull threads\n", mainPullThreadCount); + BOOLEAN allowIpcBatching = + (BOOLEAN)(DokanOptions->Options & DOKAN_OPTION_ALLOW_IPC_BATCHING); + DbgPrintW(L"Dokan: Using %d main pull threads with ipc batching: %d\n", + mainPullThreadCount, allowIpcBatching); for (DWORD x = 0; x < mainPullThreadCount; ++x) { PDOKAN_IO_EVENT ioEvent = PopIoEventBuffer(); if (!ioEvent) { @@ -818,7 +821,7 @@ int DOKANAPI DokanCreateFileSystem(_In_ PDOKAN_OPTIONS DokanOptions, return DOKAN_MOUNT_ERROR; } ioEvent->DokanInstance = dokanInstance; - QueueIoEvent(ioEvent, DokanOptions->Options & DOKAN_OPTION_ALLOW_IPC_BATCHING + QueueIoEvent(ioEvent, allowIpcBatching ? DispatchBatchIoCallback : DispatchDedicatedIoCallback); } @@ -1109,6 +1112,9 @@ int DokanStart(_In_ PDOKAN_INSTANCE DokanInstance) { if (DokanInstance->DokanOptions->Options & DOKAN_OPTION_DISPATCH_DRIVER_LOGS) { eventStart.Flags |= DOKAN_EVENT_DISPATCH_DRIVER_LOGS; } + if (DokanInstance->DokanOptions->Options & DOKAN_OPTION_ALLOW_IPC_BATCHING) { + eventStart.Flags |= DOKAN_EVENT_ALLOW_IPC_BATCHING; + } if (driverLetter && mountManager && !CheckDriveLetterAvailability(DokanInstance->MountPoint[0])) { eventStart.Flags |= DOKAN_EVENT_DRIVE_LETTER_IN_USE; diff --git a/samples/dokan_mirror/mirror.c b/samples/dokan_mirror/mirror.c index 5e196801..5090b082 100644 --- a/samples/dokan_mirror/mirror.c +++ b/samples/dokan_mirror/mirror.c @@ -1508,6 +1508,7 @@ void ShowUsage() { " /r RootDirectory (ex. /r c:\\test)\t\t Directory source to mirror.\n" " /l MountPoint (ex. /l m)\t\t\t Mount point. Can be M:\\ (drive letter) or empty NTFS folder C:\\mount\\dokan .\n" " /t Single thread\t\t\t\t Only use a single thread to process events.\n\t\t\t\t\t\t This is highly not recommended as can easily create a bottleneck.\n" + " /g IPC Batching\t\t\t\t Pull batches of events from the driver instead of a single one and execute them parallelly.\n\t\t\t\t\t\t Only recommended for slow (remote) mirrored device.\n" " /d (enable debug output)\t\t\t Enable debug output to an attached debugger.\n" " /s (use stderr for output)\t\t\t Enable debug output to stderr.\n" " /m (use removable drive)\t\t\t Show device as removable media.\n" @@ -1607,6 +1608,9 @@ int __cdecl wmain(ULONG argc, PWCHAR argv[]) { case L'e': dokanOptions.Options |= DOKAN_OPTION_DISPATCH_DRIVER_LOGS; break; + case L'g': + dokanOptions.Options |= DOKAN_OPTION_ALLOW_IPC_BATCHING; + break; case L'b': // Only work when mirroring a folder with setCaseSensitiveInfo option enabled on win10 dokanOptions.Options |= DOKAN_OPTION_CASE_SENSITIVE; diff --git a/samples/mirror_test.ps1 b/samples/mirror_test.ps1 index ea13b09a..963fdced 100644 --- a/samples/mirror_test.ps1 +++ b/samples/mirror_test.ps1 @@ -39,6 +39,11 @@ $Configs = @( "Destination" = "$($DokanDriverLetter):"; "Name" = "driveRemovable"; }, + @{ + "MirrorArguments" = "/l $DokanDriverLetter /g"; + "Destination" = "$($DokanDriverLetter):"; + "Name" = "ipcBatching"; + }, @{ "MirrorArguments" = "/l $DokanDriverLetter /o"; "Destination" = "$($DokanDriverLetter):";