diff --git a/dokan/dokan.c b/dokan/dokan.c index f15f1dc5c..ebe95ceb1 100644 --- a/dokan/dokan.c +++ b/dokan/dokan.c @@ -84,6 +84,9 @@ volatile PDokanMalloc g_DokanMalloc = NULL; volatile PDokanFree g_DokanFree = NULL; volatile PDokanRealloc g_DokanRealloc = NULL; +volatile PDokanDbgPrint g_PDokanDbgPrint = NULL; +volatile PDokanDbgPrintW g_PDokanDbgPrintW = NULL; + volatile LONG g_DokanInitialized = 0; // TODO NEXT: @@ -2016,8 +2019,7 @@ DOKAN_API PTP_POOL DOKAN_CALLBACK DokanGetThreadPool() { return threadPool; } -void DOKANAPI DokanInit(DOKAN_MEMORY_CALLBACKS *memoryCallbacks) { - +void DOKANAPI DokanInit(DOKAN_MEMORY_CALLBACKS* memoryCallbacks, DOKAN_LOG_CALLBACKS* logCallbacks) { // ensure 64-bit alignment assert(offsetof(EVENT_INFORMATION, Buffer) % 8 == 0); @@ -2047,6 +2049,18 @@ void DOKANAPI DokanInit(DOKAN_MEMORY_CALLBACKS *memoryCallbacks) { InterlockedExchange((volatile LONG*)&g_DokanRealloc, (LONG)memoryCallbacks->Realloc); #else #error Unsupported architecture! +#endif + } + + if (logCallbacks) { +#if INTPTR_MAX == INT64_MAX + InterlockedExchange64((volatile LONG64*)&g_PDokanDbgPrint, (LONG64)logCallbacks->DbgPrint); + InterlockedExchange64((volatile LONG64*)&g_PDokanDbgPrintW, (LONG64)logCallbacks->DbgPrintW); +#elif INTPTR_MAX == INT32_MAX + InterlockedExchange((volatile LONG*)&g_PDokanDbgPrint, (LONG)logCallbacks->DbgPrint); + InterlockedExchange((volatile LONG*)&g_PDokanDbgPrintW, (LONG)logCallbacks->DbgPrintW); +#else +#error Unsupported architecture! #endif } diff --git a/dokan/dokan.h b/dokan/dokan.h index 8df50ee1c..7697f1eba 100644 --- a/dokan/dokan.h +++ b/dokan/dokan.h @@ -227,12 +227,21 @@ typedef void* (WINAPI *PDokanMalloc)(size_t size, const char *fileName, int line typedef void (WINAPI *PDokanFree)(void *userData); typedef void* (WINAPI *PDokanRealloc)(void *userData, size_t newSize, const char *fileName, int lineNumber); +typedef void (WINAPI *PDokanDbgPrint)(LPCSTR logString); +typedef void (WINAPI *PDokanDbgPrintW)(LPCWSTR logString); + typedef struct _DOKAN_MEMORY_CALLBACKS { PDokanMalloc Malloc; PDokanFree Free; PDokanRealloc Realloc; } DOKAN_MEMORY_CALLBACKS, *PDOKAN_MEMORY_CALLBACKS; +typedef struct _DOKAN_LOG_CALLBACKS +{ + PDokanDbgPrint DbgPrint; + PDokanDbgPrintW DbgPrintW; +} DOKAN_LOG_CALLBACKS, *PDOKAN_LOG_CALLBACKS; + #define DOKAN_EXCEPTION_NOT_INITIALIZED 0x0f0ff0ff #define DOKAN_EXCEPTION_INITIALIZATION_FAILED 0x0fbadbad #define DOKAN_EXCEPTION_SHUTDOWN_FAILED 0x0fbadf00 @@ -1102,7 +1111,7 @@ void DOKANAPI DokanEndDispatchSetFileSecurity(DOKAN_SET_FILE_SECURITY_EVENT *Eve DOKAN_API PTP_POOL DOKAN_CALLBACK DokanGetThreadPool(); // Init/shutdown -void DOKANAPI DokanInit(DOKAN_MEMORY_CALLBACKS *memoryCallbacks); +void DOKANAPI DokanInit(DOKAN_MEMORY_CALLBACKS* memoryCallbacks, DOKAN_LOG_CALLBACKS* logCallbacks); void DOKANAPI DokanShutdown(); /** @} */ diff --git a/dokan/dokanc.h b/dokan/dokanc.h index 6be4e7a09..cab264c49 100644 --- a/dokan/dokanc.h +++ b/dokan/dokanc.h @@ -52,6 +52,9 @@ extern BOOL g_DebugMode; // DokanOptions->UseStdErr is ON? extern BOOL g_UseStdErr; +extern volatile PDokanDbgPrint g_PDokanDbgPrint; +extern volatile PDokanDbgPrintW g_PDokanDbgPrintW; + #ifdef _MSC_VER static VOID DokanDbgPrint(LPCSTR format, ...) { @@ -71,14 +74,16 @@ static VOID DokanDbgPrint(LPCSTR format, ...) { outputString = buffer; } - OutputDebugStringA(outputString); - - if(g_UseStdErr) { - - fputs(outputString, stderr); - fflush(stderr); + if (g_PDokanDbgPrint) { + g_PDokanDbgPrint(outputString); + } else { + OutputDebugStringA(outputString); + if (g_UseStdErr) { + fputs(outputString, stderr); + fflush(stderr); + } } - + if(buffer) { _freea(buffer); } @@ -103,16 +108,17 @@ static VOID DokanDbgPrintW(LPCWSTR format, ...) { outputString = buffer; } - OutputDebugStringW(outputString); - - if(g_UseStdErr) { - - fputws(outputString, stderr); - fflush(stderr); + if (g_PDokanDbgPrint) { + g_PDokanDbgPrintW(outputString); + } else { + OutputDebugStringW(outputString); + if (g_UseStdErr) { + fputws(outputString, stderr); + fflush(stderr); + } } if(buffer) { - _freea(buffer); } diff --git a/dokan_control/dokanctl.c b/dokan_control/dokanctl.c index 7b9244dc4..544d5d3f3 100644 --- a/dokan_control/dokanctl.c +++ b/dokan_control/dokanctl.c @@ -114,7 +114,7 @@ int __cdecl wmain(int argc, PWCHAR argv[]) { PVOID wow64OldValue; BOOL isAdmin; - DokanInit(NULL); + DokanInit(NULL, NULL); isAdmin = IsUserAnAdmin(); DokanUseStdErr(TRUE); // Set dokan library debug output diff --git a/dokan_fuse/src/dokanfuse.cpp b/dokan_fuse/src/dokanfuse.cpp index 39fe97d05..21b15aaa3 100644 --- a/dokan_fuse/src/dokanfuse.cpp +++ b/dokan_fuse/src/dokanfuse.cpp @@ -634,7 +634,7 @@ bool fuse_chan::init() { // check version typedef ULONG(__stdcall * DokanVersionType)(); - typedef void(__stdcall *DokanInitType)(DOKAN_MEMORY_CALLBACKS *memoryCallbacks); + typedef void(__stdcall *DokanInitType)(DOKAN_MEMORY_CALLBACKS *memoryCallbacks, DOKAN_LOG_CALLBACKS *logCallbacks); DokanVersionType ResolvedDokanVersion; DokanInitType ResolvedInit; @@ -647,7 +647,7 @@ bool fuse_chan::init() { return false; } - ResolvedInit(NULL); + ResolvedInit(NULL, NULL); ResolvedDokanVersion = (DokanVersionType)GetProcAddress(dokanDll, "DokanVersion"); diff --git a/samples/dokan_mirror/mirror.c b/samples/dokan_mirror/mirror.c index ea583a27b..9c2b846a6 100644 --- a/samples/dokan_mirror/mirror.c +++ b/samples/dokan_mirror/mirror.c @@ -2820,11 +2820,11 @@ int __cdecl wmain(ULONG argc, PWCHAR argv[]) { memoryCallbacks.Free = MirrorFree; memoryCallbacks.Realloc = MirrorRealloc; - DokanInit(&memoryCallbacks); + DokanInit(&memoryCallbacks, NULL); #else - DokanInit(NULL); + DokanInit(NULL, NULL); #endif