dokan.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. Dokan : user-mode file system library for Windows
  3. Copyright (C) 2008 Hiroki Asakawa info@dokan-dev.net
  4. http://dokan-dev.net/en
  5. This program is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU Lesser General Public License as published by the Free
  7. Software Foundation; either version 3 of the License, or (at your option) any
  8. later version.
  9. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef _DOKAN_H_
  16. #define _DOKAN_H_
  17. #define DOKAN_DRIVER_NAME L"dokan.sys"
  18. #ifndef _M_X64
  19. #ifdef _EXPORTING
  20. #define DOKANAPI __declspec(dllimport) __stdcall
  21. #else
  22. #define DOKANAPI __declspec(dllexport) __stdcall
  23. #endif
  24. #else
  25. #define DOKANAPI
  26. #endif
  27. #define DOKAN_CALLBACK __stdcall
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. // The current Dokan version (ver 0.6.0). Please set this constant on DokanOptions->Version.
  32. #define DOKAN_VERSION 600
  33. #define DOKAN_OPTION_DEBUG 1 // ouput debug message
  34. #define DOKAN_OPTION_STDERR 2 // ouput debug message to stderr
  35. #define DOKAN_OPTION_ALT_STREAM 4 // use alternate stream
  36. #define DOKAN_OPTION_KEEP_ALIVE 8 // use auto unmount
  37. #define DOKAN_OPTION_NETWORK 16 // use network drive, you need to install Dokan network provider.
  38. #define DOKAN_OPTION_REMOVABLE 32 // use removable drive
  39. typedef struct _DOKAN_OPTIONS {
  40. USHORT Version; // Supported Dokan Version, ex. "530" (Dokan ver 0.5.3)
  41. USHORT ThreadCount; // number of threads to be used
  42. ULONG Options; // combination of DOKAN_OPTIONS_*
  43. ULONG64 GlobalContext; // FileSystem can use this variable
  44. LPCWSTR MountPoint; // mount point "M:\" (drive letter) or "C:\mount\dokan" (path in NTFS)
  45. } DOKAN_OPTIONS, *PDOKAN_OPTIONS;
  46. typedef struct _DOKAN_FILE_INFO {
  47. ULONG64 Context; // FileSystem can use this variable
  48. ULONG64 DokanContext; // Don't touch this
  49. PDOKAN_OPTIONS DokanOptions; // A pointer to DOKAN_OPTIONS which was passed to DokanMain.
  50. ULONG ProcessId; // process id for the thread that originally requested a given I/O operation
  51. UCHAR IsDirectory; // requesting a directory file
  52. UCHAR DeleteOnClose; // Delete on when "cleanup" is called
  53. UCHAR PagingIo; // Read or write is paging IO.
  54. UCHAR SynchronousIo; // Read or write is synchronous IO.
  55. UCHAR Nocache;
  56. UCHAR WriteToEndOfFile; // If true, write to the current end of file instead of Offset parameter.
  57. } DOKAN_FILE_INFO, *PDOKAN_FILE_INFO;
  58. // FillFileData
  59. // add an entry in FindFiles
  60. // return 1 if buffer is full, otherwise 0
  61. // (currently never return 1)
  62. typedef int (WINAPI *PFillFindData) (PWIN32_FIND_DATAW, PDOKAN_FILE_INFO);
  63. typedef struct _DOKAN_OPERATIONS {
  64. // When an error occurs, return negative value.
  65. // Usually you should return GetLastError() * -1.
  66. // CreateFile
  67. // If file is a directory, CreateFile (not OpenDirectory) may be called.
  68. // In this case, CreateFile should return 0 when that directory can be opened.
  69. // You should set TRUE on DokanFileInfo->IsDirectory when file is a directory.
  70. // When CreationDisposition is CREATE_ALWAYS or OPEN_ALWAYS and a file already exists,
  71. // you should return ERROR_ALREADY_EXISTS(183) (not negative value)
  72. int (DOKAN_CALLBACK *CreateFile) (
  73. LPCWSTR, // FileName
  74. DWORD, // DesiredAccess
  75. DWORD, // ShareMode
  76. DWORD, // CreationDisposition
  77. DWORD, // FlagsAndAttributes
  78. PDOKAN_FILE_INFO);
  79. int (DOKAN_CALLBACK *OpenDirectory) (
  80. LPCWSTR, // FileName
  81. PDOKAN_FILE_INFO);
  82. int (DOKAN_CALLBACK *CreateDirectory) (
  83. LPCWSTR, // FileName
  84. PDOKAN_FILE_INFO);
  85. // When FileInfo->DeleteOnClose is true, you must delete the file in Cleanup.
  86. int (DOKAN_CALLBACK *Cleanup) (
  87. LPCWSTR, // FileName
  88. PDOKAN_FILE_INFO);
  89. int (DOKAN_CALLBACK *CloseFile) (
  90. LPCWSTR, // FileName
  91. PDOKAN_FILE_INFO);
  92. int (DOKAN_CALLBACK *ReadFile) (
  93. LPCWSTR, // FileName
  94. LPVOID, // Buffer
  95. DWORD, // NumberOfBytesToRead
  96. LPDWORD, // NumberOfBytesRead
  97. LONGLONG, // Offset
  98. PDOKAN_FILE_INFO);
  99. int (DOKAN_CALLBACK *WriteFile) (
  100. LPCWSTR, // FileName
  101. LPCVOID, // Buffer
  102. DWORD, // NumberOfBytesToWrite
  103. LPDWORD, // NumberOfBytesWritten
  104. LONGLONG, // Offset
  105. PDOKAN_FILE_INFO);
  106. int (DOKAN_CALLBACK *FlushFileBuffers) (
  107. LPCWSTR, // FileName
  108. PDOKAN_FILE_INFO);
  109. int (DOKAN_CALLBACK *GetFileInformation) (
  110. LPCWSTR, // FileName
  111. LPBY_HANDLE_FILE_INFORMATION, // Buffer
  112. PDOKAN_FILE_INFO);
  113. int (DOKAN_CALLBACK *FindFiles) (
  114. LPCWSTR, // PathName
  115. PFillFindData, // call this function with PWIN32_FIND_DATAW
  116. PDOKAN_FILE_INFO); // (see PFillFindData definition)
  117. // You should implement either FindFiles or FindFilesWithPattern
  118. int (DOKAN_CALLBACK *FindFilesWithPattern) (
  119. LPCWSTR, // PathName
  120. LPCWSTR, // SearchPattern
  121. PFillFindData, // call this function with PWIN32_FIND_DATAW
  122. PDOKAN_FILE_INFO);
  123. int (DOKAN_CALLBACK *SetFileAttributes) (
  124. LPCWSTR, // FileName
  125. DWORD, // FileAttributes
  126. PDOKAN_FILE_INFO);
  127. int (DOKAN_CALLBACK *SetFileTime) (
  128. LPCWSTR, // FileName
  129. CONST FILETIME*, // CreationTime
  130. CONST FILETIME*, // LastAccessTime
  131. CONST FILETIME*, // LastWriteTime
  132. PDOKAN_FILE_INFO);
  133. // You should not delete file on DeleteFile or DeleteDirectory.
  134. // When DeleteFile or DeleteDirectory, you must check whether
  135. // you can delete the file or not, and return 0 (when you can delete it)
  136. // or appropriate error codes such as -ERROR_DIR_NOT_EMPTY,
  137. // -ERROR_SHARING_VIOLATION.
  138. // When you return 0 (ERROR_SUCCESS), you get Cleanup with
  139. // FileInfo->DeleteOnClose set TRUE and you have to delete the
  140. // file in Close.
  141. int (DOKAN_CALLBACK *DeleteFile) (
  142. LPCWSTR, // FileName
  143. PDOKAN_FILE_INFO);
  144. int (DOKAN_CALLBACK *DeleteDirectory) (
  145. LPCWSTR, // FileName
  146. PDOKAN_FILE_INFO);
  147. int (DOKAN_CALLBACK *MoveFile) (
  148. LPCWSTR, // ExistingFileName
  149. LPCWSTR, // NewFileName
  150. BOOL, // ReplaceExisiting
  151. PDOKAN_FILE_INFO);
  152. int (DOKAN_CALLBACK *SetEndOfFile) (
  153. LPCWSTR, // FileName
  154. LONGLONG, // Length
  155. PDOKAN_FILE_INFO);
  156. int (DOKAN_CALLBACK *SetAllocationSize) (
  157. LPCWSTR, // FileName
  158. LONGLONG, // Length
  159. PDOKAN_FILE_INFO);
  160. int (DOKAN_CALLBACK *LockFile) (
  161. LPCWSTR, // FileName
  162. LONGLONG, // ByteOffset
  163. LONGLONG, // Length
  164. PDOKAN_FILE_INFO);
  165. int (DOKAN_CALLBACK *UnlockFile) (
  166. LPCWSTR, // FileName
  167. LONGLONG,// ByteOffset
  168. LONGLONG,// Length
  169. PDOKAN_FILE_INFO);
  170. // Neither GetDiskFreeSpace nor GetVolumeInformation
  171. // save the DokanFileContext->Context.
  172. // Before these methods are called, CreateFile may not be called.
  173. // (ditto CloseFile and Cleanup)
  174. // see Win32 API GetDiskFreeSpaceEx
  175. int (DOKAN_CALLBACK *GetDiskFreeSpace) (
  176. PULONGLONG, // FreeBytesAvailable
  177. PULONGLONG, // TotalNumberOfBytes
  178. PULONGLONG, // TotalNumberOfFreeBytes
  179. PDOKAN_FILE_INFO);
  180. // see Win32 API GetVolumeInformation
  181. int (DOKAN_CALLBACK *GetVolumeInformation) (
  182. LPWSTR, // VolumeNameBuffer
  183. DWORD, // VolumeNameSize in num of chars
  184. LPDWORD,// VolumeSerialNumber
  185. LPDWORD,// MaximumComponentLength in num of chars
  186. LPDWORD,// FileSystemFlags
  187. LPWSTR, // FileSystemNameBuffer
  188. DWORD, // FileSystemNameSize in num of chars
  189. PDOKAN_FILE_INFO);
  190. int (DOKAN_CALLBACK *Unmount) (
  191. PDOKAN_FILE_INFO);
  192. // Suported since 0.6.0. You must specify the version at DOKAN_OPTIONS.Version.
  193. int (DOKAN_CALLBACK *GetFileSecurity) (
  194. LPCWSTR, // FileName
  195. PSECURITY_INFORMATION, // A pointer to SECURITY_INFORMATION value being requested
  196. PSECURITY_DESCRIPTOR, // A pointer to SECURITY_DESCRIPTOR buffer to be filled
  197. ULONG, // length of Security descriptor buffer
  198. PULONG, // LengthNeeded
  199. PDOKAN_FILE_INFO);
  200. int (DOKAN_CALLBACK *SetFileSecurity) (
  201. LPCWSTR, // FileName
  202. PSECURITY_INFORMATION,
  203. PSECURITY_DESCRIPTOR, // SecurityDescriptor
  204. ULONG, // SecurityDescriptor length
  205. PDOKAN_FILE_INFO);
  206. } DOKAN_OPERATIONS, *PDOKAN_OPERATIONS;
  207. /* DokanMain returns error codes */
  208. #define DOKAN_SUCCESS 0
  209. #define DOKAN_ERROR -1 /* General Error */
  210. #define DOKAN_DRIVE_LETTER_ERROR -2 /* Bad Drive letter */
  211. #define DOKAN_DRIVER_INSTALL_ERROR -3 /* Can't install driver */
  212. #define DOKAN_START_ERROR -4 /* Driver something wrong */
  213. #define DOKAN_MOUNT_ERROR -5 /* Can't assign a drive letter or mount point */
  214. #define DOKAN_MOUNT_POINT_ERROR -6 /* Mount point is invalid */
  215. int DOKANAPI
  216. DokanMain(
  217. PDOKAN_OPTIONS DokanOptions,
  218. PDOKAN_OPERATIONS DokanOperations);
  219. BOOL DOKANAPI
  220. DokanUnmount(
  221. WCHAR DriveLetter);
  222. BOOL DOKANAPI
  223. DokanRemoveMountPoint(
  224. LPCWSTR MountPoint);
  225. // DokanIsNameInExpression
  226. // check whether Name can match Expression
  227. // Expression can contain wildcard characters (? and *)
  228. BOOL DOKANAPI
  229. DokanIsNameInExpression(
  230. LPCWSTR Expression, // matching pattern
  231. LPCWSTR Name, // file name
  232. BOOL IgnoreCase);
  233. ULONG DOKANAPI
  234. DokanVersion();
  235. ULONG DOKANAPI
  236. DokanDriverVersion();
  237. // DokanResetTimeout
  238. // extends the time out of the current IO operation in driver.
  239. BOOL DOKANAPI
  240. DokanResetTimeout(
  241. ULONG Timeout, // timeout in millisecond
  242. PDOKAN_FILE_INFO DokanFileInfo);
  243. // Get the handle to Access Token
  244. // This method needs be called in CreateFile, OpenDirectory or CreateDirectly callback.
  245. // The caller must call CloseHandle for the returned handle.
  246. HANDLE DOKANAPI
  247. DokanOpenRequestorToken(
  248. PDOKAN_FILE_INFO DokanFileInfo);
  249. #ifdef __cplusplus
  250. }
  251. #endif
  252. #endif // _DOKAN_H_