WDK Mini Filter Example
avscan.h
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) 1989-2011 Microsoft Corporation
4 
5 Module Name:
6 
7  avscan.h
8 
9 Abstract:
10 
11  Header file which contains the structures, type definitions,
12  constants, global variables and function prototypes that are
13  only visible within the kernel. Mainly used by avscan module.
14 
15 Environment:
16 
17  Kernel mode
18 
19 --*/
20 #ifndef __AVSCAN_H__
21 #define __AVSCAN_H__
22 
23 #ifndef RTL_USE_AVL_TABLES
24 #define RTL_USE_AVL_TABLES
25 #endif // RTL_USE_AVL_TABLES
26 
27 #define AV_VISTA (NTDDI_VERSION >= NTDDI_VISTA)
28 
29 #include <fltKernel.h>
30 #include <dontuse.h>
31 #include <suppress.h>
32 #include "utility.h"
33 #include "context.h"
34 #include "scan.h"
35 #include "csvfs.h"
36 #include "avlib.h"
37 
38 
39 #pragma prefast(disable:__WARNING_ENCODE_MEMBER_FUNCTION_POINTER, "Not valid for kernel mode drivers")
40 
41 //
42 // Scan context.
43 //
44 // We chose to seperate scan context and section context to have one struct per concept.
45 // The I/O request thread does not need to know how scanner implement the scan, so
46 // that the I/O request thread has less coupling with scanner threads.
47 //
48 // You can also put all of fields of the scan context into a section context, and allocate
49 // section context at the place of allocation of scan context.
50 //
51 
52 typedef struct _AV_SCAN_CONTEXT {
53 
54  LONG RefCount;
55  PFLT_INSTANCE FilterInstance;
56  PFILE_OBJECT FileObject;
58  LIST_ENTRY List;
60  LONGLONG ScanId;
61  ULONG ScanThreadId;
62 
66 
68 
69 //
70 // The global variable
71 //
72 
73 typedef struct _AV_SCANNER_GLOBAL_DATA {
74 
75  //
76  // A counter for Scan Id
77  //
78 
79  LONGLONG ScanIdCounter;
80 
81  //
82  // The global FLT_FILTER pointer. Many API needs this, such as
83  // FltAllocateContext(...)
84  //
85 
86  PFLT_FILTER Filter;
87 
88  //
89  // Server-side communicate ports.
90  //
91 
92  PFLT_PORT ScanServerPort;
93  PFLT_PORT AbortServerPort;
94  PFLT_PORT QueryServerPort;
95 
96  //
97  // The scan client ports.
98  // These ports are assigned at AvConnectNotifyCallback and cleaned at AvDisconnectNotifyCallback
99  //
100  // ScanClientPort is the connection port regarding the scan message.
101  // AbortClientPort is the connection port regarding the abort message.
102  // QueryClient is the connection port regarding the query command.
103  //
104 
105  PFLT_PORT ScanClientPort;
106  PFLT_PORT AbortClientPort;
107  PFLT_PORT QueryClientPort;
108 
109  //
110  // Scan context list head.
111  // At AvMessageNotifyCallback, when user passes ScanCtxId, we
112  // have to check the validity of the id by checking this list.
113  //
114 
115  LIST_ENTRY ScanCtxListHead;
116 
117  //
118  // The lock that synchronizes the accesses of the scan context list above.
119  //
120 
121  ERESOURCE ScanCtxListLock;
122 
123  //
124  // Timeout for local file scans in milliseconds
125  //
126 
128 
129  //
130  // Timeout for network file scans in milliseconds
131  //
132 
134 
135 #if DBG
136 
137  //
138  // Field to control nature of debug output
139  //
140 
141  ULONG DebugLevel;
142 #endif
143 
144  //
145  // A flag that indicating that the filter is being unloaded.
146  //
147 
148  BOOLEAN Unloading;
149 
151 
153 
154 #if DBG
155 
156 //
157 // Debugging level flags.
158 //
159 
160 #define AVDBG_TRACE_ROUTINES 0x00000001
161 #define AVDBG_TRACE_OPERATION_STATUS 0x00000002
162 #define AVDBG_TRACE_DEBUG 0x00000004
163 #define AVDBG_TRACE_ERROR 0x00000008
164 
165 #define AV_DBG_PRINT( _dbgLevel, _string ) \
166  if(FlagOn(Globals.DebugLevel,(_dbgLevel))) { \
167  DbgPrint _string; \
168  }
169 
170 #else
171 
172 #define AV_DBG_PRINT(_dbgLevel, _string) {NOTHING;}
173 
174 #endif
175 
176 FORCEINLINE
177 VOID
179  _Inout_ PFLT_CALLBACK_DATA Data,
180  _In_ PCFLT_RELATED_OBJECTS FltObjects,
181  _In_ NTSTATUS Status
182  )
183 /*++
184 
185 Routine Description:
186 
187  This function cancel the file open. This is supposed to be called at post create if
188  the I/O is cancelled.
189 
190 Arguments:
191 
192  Data - Pointer to the filter callbackData that is passed to us.
193 
194  FltObjects - Pointer to the FLT_RELATED_OBJECTS data structure containing
195  opaque handles to this filter, instance, its associated volume and
196  file object.
197 
198  Status - The status code to be returned for this IRP.
199 
200 Return Value:
201 
202  None.
203 
204 --*/
205 
206 {
207  FltCancelFileOpen( FltObjects->Instance, FltObjects->FileObject );
208  Data->IoStatus.Status = Status;
209  Data->IoStatus.Information = 0;
210 }
211 
212 
213 NTSTATUS
215  _In_ PSECURITY_DESCRIPTOR SecurityDescriptor,
216  _In_ AVSCAN_CONNECTION_TYPE ConnectionType
217  );
218 
219 NTSTATUS
221  _In_ ULONG ScanThreadId,
222  _In_ LONGLONG ScanId
223  );
224 
225 NTSTATUS
227  _In_ PFLT_INSTANCE Instance,
228  _In_ PFILE_OBJECT FileObject,
229  _Outptr_ PAV_SCAN_CONTEXT *ScanContext
230  );
231 
232 NTSTATUS
234  _In_ PAV_SCAN_CONTEXT ScanContext
235  );
236 
237 NTSTATUS
239  _In_ PAV_SCAN_CONTEXT ScanContext
240  );
241 
242 //
243 // Fianlize function for scan context and section context.
244 // Wrapper functions of synchronization calling sequences.
245 // In the normal cases, the caller should call AvFinalizeScanAndSection
246 // when it finishes using it.
247 //
248 // Unless the caller wants to do things about section context inside scan context,
249 // then it should call AvFinalizeScanContext(), and followed by
250 // AvFinalizeSectionContext()
251 //
252 // These wrappers are designed to make the synchronization easier.
253 //
254 NTSTATUS
256  _Inout_ PAV_SCAN_CONTEXT ScanContext
257  );
258 
259 NTSTATUS
262  );
263 
264 VOID
266  _Inout_ PAV_SCAN_CONTEXT ScanContext,
267  _Outptr_result_maybenull_ PAV_SECTION_CONTEXT *SectionContext
268  );
269 
270 #endif
271 
UCHAR IOMajorFunctionAtScan
Definition: avscan.h:63
LONGLONG NetworkScanTimeout
Definition: avscan.h:133
NTSTATUS AvPrepareServerPort(_In_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ AVSCAN_CONNECTION_TYPE ConnectionType)
LONG RefCount
Definition: avscan.h:54
LONGLONG ScanId
Definition: avscan.h:60
PFILE_OBJECT FileObject
Definition: avscan.h:56
PFLT_INSTANCE FilterInstance
Definition: avscan.h:55
PFLT_PORT ScanClientPort
Definition: avscan.h:105
_In_opt_ PFILE_OBJECT _In_opt_ PFLT_INSTANCE Instance
Definition: nc.h:493
LONGLONG LocalScanTimeout
Definition: avscan.h:127
PFLT_PORT QueryServerPort
Definition: avscan.h:94
LIST_ENTRY ScanCtxListHead
Definition: avscan.h:115
PFLT_PORT QueryClientPort
Definition: avscan.h:107
NTSTATUS AvFinalizeScanAndSection(_Inout_ PAV_SCAN_CONTEXT ScanContext)
AV_SCANNER_GLOBAL_DATA Globals
Definition: avscan.h:152
NTSTATUS AvAllocateScanContext(_In_ PFLT_INSTANCE Instance, _In_ PFILE_OBJECT FileObject, _Outptr_ PAV_SCAN_CONTEXT *ScanContext)
NTSTATUS AvFinalizeSectionContext(_Inout_ PAV_SECTION_CONTEXT SectionContext)
NTSTATUS AvReferenceScanContext(_In_ PAV_SCAN_CONTEXT ScanContext)
PFLT_FILTER Filter
Definition: avscan.h:86
PFLT_PORT ScanServerPort
Definition: avscan.h:92
NTSTATUS AvSendAbortToUser(_In_ ULONG ScanThreadId, _In_ LONGLONG ScanId)
struct _AV_SCANNER_GLOBAL_DATA * PAV_SCANNER_GLOBAL_DATA
struct _AV_SCAN_CONTEXT AV_SCAN_CONTEXT
BOOLEAN IoWaitOnScanCompleteNotificationAborted
Definition: avscan.h:65
LONGLONG ScanIdCounter
Definition: avscan.h:79
PAV_SECTION_CONTEXT SectionContext
Definition: avscan.h:59
BOOLEAN IsFileInTxWriter
Definition: avscan.h:64
struct _AV_SCAN_CONTEXT * PAV_SCAN_CONTEXT
struct _AV_SCANNER_GLOBAL_DATA AV_SCANNER_GLOBAL_DATA
ULONG ScanThreadId
Definition: avscan.h:61
IoStatus Status
ERESOURCE ScanCtxListLock
Definition: avscan.h:121
VOID AvFinalizeScanContext(_Inout_ PAV_SCAN_CONTEXT ScanContext, _Outptr_result_maybenull_ PAV_SECTION_CONTEXT *SectionContext)
LIST_ENTRY List
Definition: avscan.h:58
NTSTATUS AvReleaseScanContext(_In_ PAV_SCAN_CONTEXT ScanContext)
PFLT_PORT AbortClientPort
Definition: avscan.h:106
KEVENT ScanCompleteNotification
Definition: avscan.h:57
FORCEINLINE VOID AvCancelFileOpen(_Inout_ PFLT_CALLBACK_DATA Data, _In_ PCFLT_RELATED_OBJECTS FltObjects, _In_ NTSTATUS Status)
Definition: avscan.h:178
enum _AVSCAN_CONNECTION_TYPE AVSCAN_CONNECTION_TYPE
PFLT_PORT AbortServerPort
Definition: avscan.h:93

Social Network


Services Overview

Architect, implement and test file system filter drivers for a wide range of functionality. We can offer several levels of assistance to meet your specific.

Contact Us

You are welcome to contact us for salse or partnership.

Sales: sales@easefilter.com
Support: support@easefilter.com
Info: info@easefilter.com