dokanc.h
1 /*
2  Dokan : user-mode file system library for Windows
3 
4  Copyright (C) 2020 - 2023 Google, Inc.
5  Copyright (C) 2015 - 2019 Adrien J. <liryna.stark@gmail.com> and Maxime C. <maxime@islog.com>
6  Copyright (C) 2007 - 2011 Hiroki Asakawa <info@dokan-dev.net>
7 
8  http://dokan-dev.github.io
9 
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free
12 Software Foundation; either version 3 of the License, or (at your option) any
13 later version.
14 
15 This program is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public License along
20 with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #ifndef DOKANC_H_
24 #define DOKANC_H_
25 
26 #include "dokan.h"
27 #include <malloc.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #define DOKAN_GLOBAL_DEVICE_NAME L"\\\\.\\Dokan_" DOKAN_MAJOR_API_VERSION
34 
35 #define DOKAN_DRIVER_SERVICE L"Dokan" DOKAN_MAJOR_API_VERSION
36 
37 #define DOKAN_SERVICE_START 1
38 #define DOKAN_SERVICE_STOP 2
39 #define DOKAN_SERVICE_DELETE 3
40 
41 // DokanOptions->DebugMode is ON?
42 extern BOOL g_DebugMode;
43 
44 // DokanOptions->UseStdErr is ON?
45 extern BOOL g_UseStdErr;
46 
47 #if defined(_MSC_VER) || (defined(__GNUC__) && !defined(__CYGWIN__))
48 
49 static VOID DokanDbgPrint(LPCSTR format, ...) {
50  const char *outputString = format; // fallback
51  char *buffer = NULL;
52  int length;
53  va_list argp;
54 
55  va_start(argp, format);
56  length = _vscprintf(format, argp) + 1;
57  if ((length - 1) != -1) {
58  buffer = (char *)_malloca(length * sizeof(char));
59  }
60  if (buffer && vsprintf_s(buffer, length, format, argp) != -1) {
61  outputString = buffer;
62  }
63  if (g_UseStdErr)
64  fputs(outputString, stderr);
65  else
66  OutputDebugStringA(outputString);
67  if (buffer)
68  _freea(buffer);
69  va_end(argp);
70  if (g_UseStdErr)
71  fflush(stderr);
72 }
73 
74 static VOID DokanDbgPrintW(LPCWSTR format, ...) {
75  const WCHAR *outputString = format; // fallback
76  WCHAR *buffer = NULL;
77  int length;
78  va_list argp;
79 
80  va_start(argp, format);
81  length = _vscwprintf(format, argp) + 1;
82  if ((length - 1) != -1) {
83  buffer = (WCHAR *)_malloca(length * sizeof(WCHAR));
84  }
85  if (buffer && vswprintf_s(buffer, length, format, argp) != -1) {
86  outputString = buffer;
87  }
88  if (g_UseStdErr)
89  fputws(outputString, stderr);
90  else
91  OutputDebugStringW(outputString);
92  if (buffer)
93  _freea(buffer);
94  va_end(argp);
95 }
96 
97 #if defined(_MSC_VER)
98 
99 #define DbgPrint(format, ...) \
100  do { \
101  if (g_DebugMode) { \
102  DokanDbgPrint(format, __VA_ARGS__); \
103  } \
104  } \
105  __pragma(warning(push)) __pragma(warning(disable : 4127)) while (0) \
106  __pragma(warning(pop))
107 
108 #define DbgPrintW(format, ...) \
109  do { \
110  if (g_DebugMode) { \
111  DokanDbgPrintW(format, __VA_ARGS__); \
112  } \
113  } \
114  __pragma(warning(push)) __pragma(warning(disable : 4127)) while (0) \
115  __pragma(warning(pop))
116 
117 #endif // defined(_MSC_VER)
118 
119 #if defined(__GNUC__)
120 
121 #define DbgPrint(format, ...) \
122  do { \
123  if (g_DebugMode) { \
124  DokanDbgPrint(format, ##__VA_ARGS__); \
125  } \
126  } while (0)
127 
128 #define DbgPrintW(format, ...) \
129  do { \
130  if (g_DebugMode) { \
131  DokanDbgPrintW(format, ##__VA_ARGS__); \
132  } \
133  } while (0)
134 
135 #endif // defined(__GNUC__)
136 
137 #endif // defined(_MSC_VER) || (defined(__GNUC__) && !defined(__CYGWIN__))
138 
139 #define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
140 
146 VOID DOKANAPI DokanUseStdErr(BOOL Status);
147 
151 VOID DOKANAPI DokanDebugMode(BOOL Status);
152 
158 BOOL DOKANAPI DokanServiceInstall(LPCWSTR ServiceName, DWORD ServiceType,
159  LPCWSTR ServiceFullPath);
160 
166 BOOL DOKANAPI DokanServiceDelete(LPCWSTR ServiceName);
167 
173 BOOL DOKANAPI DokanNetworkProviderInstall();
174 
180 BOOL DOKANAPI DokanNetworkProviderUninstall();
181 
188 BOOL DOKANAPI DokanSetDebugMode(ULONG Mode);
189 
197 BOOL DOKANAPI DokanMountPointsCleanUp();
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 #endif // DOKANC_H_
#define DOKANAPI
Definition: dokan.h:40