2 * Copyright (C) 2018 Alistair Leslie-Hughes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include <ddk/ntifs.h>
27 typedef struct _FLT_FILTER
*PFLT_FILTER
;
28 typedef struct _FLT_INSTANCE
*PFLT_INSTANCE
;
29 typedef ULONG FLT_CALLBACK_DATA_FLAGS
;
30 typedef USHORT FLT_CONTEXT_REGISTRATION_FLAGS
;
31 typedef USHORT FLT_CONTEXT_TYPE
;
32 typedef ULONG FLT_FILE_NAME_OPTIONS
;
33 typedef ULONG FLT_FILTER_UNLOAD_FLAGS
;
34 typedef ULONG FLT_INSTANCE_QUERY_TEARDOWN_FLAGS
;
35 typedef ULONG FLT_INSTANCE_SETUP_FLAGS
;
36 typedef ULONG FLT_INSTANCE_TEARDOWN_FLAGS
;
37 typedef ULONG FLT_NORMALIZE_NAME_FLAGS
;
38 typedef ULONG FLT_OPERATION_REGISTRATION_FLAGS
;
39 typedef ULONG FLT_POST_OPERATION_FLAGS
;
40 typedef ULONG FLT_REGISTRATION_FLAGS
;
41 typedef void* PFLT_CONTEXT
;
44 #define FLT_VOLUME_CONTEXT 0x0001
45 #define FLT_INSTANCE_CONTEXT 0x0002
46 #define FLT_FILE_CONTEXT 0x0004
47 #define FLT_STREAM_CONTEXT 0x0008
48 #define FLT_STREAMHANDLE_CONTEXT 0x0010
49 #define FLT_TRANSACTION_CONTEXT 0x0020
51 #define FLTFL_OPERATION_REGISTRATION_SKIP_PAGING_IO 0x00000001
52 #define FLTFL_OPERATION_REGISTRATION_SKIP_CACHED_IO 0x00000002
53 #define FLTFL_OPERATION_REGISTRATION_SKIP_NON_DASD_IO 0x00000004
55 #define FLTFL_INSTANCE_TEARDOWN_MANUAL 0x00000001
56 #define FLTFL_INSTANCE_TEARDOWN_FILTER_UNLOAD 0x00000002
57 #define FLTFL_INSTANCE_TEARDOWN_MANDATORY_FILTER_UNLOAD 0x00000004
58 #define FLTFL_INSTANCE_TEARDOWN_VOLUME_DISMOUNT 0x00000008
59 #define FLTFL_INSTANCE_TEARDOWN_INTERNAL_ERROR 0x00000010
61 /* Belongs in fltuserstructures.h */
62 typedef enum _FLT_FILESYSTEM_TYPE
74 FLT_FSTYPE_MS_NETWARE
,
79 FLT_FSTYPE_ROXIO_UDF1
,
80 FLT_FSTYPE_ROXIO_UDF2
,
81 FLT_FSTYPE_ROXIO_UDF3
,
94 } FLT_FILESYSTEM_TYPE
, *PFLT_FILESYSTEM_TYPE
;
96 typedef struct _FLT_NAME_CONTROL
99 } FLT_NAME_CONTROL
, *PFLT_NAME_CONTROL
;
101 typedef enum _FLT_PREOP_CALLBACK_STATUS
103 FLT_PREOP_SUCCESS_WITH_CALLBACK
,
104 FLT_PREOP_SUCCESS_NO_CALLBACK
,
106 FLT_PREOP_DISALLOW_FASTIO
,
108 FLT_PREOP_SYNCHRONIZE
,
109 FLT_PREOP_DISALLOW_FSFILTER_IO
110 } FLT_PREOP_CALLBACK_STATUS
, *PFLT_PREOP_CALLBACK_STATUS
;
112 typedef enum _FLT_POSTOP_CALLBACK_STATUS
114 FLT_POSTOP_FINISHED_PROCESSING
,
115 FLT_POSTOP_MORE_PROCESSING_REQUIRED
,
116 FLT_POSTOP_DISALLOW_FSFILTER_IO
117 } FLT_POSTOP_CALLBACK_STATUS
, *PFLT_POSTOP_CALLBACK_STATUS
;
119 typedef struct _FLT_RELATED_CONTEXTS
121 PFLT_CONTEXT VolumeContext
;
122 PFLT_CONTEXT InstanceContext
;
123 PFLT_CONTEXT FileContext
;
124 PFLT_CONTEXT StreamContext
;
125 PFLT_CONTEXT StreamHandleContext
;
126 PFLT_CONTEXT TransactionContext
;
127 } FLT_RELATED_CONTEXTS
, *PFLT_RELATED_CONTEXTS
;
129 typedef const struct _FLT_RELATED_OBJECTS
*PCFLT_RELATED_OBJECTS
;
131 typedef union _FLT_PARAMETERS
135 PIO_SECURITY_CONTEXT SecurityContext
;
137 USHORT POINTER_ALIGNMENT FileAttributes
;
139 ULONG POINTER_ALIGNMENT EaLength
;
141 LARGE_INTEGER AllocationSize
;
146 PIO_SECURITY_CONTEXT SecurityContext
;
148 USHORT POINTER_ALIGNMENT Reserved
;
153 #undef CreateMailslot
156 PIO_SECURITY_CONTEXT SecurityContext
;
158 USHORT POINTER_ALIGNMENT Reserved
;
166 ULONG POINTER_ALIGNMENT Key
;
167 LARGE_INTEGER ByteOffset
;
175 ULONG POINTER_ALIGNMENT Key
;
176 LARGE_INTEGER ByteOffset
;
184 FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass
;
186 } QueryFileInformation
;
191 FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass
;
192 PFILE_OBJECT ParentOfTarget
;
197 BOOLEAN ReplaceIfExists
;
204 } SetFileInformation
;
211 ULONG POINTER_ALIGNMENT EaIndex
;
226 FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass
;
228 } QueryVolumeInformation
;
233 FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass
;
235 } SetVolumeInformation
;
242 PUNICODE_STRING FileName
;
243 FILE_INFORMATION_CLASS FileInformationClass
;
244 ULONG POINTER_ALIGNMENT FileIndex
;
245 void *DirectoryBuffer
;
252 ULONG POINTER_ALIGNMENT CompletionFilter
;
253 ULONG POINTER_ALIGNMENT Spare1
;
254 ULONG POINTER_ALIGNMENT Spare2
;
255 void *DirectoryBuffer
;
262 ULONG POINTER_ALIGNMENT CompletionFilter
;
263 DIRECTORY_NOTIFY_INFORMATION_CLASS POINTER_ALIGNMENT DirectoryNotifyInformationClass
;
264 ULONG POINTER_ALIGNMENT Spare2
;
265 void *DirectoryBuffer
;
275 PDEVICE_OBJECT DeviceObject
;
280 ULONG OutputBufferLength
;
281 ULONG POINTER_ALIGNMENT InputBufferLength
;
282 ULONG POINTER_ALIGNMENT FsControlCode
;
287 ULONG OutputBufferLength
;
288 ULONG POINTER_ALIGNMENT InputBufferLength
;
289 ULONG POINTER_ALIGNMENT FsControlCode
;
292 PMDL OutputMdlAddress
;
297 ULONG OutputBufferLength
;
298 ULONG POINTER_ALIGNMENT InputBufferLength
;
299 ULONG POINTER_ALIGNMENT FsControlCode
;
305 ULONG OutputBufferLength
;
306 ULONG POINTER_ALIGNMENT InputBufferLength
;
307 ULONG POINTER_ALIGNMENT FsControlCode
;
308 void *InputSystemBuffer
;
310 PMDL OutputMdlAddress
;
318 ULONG OutputBufferLength
;
319 ULONG POINTER_ALIGNMENT InputBufferLength
;
320 ULONG POINTER_ALIGNMENT IoControlCode
;
325 ULONG OutputBufferLength
;
326 ULONG POINTER_ALIGNMENT InputBufferLength
;
327 ULONG POINTER_ALIGNMENT IoControlCode
;
330 PMDL OutputMdlAddress
;
335 ULONG OutputBufferLength
;
336 ULONG POINTER_ALIGNMENT InputBufferLength
;
337 ULONG POINTER_ALIGNMENT IoControlCode
;
343 ULONG OutputBufferLength
;
344 ULONG POINTER_ALIGNMENT InputBufferLength
;
345 ULONG POINTER_ALIGNMENT IoControlCode
;
346 void *InputSystemBuffer
;
348 PMDL OutputMdlAddress
;
353 ULONG OutputBufferLength
;
354 ULONG POINTER_ALIGNMENT InputBufferLength
;
355 ULONG POINTER_ALIGNMENT IoControlCode
;
363 PLARGE_INTEGER Length
;
364 ULONG POINTER_ALIGNMENT Key
;
365 LARGE_INTEGER ByteOffset
;
367 BOOLEAN FailImmediately
;
368 BOOLEAN ExclusiveLock
;
373 SECURITY_INFORMATION SecurityInformation
;
374 ULONG POINTER_ALIGNMENT Length
;
375 void *SecurityBuffer
;
381 SECURITY_INFORMATION SecurityInformation
;
382 PSECURITY_DESCRIPTOR SecurityDescriptor
;
387 ULONG_PTR ProviderId
;
397 PFILE_GET_QUOTA_INFORMATION SidList
;
414 PCM_RESOURCE_LIST AllocatedResources
;
415 PCM_RESOURCE_LIST AllocatedResourcesTranslated
;
420 DEVICE_RELATION_TYPE Type
;
421 } QueryDeviceRelations
;
425 const GUID
*InterfaceType
;
428 PINTERFACE Interface
;
429 void *InterfaceSpecificData
;
434 PDEVICE_CAPABILITIES Capabilities
;
435 } DeviceCapabilities
;
439 PIO_RESOURCE_REQUIREMENTS_LIST IoResourceRequirementList
;
440 } FilterResourceRequirements
;
447 ULONG POINTER_ALIGNMENT Length
;
456 BUS_QUERY_ID_TYPE IdType
;
461 DEVICE_TEXT_TYPE DeviceTextType
;
462 LCID POINTER_ALIGNMENT LocaleId
;
469 DEVICE_USAGE_NOTIFICATION_TYPE POINTER_ALIGNMENT Type
;
475 FS_FILTER_SECTION_SYNC_TYPE SyncType
;
476 ULONG PageProtection
;
477 PFS_FILTER_SECTION_SYNC_OUTPUT OutputInformation
;
478 } AcquireForSectionSynchronization
;
482 PLARGE_INTEGER EndingOffset
;
483 PERESOURCE
*ResourceToRelease
;
484 } AcquireForModifiedPageWriter
;
488 PERESOURCE ResourceToRelease
;
489 } ReleaseForModifiedPageWriter
;
494 void *FileInformation
;
496 FILE_INFORMATION_CLASS FileInformationClass
;
501 LARGE_INTEGER FileOffset
;
503 ULONG POINTER_ALIGNMENT LockKey
;
504 BOOLEAN POINTER_ALIGNMENT CheckForReadOperation
;
505 } FastIoCheckIfPossible
;
510 PFILE_NETWORK_OPEN_INFORMATION NetworkInformation
;
515 LARGE_INTEGER FileOffset
;
516 ULONG POINTER_ALIGNMENT Length
;
517 ULONG POINTER_ALIGNMENT Key
;
528 LARGE_INTEGER FileOffset
;
529 ULONG POINTER_ALIGNMENT Length
;
530 ULONG POINTER_ALIGNMENT Key
;
536 LARGE_INTEGER FileOffset
;
552 LARGE_INTEGER Argument6
;
554 } FLT_PARAMETERS
, *PFLT_PARAMETERS
;
556 typedef struct _FLT_IO_PARAMETER_BLOCK
561 UCHAR OperationFlags
;
563 PFILE_OBJECT TargetFileObject
;
564 PFLT_INSTANCE TargetInstance
;
565 FLT_PARAMETERS Parameters
;
566 } FLT_IO_PARAMETER_BLOCK
, *PFLT_IO_PARAMETER_BLOCK
;
568 typedef struct _FLT_CALLBACK_DATA
570 FLT_CALLBACK_DATA_FLAGS Flags
;
571 PETHREAD
const Thread
;
572 PFLT_IO_PARAMETER_BLOCK
const Iopb
;
573 IO_STATUS_BLOCK IoStatus
;
574 struct _FLT_TAG_DATA_BUFFER
*TagData
;
580 LIST_ENTRY QueueLinks
;
581 void *QueueContext
[2];
583 void *FilterContext
[4];
585 KPROCESSOR_MODE RequestorMode
;
586 } FLT_CALLBACK_DATA
, *PFLT_CALLBACK_DATA
;
588 typedef void* (__WINE_ALLOC_SIZE(2) WINAPI
*PFLT_CONTEXT_ALLOCATE_CALLBACK
)(POOL_TYPE
,SIZE_T
,FLT_CONTEXT_TYPE
);
589 typedef void (WINAPI
*PFLT_CONTEXT_CLEANUP_CALLBACK
)(PFLT_CONTEXT
, FLT_CONTEXT_TYPE
);
590 typedef void (WINAPI
*PFLT_CONTEXT_FREE_CALLBACK
)(void *, FLT_CONTEXT_TYPE
);
591 typedef NTSTATUS (WINAPI
*PFLT_FILTER_UNLOAD_CALLBACK
)(FLT_FILTER_UNLOAD_FLAGS
);
592 typedef NTSTATUS (WINAPI
*PFLT_INSTANCE_QUERY_TEARDOWN_CALLBACK
)(PCFLT_RELATED_OBJECTS
,
593 FLT_INSTANCE_QUERY_TEARDOWN_FLAGS
);
594 typedef NTSTATUS (WINAPI
*PFLT_GENERATE_FILE_NAME
)(PFLT_INSTANCE
, PFILE_OBJECT
,PFLT_CALLBACK_DATA
,
595 FLT_FILE_NAME_OPTIONS
,PBOOLEAN
, PFLT_NAME_CONTROL
);
596 typedef NTSTATUS (WINAPI
*PFLT_INSTANCE_SETUP_CALLBACK
)(PCFLT_RELATED_OBJECTS
,FLT_INSTANCE_SETUP_FLAGS
,
597 DEVICE_TYPE
,FLT_FILESYSTEM_TYPE
);
598 typedef void (WINAPI
*PFLT_INSTANCE_TEARDOWN_CALLBACK
)(PCFLT_RELATED_OBJECTS
, FLT_INSTANCE_TEARDOWN_FLAGS
);
599 typedef void (WINAPI
*PFLT_NORMALIZE_CONTEXT_CLEANUP
)(void**);
600 typedef NTSTATUS (WINAPI
*PFLT_NORMALIZE_NAME_COMPONENT
)(PFLT_INSTANCE
, PCUNICODE_STRING
, USHORT
,
601 PCUNICODE_STRING
,PFILE_NAMES_INFORMATION
,ULONG
,FLT_NORMALIZE_NAME_FLAGS
, void **);
602 typedef NTSTATUS (WINAPI
*PFLT_NORMALIZE_NAME_COMPONENT_EX
)(PFLT_INSTANCE
, PFILE_OBJECT
, PCUNICODE_STRING
,
603 USHORT
, PCUNICODE_STRING
,PFILE_NAMES_INFORMATION
, ULONG
, FLT_NORMALIZE_NAME_FLAGS Flags
,
604 void **NormalizationContext
);
605 typedef FLT_PREOP_CALLBACK_STATUS (WINAPI
*PFLT_PRE_OPERATION_CALLBACK
)(PFLT_CALLBACK_DATA
,
606 PCFLT_RELATED_OBJECTS
, void**);
607 typedef FLT_POSTOP_CALLBACK_STATUS (WINAPI
*PFLT_POST_OPERATION_CALLBACK
)(PFLT_CALLBACK_DATA
,
608 PCFLT_RELATED_OBJECTS
, void*, FLT_POST_OPERATION_FLAGS
);
609 typedef NTSTATUS (WINAPI
*PFLT_SECTION_CONFLICT_NOTIFICATION_CALLBACK
)(PFLT_INSTANCE
, PFLT_CONTEXT
,
611 typedef NTSTATUS (WINAPI
*PFLT_TRANSACTION_NOTIFICATION_CALLBACK
)(PCFLT_RELATED_OBJECTS
, PFLT_CONTEXT
, ULONG
);
613 typedef struct _FLT_CONTEXT_REGISTRATION
615 FLT_CONTEXT_TYPE ContextType
;
616 FLT_CONTEXT_REGISTRATION_FLAGS Flags
;
617 PFLT_CONTEXT_CLEANUP_CALLBACK ContextCleanupCallback
;
620 PFLT_CONTEXT_ALLOCATE_CALLBACK ContextAllocateCallback
;
621 PFLT_CONTEXT_FREE_CALLBACK ContextFreeCallback
;
623 } FLT_CONTEXT_REGISTRATION
, *PFLT_CONTEXT_REGISTRATION
;
625 typedef const FLT_CONTEXT_REGISTRATION
*PCFLT_CONTEXT_REGISTRATION
;
627 typedef struct _FLT_OPERATION_REGISTRATION
630 FLT_OPERATION_REGISTRATION_FLAGS Flags
;
631 PFLT_PRE_OPERATION_CALLBACK PreOperation
;
632 PFLT_POST_OPERATION_CALLBACK PostOperation
;
634 } FLT_OPERATION_REGISTRATION
, *PFLT_OPERATION_REGISTRATION
;
636 typedef struct _FLT_REGISTRATION
640 FLT_REGISTRATION_FLAGS Flags
;
641 const FLT_CONTEXT_REGISTRATION
*ContextRegistration
;
642 const FLT_OPERATION_REGISTRATION
*OperationRegistration
;
643 PFLT_FILTER_UNLOAD_CALLBACK FilterUnloadCallback
;
644 PFLT_INSTANCE_SETUP_CALLBACK InstanceSetupCallback
;
645 PFLT_INSTANCE_QUERY_TEARDOWN_CALLBACK InstanceQueryTeardownCallback
;
646 PFLT_INSTANCE_TEARDOWN_CALLBACK InstanceTeardownStartCallback
;
647 PFLT_INSTANCE_TEARDOWN_CALLBACK InstanceTeardownCompleteCallback
;
648 PFLT_GENERATE_FILE_NAME GenerateFileNameCallback
;
649 PFLT_NORMALIZE_NAME_COMPONENT NormalizeNameComponentCallback
;
650 PFLT_NORMALIZE_CONTEXT_CLEANUP NormalizeContextCleanupCallback
;
651 PFLT_TRANSACTION_NOTIFICATION_CALLBACK TransactionNotificationCallback
;
652 PFLT_NORMALIZE_NAME_COMPONENT_EX NormalizeNameComponentExCallback
;
653 PFLT_SECTION_CONFLICT_NOTIFICATION_CALLBACK SectionNotificationCallback
;
654 } FLT_REGISTRATION
, *PFLT_REGISTRATION
;
657 void* WINAPI
FltGetRoutineAddress(LPCSTR name
);
658 NTSTATUS WINAPI
FltRegisterFilter(PDRIVER_OBJECT
, const FLT_REGISTRATION
*, PFLT_FILTER
*);
659 NTSTATUS WINAPI
FltStartFiltering(PFLT_FILTER
);
660 void WINAPI
FltUnregisterFilter(PFLT_FILTER
);