github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/dokan/dokan_header/public.h (about) 1 /* 2 Dokan : user-mode file system library for Windows 3 4 Copyright (C) 2015 - 2016 Adrien J. <liryna.stark@gmail.com> and Maxime C. <maxime@islog.com> 5 Copyright (C) 2007 - 2011 Hiroki Asakawa <info@dokan-dev.net> 6 7 http://dokan-dev.github.io 8 9 This program is free software; you can redistribute it and/or modify it under 10 the terms of the GNU Lesser General Public License as published by the Free 11 Software Foundation; either version 3 of the License, or (at your option) any 12 later version. 13 14 This program is distributed in the hope that it will be useful, but WITHOUT ANY 15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public License along 19 with this program. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef PUBLIC_H_ 23 #define PUBLIC_H_ 24 25 #ifndef DOKAN_MAJOR_API_VERSION 26 #define DOKAN_MAJOR_API_VERSION L"1" 27 #endif 28 29 #define DOKAN_DRIVER_VERSION 0x0000190 30 31 #define EVENT_CONTEXT_MAX_SIZE (1024 * 32) 32 33 #define IOCTL_TEST \ 34 CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) 35 36 #define IOCTL_SET_DEBUG_MODE \ 37 CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, METHOD_BUFFERED, FILE_ANY_ACCESS) 38 39 #define IOCTL_EVENT_WAIT \ 40 CTL_CODE(FILE_DEVICE_UNKNOWN, 0x802, METHOD_BUFFERED, FILE_ANY_ACCESS) 41 42 #define IOCTL_EVENT_INFO \ 43 CTL_CODE(FILE_DEVICE_UNKNOWN, 0x803, METHOD_BUFFERED, FILE_ANY_ACCESS) 44 45 #define IOCTL_EVENT_RELEASE \ 46 CTL_CODE(FILE_DEVICE_UNKNOWN, 0x804, METHOD_BUFFERED, FILE_ANY_ACCESS) 47 48 #define IOCTL_EVENT_START \ 49 CTL_CODE(FILE_DEVICE_UNKNOWN, 0x805, METHOD_BUFFERED, FILE_ANY_ACCESS) 50 51 #define IOCTL_EVENT_WRITE \ 52 CTL_CODE(FILE_DEVICE_UNKNOWN, 0x806, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 53 54 #define IOCTL_KEEPALIVE \ 55 CTL_CODE(FILE_DEVICE_UNKNOWN, 0x809, METHOD_NEITHER, FILE_ANY_ACCESS) 56 57 #define IOCTL_SERVICE_WAIT \ 58 CTL_CODE(FILE_DEVICE_UNKNOWN, 0x80A, METHOD_BUFFERED, FILE_ANY_ACCESS) 59 60 #define IOCTL_RESET_TIMEOUT \ 61 CTL_CODE(FILE_DEVICE_UNKNOWN, 0x80B, METHOD_BUFFERED, FILE_ANY_ACCESS) 62 63 #define IOCTL_GET_ACCESS_TOKEN \ 64 CTL_CODE(FILE_DEVICE_UNKNOWN, 0x80C, METHOD_BUFFERED, FILE_ANY_ACCESS) 65 66 #define IOCTL_EVENT_MOUNTPOINT_LIST \ 67 CTL_CODE(FILE_DEVICE_UNKNOWN, 0x80D, METHOD_BUFFERED, FILE_ANY_ACCESS) 68 69 #define DRIVER_FUNC_INSTALL 0x01 70 #define DRIVER_FUNC_REMOVE 0x02 71 72 #define DOKAN_MOUNTED 1 73 #define DOKAN_USED 2 74 #define DOKAN_START_FAILED 3 75 76 #define DOKAN_DEVICE_MAX 10 77 78 #define DOKAN_DEFAULT_SECTOR_SIZE 512 79 #define DOKAN_DEFAULT_ALLOCATION_UNIT_SIZE 512 80 #define DOKAN_DEFAULT_DISK_SIZE 1024 * 1024 * 1024 81 82 // used in CCB->Flags and FCB->Flags 83 #define DOKAN_FILE_DIRECTORY 1 84 #define DOKAN_FILE_DELETED 2 85 #define DOKAN_FILE_OPENED 4 86 #define DOKAN_DIR_MATCH_ALL 8 87 #define DOKAN_DELETE_ON_CLOSE 16 88 #define DOKAN_PAGING_IO 32 89 #define DOKAN_SYNCHRONOUS_IO 64 90 #define DOKAN_WRITE_TO_END_OF_FILE 128 91 #define DOKAN_NOCACHE 256 92 93 // used in DOKAN_START->DeviceType 94 #define DOKAN_DISK_FILE_SYSTEM 0 95 #define DOKAN_NETWORK_FILE_SYSTEM 1 96 97 /* 98 * This structure is used for copying UNICODE_STRING from the kernel mode driver 99 * into the user mode driver. 100 * https://msdn.microsoft.com/en-us/library/windows/hardware/ff564879(v=vs.85).aspx 101 */ 102 typedef struct _DOKAN_UNICODE_STRING_INTERMEDIATE { 103 USHORT Length; 104 USHORT MaximumLength; 105 WCHAR Buffer[1]; 106 } DOKAN_UNICODE_STRING_INTERMEDIATE, *PDOKAN_UNICODE_STRING_INTERMEDIATE; 107 108 /* 109 * This structure is used for copying ACCESS_STATE from the kernel mode driver 110 * into the user mode driver. 111 * https://msdn.microsoft.com/en-us/library/windows/hardware/ff538840(v=vs.85).aspx 112 */ 113 typedef struct _DOKAN_ACCESS_STATE_INTERMEDIATE { 114 BOOLEAN SecurityEvaluated; 115 BOOLEAN GenerateAudit; 116 BOOLEAN GenerateOnClose; 117 BOOLEAN AuditPrivileges; 118 ULONG Flags; 119 ACCESS_MASK RemainingDesiredAccess; 120 ACCESS_MASK PreviouslyGrantedAccess; 121 ACCESS_MASK OriginalDesiredAccess; 122 123 // Offset from the beginning of this structure to a SECURITY_DESCRIPTOR 124 // if 0 that means there is no security descriptor 125 ULONG SecurityDescriptorOffset; 126 127 // Offset from the beginning of this structure to a 128 // DOKAN_UNICODE_STRING_INTERMEDIATE 129 ULONG UnicodeStringObjectNameOffset; 130 131 // Offset from the beginning of this structure to a 132 // DOKAN_UNICODE_STRING_INTERMEDIATE 133 ULONG UnicodeStringObjectTypeOffset; 134 } DOKAN_ACCESS_STATE_INTERMEDIATE, *PDOKAN_ACCESS_STATE_INTERMEDIATE; 135 136 typedef struct _DOKAN_ACCESS_STATE { 137 BOOLEAN SecurityEvaluated; 138 BOOLEAN GenerateAudit; 139 BOOLEAN GenerateOnClose; 140 BOOLEAN AuditPrivileges; 141 ULONG Flags; 142 ACCESS_MASK RemainingDesiredAccess; 143 ACCESS_MASK PreviouslyGrantedAccess; 144 ACCESS_MASK OriginalDesiredAccess; 145 PSECURITY_DESCRIPTOR SecurityDescriptor; 146 UNICODE_STRING ObjectName; 147 UNICODE_STRING ObjectType; 148 } DOKAN_ACCESS_STATE, *PDOKAN_ACCESS_STATE; 149 150 /* 151 * This structure is used for copying IO_SECURITY_CONTEXT from the kernel mode 152 * driver into the user mode driver. 153 * https://msdn.microsoft.com/en-us/library/windows/hardware/ff550613(v=vs.85).aspx 154 */ 155 typedef struct _DOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE { 156 DOKAN_ACCESS_STATE_INTERMEDIATE AccessState; 157 ACCESS_MASK DesiredAccess; 158 } DOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE, 159 *PDOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE; 160 161 typedef struct _DOKAN_IO_SECURITY_CONTEXT { 162 DOKAN_ACCESS_STATE AccessState; 163 ACCESS_MASK DesiredAccess; 164 } DOKAN_IO_SECURITY_CONTEXT, *PDOKAN_IO_SECURITY_CONTEXT; 165 166 typedef struct _CREATE_CONTEXT { 167 DOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE SecurityContext; 168 ULONG FileAttributes; 169 ULONG CreateOptions; 170 ULONG ShareAccess; 171 ULONG FileNameLength; 172 173 // Offset from the beginning of this structure to the string 174 ULONG FileNameOffset; 175 } CREATE_CONTEXT, *PCREATE_CONTEXT; 176 177 typedef struct _CLEANUP_CONTEXT { 178 ULONG FileNameLength; 179 WCHAR FileName[1]; 180 181 } CLEANUP_CONTEXT, *PCLEANUP_CONTEXT; 182 183 typedef struct _CLOSE_CONTEXT { 184 ULONG FileNameLength; 185 WCHAR FileName[1]; 186 187 } CLOSE_CONTEXT, *PCLOSE_CONTEXT; 188 189 typedef struct _DIRECTORY_CONTEXT { 190 ULONG FileInformationClass; 191 ULONG FileIndex; 192 ULONG BufferLength; 193 ULONG DirectoryNameLength; 194 ULONG SearchPatternLength; 195 ULONG SearchPatternOffset; 196 WCHAR DirectoryName[1]; 197 WCHAR SearchPatternBase[1]; 198 199 } DIRECTORY_CONTEXT, *PDIRECTORY_CONTEXT; 200 201 typedef struct _READ_CONTEXT { 202 LARGE_INTEGER ByteOffset; 203 ULONG BufferLength; 204 ULONG FileNameLength; 205 WCHAR FileName[1]; 206 } READ_CONTEXT, *PREAD_CONTEXT; 207 208 typedef struct _WRITE_CONTEXT { 209 LARGE_INTEGER ByteOffset; 210 ULONG BufferLength; 211 ULONG BufferOffset; 212 ULONG RequestLength; 213 ULONG FileNameLength; 214 WCHAR FileName[2]; 215 // "2" means to keep last null of contents to write 216 } WRITE_CONTEXT, *PWRITE_CONTEXT; 217 218 typedef struct _FILEINFO_CONTEXT { 219 ULONG FileInformationClass; 220 ULONG BufferLength; 221 ULONG FileNameLength; 222 WCHAR FileName[1]; 223 } FILEINFO_CONTEXT, *PFILEINFO_CONTEXT; 224 225 typedef struct _SETFILE_CONTEXT { 226 ULONG FileInformationClass; 227 ULONG BufferLength; 228 ULONG BufferOffset; 229 ULONG FileNameLength; 230 WCHAR FileName[1]; 231 } SETFILE_CONTEXT, *PSETFILE_CONTEXT; 232 233 typedef struct _VOLUME_CONTEXT { 234 ULONG FsInformationClass; 235 ULONG BufferLength; 236 } VOLUME_CONTEXT, *PVOLUME_CONTEXT; 237 238 typedef struct _LOCK_CONTEXT { 239 LARGE_INTEGER ByteOffset; 240 LARGE_INTEGER Length; 241 ULONG Key; 242 ULONG FileNameLength; 243 WCHAR FileName[1]; 244 } LOCK_CONTEXT, *PLOCK_CONTEXT; 245 246 typedef struct _FLUSH_CONTEXT { 247 ULONG FileNameLength; 248 WCHAR FileName[1]; 249 } FLUSH_CONTEXT, *PFLUSH_CONTEXT; 250 251 typedef struct _UNMOUNT_CONTEXT { 252 WCHAR DeviceName[64]; 253 ULONG Option; 254 } UNMOUNT_CONTEXT, *PUNMOUNT_CONTEXT; 255 256 typedef struct _SECURITY_CONTEXT { 257 SECURITY_INFORMATION SecurityInformation; 258 ULONG BufferLength; 259 ULONG FileNameLength; 260 WCHAR FileName[1]; 261 } SECURITY_CONTEXT, *PSECURITY_CONTEXT; 262 263 typedef struct _SET_SECURITY_CONTEXT { 264 SECURITY_INFORMATION SecurityInformation; 265 ULONG BufferLength; 266 ULONG BufferOffset; 267 ULONG FileNameLength; 268 WCHAR FileName[1]; 269 } SET_SECURITY_CONTEXT, *PSET_SECURITY_CONTEXT; 270 271 typedef struct _EVENT_CONTEXT { 272 ULONG Length; 273 ULONG MountId; 274 ULONG SerialNumber; 275 ULONG ProcessId; 276 UCHAR MajorFunction; 277 UCHAR MinorFunction; 278 ULONG Flags; 279 ULONG FileFlags; 280 ULONG64 Context; 281 union { 282 DIRECTORY_CONTEXT Directory; 283 READ_CONTEXT Read; 284 WRITE_CONTEXT Write; 285 FILEINFO_CONTEXT File; 286 CREATE_CONTEXT Create; 287 CLOSE_CONTEXT Close; 288 SETFILE_CONTEXT SetFile; 289 CLEANUP_CONTEXT Cleanup; 290 LOCK_CONTEXT Lock; 291 VOLUME_CONTEXT Volume; 292 FLUSH_CONTEXT Flush; 293 UNMOUNT_CONTEXT Unmount; 294 SECURITY_CONTEXT Security; 295 SET_SECURITY_CONTEXT SetSecurity; 296 } Operation; 297 } EVENT_CONTEXT, *PEVENT_CONTEXT; 298 299 #define WRITE_MAX_SIZE \ 300 (EVENT_CONTEXT_MAX_SIZE - sizeof(EVENT_CONTEXT) - 256 * sizeof(WCHAR)) 301 302 typedef struct _EVENT_INFORMATION { 303 ULONG SerialNumber; 304 NTSTATUS Status; 305 ULONG Flags; 306 union { 307 struct { 308 ULONG Index; 309 } Directory; 310 struct { 311 ULONG Flags; 312 ULONG Information; 313 } Create; 314 struct { 315 LARGE_INTEGER CurrentByteOffset; 316 } Read; 317 struct { 318 LARGE_INTEGER CurrentByteOffset; 319 } Write; 320 struct { 321 UCHAR DeleteOnClose; 322 } Delete; 323 struct { 324 ULONG Timeout; 325 } ResetTimeout; 326 struct { 327 HANDLE Handle; 328 } AccessToken; 329 } Operation; 330 ULONG64 Context; 331 ULONG BufferLength; 332 UCHAR Buffer[8]; 333 334 } EVENT_INFORMATION, *PEVENT_INFORMATION; 335 336 #define DOKAN_EVENT_ALTERNATIVE_STREAM_ON 1 337 #define DOKAN_EVENT_WRITE_PROTECT 2 338 #define DOKAN_EVENT_REMOVABLE 4 339 #define DOKAN_EVENT_MOUNT_MANAGER 8 340 #define DOKAN_EVENT_CURRENT_SESSION 16 341 342 typedef struct _EVENT_DRIVER_INFO { 343 ULONG DriverVersion; 344 ULONG Status; 345 ULONG DeviceNumber; 346 ULONG MountId; 347 WCHAR DeviceName[64]; 348 } EVENT_DRIVER_INFO, *PEVENT_DRIVER_INFO; 349 350 typedef struct _EVENT_START { 351 ULONG UserVersion; 352 ULONG DeviceType; 353 ULONG Flags; 354 WCHAR MountPoint[260]; 355 WCHAR UNCName[64]; 356 ULONG IrpTimeout; 357 } EVENT_START, *PEVENT_START; 358 359 typedef struct _DOKAN_RENAME_INFORMATION { 360 BOOLEAN ReplaceIfExists; 361 ULONG FileNameLength; 362 WCHAR FileName[1]; 363 } DOKAN_RENAME_INFORMATION, *PDOKAN_RENAME_INFORMATION; 364 365 typedef struct _DOKAN_LINK_INFORMATION { 366 BOOLEAN ReplaceIfExists; 367 ULONG FileNameLength; 368 WCHAR FileName[1]; 369 } DOKAN_LINK_INFORMATION, *PDOKAN_LINK_INFORMATION; 370 371 #endif // PUBLIC_H_