1
0

Patch dokany for logging

This commit is contained in:
Scott E. Graves
2017-03-24 19:45:10 -05:00
parent 9320247b63
commit 62957e9423
5 changed files with 200 additions and 19 deletions

1
.gitignore vendored
View File

@@ -247,3 +247,4 @@ ModelManifest.xml
*.complete
/3rd_party/dokany-1.0.2
/dist
/3rd_party/dokany-1.0.3

175
3rd_party/enable_debug_logging.patch vendored Normal file
View File

@@ -0,0 +1,175 @@
From 038b4c72b6a6b1a1f992ffd57ec9207aecd162af Mon Sep 17 00:00:00 2001
From: "SiaExtensions" <sia.extensions@gmail.com>
Date: Fri, 24 Mar 2017 18:44:48 -0500
Subject: [PATCH] Enable debug logging
---
dokan/dokan.c | 11 +++++++++++
dokan/dokan.h | 2 ++
dokan/dokanc.h | 17 +++++++++++++++++
samples/dokan_mirror/mirror.c | 16 ++++++++++++++++
4 files changed, 46 insertions(+)
diff --git a/dokan/dokan.c b/dokan/dokan.c
index 376c8e0..2e92feb 100644
--- a/dokan/dokan.c
+++ b/dokan/dokan.c
@@ -37,6 +37,9 @@ BOOL g_DebugMode = TRUE;
// DokanOptions->UseStdErr is ON?
BOOL g_UseStdErr = FALSE;
+// DokanOptions->UseDebugLogFile is ON?
+BOOL g_UseDebugLogFile = FALSE;
+
CRITICAL_SECTION g_InstanceCriticalSection;
LIST_ENTRY g_InstanceList;
@@ -44,6 +47,8 @@ VOID DOKANAPI DokanUseStdErr(BOOL Status) { g_UseStdErr = Status; }
VOID DOKANAPI DokanDebugMode(BOOL Status) { g_DebugMode = Status; }
+VOID DOKANAPI DokanUseDebugLogFile(BOOL Status) { g_UseDebugLogFile = Status; }
+
PDOKAN_INSTANCE
NewDokanInstance() {
PDOKAN_INSTANCE instance = (PDOKAN_INSTANCE)malloc(sizeof(DOKAN_INSTANCE));
@@ -178,6 +183,7 @@ int DOKANAPI DokanMain(PDOKAN_OPTIONS DokanOptions,
g_DebugMode = DokanOptions->Options & DOKAN_OPTION_DEBUG;
g_UseStdErr = DokanOptions->Options & DOKAN_OPTION_STDERR;
+ g_UseDebugLogFile = DokanOptions->Options & DOKAN_OPTION_DEBUG_LOG_FILE;
if (g_DebugMode) {
DbgPrintW(L"Dokan: debug mode on\n");
@@ -188,6 +194,11 @@ int DOKANAPI DokanMain(PDOKAN_OPTIONS DokanOptions,
g_DebugMode = TRUE;
}
+ if (g_UseDebugLogFile) {
+ DbgPrintW(L"Dokan: use debug log file\n");
+ g_DebugMode = TRUE;
+ }
+
if (DokanOptions->Options & DOKAN_OPTION_NETWORK &&
!IsMountPointDriveLetter(DokanOptions->MountPoint)) {
DokanOptions->Options &= ~DOKAN_OPTION_NETWORK;
diff --git a/dokan/dokan.h b/dokan/dokan.h
index 7e9eaa8..4c58d51 100644
--- a/dokan/dokan.h
+++ b/dokan/dokan.h
@@ -92,6 +92,8 @@ extern "C" {
#define DOKAN_OPTION_CURRENT_SESSION 128
/** Enable Lockfile/Unlockfile operations. Otherwise Dokan will take care of it */
#define DOKAN_OPTION_FILELOCK_USER_MODE 256
+/** Enable debug logging to file*/
+#define DOKAN_OPTION_DEBUG_LOG_FILE 512
/** @} */
diff --git a/dokan/dokanc.h b/dokan/dokanc.h
index 7fd288f..a0865f7 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;
+// DokanOptions->UseDebugLogFile is ON?
+extern BOOL g_UseDebugLogFile;
+
#ifdef _MSC_VER
static VOID DokanDbgPrint(LPCSTR format, ...) {
@@ -73,6 +76,13 @@ static VOID DokanDbgPrint(LPCSTR format, ...) {
fputs(outputString, stderr);
else
OutputDebugStringA(outputString);
+ if (g_UseDebugLogFile) {
+ FILE* logFile;
+ if (fopen_s(&logFile, "DokanyDebugA.log", "a") == 0) {
+ fprintf_s(logFile, outputString);
+ fclose(logFile);
+ }
+ }
if (buffer)
_freea(buffer);
va_end(argp);
@@ -99,6 +109,13 @@ static VOID DokanDbgPrintW(LPCWSTR format, ...) {
fputws(outputString, stderr);
else
OutputDebugStringW(outputString);
+ if (g_UseDebugLogFile) {
+ FILE* logFile;
+ if (_wfopen_s(&logFile, L"DokanyDebugW.log", L"a") == 0) {
+ fwprintf_s(logFile, outputString);
+ fclose(logFile);
+ }
+ }
if (buffer)
_freea(buffer);
va_end(argp);
diff --git a/samples/dokan_mirror/mirror.c b/samples/dokan_mirror/mirror.c
index c077186..1defa23 100644
--- a/samples/dokan_mirror/mirror.c
+++ b/samples/dokan_mirror/mirror.c
@@ -43,6 +43,7 @@ THE SOFTWARE.
BOOL g_UseStdErr;
BOOL g_DebugMode;
BOOL g_HasSeSecurityPrivilege;
+BOOL g_UseDebugLogFile;
static void DbgPrint(LPCWSTR format, ...) {
if (g_DebugMode) {
@@ -64,6 +65,13 @@ static void DbgPrint(LPCWSTR format, ...) {
fputws(outputString, stderr);
else
OutputDebugStringW(outputString);
+ if (g_UseDebugLogFile) {
+ FILE* logFile;
+ if (_wfopen_s(&logFile, L"DokanyMirror.log", L"a") == 0) {
+ fwprintf_s(logFile, outputString);
+ fclose(logFile);
+ }
+ }
if (buffer)
_freea(buffer);
va_end(argp);
@@ -1331,6 +1339,7 @@ void ShowUsage() {
" /l MountPoint (ex. /l m)\t\t\t Mount point. Can be M:\\ (drive letter) or empty NTFS folder C:\\mount\\dokan .\n"
" /t ThreadCount (ex. /t 5)\t\t\t Number of threads to be used internally by Dokan library.\n\t\t\t\t\t\t More threads will handle more event at the same time.\n"
" /d (enable debug output)\t\t\t Enable debug output to an attached debugger.\n"
+ " /b (enable debug log)\t\t\t Enable debug output to log file.\n"
" /s (use stderr for output)\t\t\t Enable debug output to stderr.\n"
" /n (use network drive)\t\t\t Show device as network device.\n"
" /m (use removable drive)\t\t\t Show device as removable media.\n"
@@ -1373,6 +1382,7 @@ int __cdecl wmain(ULONG argc, PWCHAR argv[]) {
g_DebugMode = FALSE;
g_UseStdErr = FALSE;
+ g_UseDebugLogFile = FALSE;
ZeroMemory(dokanOptions, sizeof(DOKAN_OPTIONS));
dokanOptions->Version = DOKAN_VERSION;
@@ -1401,6 +1411,9 @@ int __cdecl wmain(ULONG argc, PWCHAR argv[]) {
case L's':
g_UseStdErr = TRUE;
break;
+ case L'b':
+ g_UseDebugLogFile = TRUE;
+ break;
case L'n':
dokanOptions->Options |= DOKAN_OPTION_NETWORK;
break;
@@ -1498,6 +1511,9 @@ int __cdecl wmain(ULONG argc, PWCHAR argv[]) {
if (g_UseStdErr) {
dokanOptions->Options |= DOKAN_OPTION_STDERR;
}
+ if (g_UseDebugLogFile) {
+ dokanOptions->Options |= DOKAN_OPTION_DEBUG_LOG_FILE;
+ }
dokanOptions->Options |= DOKAN_OPTION_ALT_STREAM;
--
2.10.1.windows.1

View File

@@ -24,6 +24,7 @@ set_target_properties(siadrive.api
)
if (MSVC)
set(DOKANY_VERSION dokany-1.0.3)
ExternalProject_Add(curl_project
URL https://github.com/curl/curl/archive/curl-7_53_1.tar.gz
PREFIX ${EXTERNAL_BUILD_ROOT}/builds/curl
@@ -62,10 +63,10 @@ if (MSVC)
PROPERTIES COMPILE_FLAGS -DSIADRIVE_DOKAN_EXPORT_SYMBOLS
)
target_include_directories(siadrive.dokan.api PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/dokany-1.0.2/dokan
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/dokany-1.0.2/sys
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/${DOKANY_VERSION}/dokan
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/${DOKANY_VERSION}/sys
${CMAKE_CURRENT_SOURCE_DIR}/include/siadrive_dokan_api)
target_link_libraries(siadrive.dokan.api siadrive.api ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/dokany-1.0.2/x64/${CMAKE_BUILD_TYPE}/dokan1.lib)
target_link_libraries(siadrive.dokan.api siadrive.api ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/${DOKANY_VERSION}/x64/${CMAKE_BUILD_TYPE}/dokan1.lib)
endif()
@@ -100,9 +101,9 @@ if (MSVC)
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/CEF/bin/${CMAKE_BUILD_TYPE}/libEGL.dll
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/CEF/bin/${CMAKE_BUILD_TYPE}/libGLESv2.dll
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/CEF/bin/${CMAKE_BUILD_TYPE}/d3dcompiler_47.dll
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/dokany-1.0.2/x64/${CMAKE_BUILD_TYPE}/dokan1.dll
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/dokany-1.0.2/x64/${CMAKE_BUILD_TYPE}/dokanfuse1.dll
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/dokany-1.0.2/x64/${CMAKE_BUILD_TYPE}/dokannp1.dll)
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/${DOKANY_VERSION}/x64/${CMAKE_BUILD_TYPE}/dokan1.dll
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/${DOKANY_VERSION}/x64/${CMAKE_BUILD_TYPE}/dokanfuse1.dll
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/${DOKANY_VERSION}/x64/${CMAKE_BUILD_TYPE}/dokannp1.dll)
file(GLOB CEF_SUPPORT
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/CEF/bin/${CMAKE_BUILD_TYPE}/icudtl.dat
@@ -119,9 +120,9 @@ if (MSVC)
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/CEF/bin/${CMAKE_BUILD_TYPE}/libEGL.dll.pdb
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/CEF/bin/${CMAKE_BUILD_TYPE}/libGLESv2.dll.pdb
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/CEF/bin/${CMAKE_BUILD_TYPE}/libcef_dll_wrapper_cc.pdb
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/dokany-1.0.2/x64/${CMAKE_BUILD_TYPE}/dokan1.pdb
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/dokany-1.0.2/x64/${CMAKE_BUILD_TYPE}/dokanfuse1.pdb
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/dokany-1.0.2/x64/${CMAKE_BUILD_TYPE}/dokannp1.pdb)
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/${DOKANY_VERSION}/x64/${CMAKE_BUILD_TYPE}/dokan1.pdb
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/${DOKANY_VERSION}/x64/${CMAKE_BUILD_TYPE}/dokanfuse1.pdb
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/${DOKANY_VERSION}/x64/${CMAKE_BUILD_TYPE}/dokannp1.pdb)
endif()
SET ( CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO )

BIN
bin/patch.exe Normal file

Binary file not shown.

View File

@@ -2,16 +2,20 @@
set ROOT=%~dp0%
set PATH=%ROOT%bin;%PATH%
pushd "%ROOT%"
set DOKANY_VERSION=1.0.3
if NOT EXIST "3rd_party\dokany-1.0.2" (
del /q v1.0.2.zip > NUL
wget --no-check-certificate "https://github.com/dokan-dev/dokany/archive/v1.0.2.zip" || goto :ERROR
unzip -o -q -d 3rd_party v1.0.2.zip || goto :ERROR
del /q v1.0.2.zip > NUL
del /q dokan.zip > NUL
wget --no-check-certificate "https://github.com/dokan-dev/dokany/releases/download/v1.0.2/dokan.zip" || goto :ERROR
unzip -o -q -d 3rd_party\dokany-1.0.2 dokan.zip || goto :ERROR
del /q dokan.zip > NUL
if NOT EXIST "3rd_party\dokany-%DOKANY_VERSION%.complete" (
del /q v%DOKANY_VERSION%.zip > NUL
wget --no-check-certificate "https://github.com/dokan-dev/dokany/archive/v%DOKANY_VERSION%.zip" || goto :ERROR
unzip -o -q -d 3rd_party v%DOKANY_VERSION%.zip || goto :ERROR
del /q v%DOKANY_VERSION%.zip > NUL
pushd "3rd_party\dokany-%DOKANY_VERSION%"
copy /y ..\enable_debug_logging.patch
patch -p1 -N < enable_debug_logging.patch || goto :ERROR
call build.bat
popd
echo "1">3rd_party\dokany-%DOKANY_VERSION%.complete
)
if NOT EXIST ".\bin\cmake-3.7.2-win64-x64\bin\cmake.exe" (