WDK Mini Filter Example
minispy.h
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) 1989-2002 Microsoft Corporation
4 
5 Module Name:
6 
7  minispy.h
8 
9 Abstract:
10 
11  Header file which contains the structures, type definitions,
12  and constants that are shared between the kernel mode driver,
13  minispy.sys, and the user mode executable, minispy.exe.
14 
15 Environment:
16 
17  Kernel and user mode
18 
19 --*/
20 #ifndef __MINISPY_H__
21 #define __MINISPY_H__
22 
23 
24 //
25 // FltMgr's IRP major codes
26 //
27 
28 #define IRP_MJ_ACQUIRE_FOR_SECTION_SYNCHRONIZATION ((UCHAR)-1)
29 #define IRP_MJ_RELEASE_FOR_SECTION_SYNCHRONIZATION ((UCHAR)-2)
30 #define IRP_MJ_ACQUIRE_FOR_MOD_WRITE ((UCHAR)-3)
31 #define IRP_MJ_RELEASE_FOR_MOD_WRITE ((UCHAR)-4)
32 #define IRP_MJ_ACQUIRE_FOR_CC_FLUSH ((UCHAR)-5)
33 #define IRP_MJ_RELEASE_FOR_CC_FLUSH ((UCHAR)-6)
34 #define IRP_MJ_NOTIFY_STREAM_FO_CREATION ((UCHAR)-7)
35 
36 #define IRP_MJ_FAST_IO_CHECK_IF_POSSIBLE ((UCHAR)-13)
37 #define IRP_MJ_NETWORK_QUERY_OPEN ((UCHAR)-14)
38 #define IRP_MJ_MDL_READ ((UCHAR)-15)
39 #define IRP_MJ_MDL_READ_COMPLETE ((UCHAR)-16)
40 #define IRP_MJ_PREPARE_MDL_WRITE ((UCHAR)-17)
41 #define IRP_MJ_MDL_WRITE_COMPLETE ((UCHAR)-18)
42 #define IRP_MJ_VOLUME_MOUNT ((UCHAR)-19)
43 #define IRP_MJ_VOLUME_DISMOUNT ((UCHAR)-20)
44 
45 //
46 // My own definition for transaction notify command
47 //
48 
49 #define IRP_MJ_TRANSACTION_NOTIFY ((UCHAR)-40)
50 
51 
52 //
53 // Version definition
54 //
55 
56 #define MINISPY_MAJ_VERSION 2
57 #define MINISPY_MIN_VERSION 0
58 
59 typedef struct _MINISPYVER {
60 
61  USHORT Major;
62  USHORT Minor;
63 
65 
66 //
67 // Name of minispy's communication server port
68 //
69 
70 #define MINISPY_PORT_NAME L"\\MiniSpyPort"
71 
72 //
73 // Local definitions for passing parameters between the filter and user mode
74 //
75 
76 typedef ULONG_PTR FILE_ID;
77 typedef _Return_type_success_(return >= 0) LONG NTSTATUS;
78 
79 //
80 // The maximum size of a record that can be passed from the filter
81 //
82 
83 #define RECORD_SIZE 1024
84 
85 //
86 // This defines the type of record buffer this is along with certain flags.
87 //
88 
89 #define RECORD_TYPE_NORMAL 0x00000000
90 #define RECORD_TYPE_FILETAG 0x00000004
91 
92 #define RECORD_TYPE_FLAG_STATIC 0x80000000
93 #define RECORD_TYPE_FLAG_EXCEED_MEMORY_ALLOWANCE 0x20000000
94 #define RECORD_TYPE_FLAG_OUT_OF_MEMORY 0x10000000
95 #define RECORD_TYPE_FLAG_MASK 0xffff0000
96 
97 //
98 // The fixed data received for RECORD_TYPE_NORMAL
99 //
100 
101 typedef struct _RECORD_DATA {
102 
103  LARGE_INTEGER OriginatingTime;
104  LARGE_INTEGER CompletionTime;
105 
109 
112 
113  ULONG_PTR Information;
114 
115  NTSTATUS Status;
116 
117  ULONG IrpFlags;
118  ULONG Flags;
119 
122  UCHAR Reserved[2]; // Alignment on IA64
123 
124  PVOID Arg1;
125  PVOID Arg2;
126  PVOID Arg3;
127  PVOID Arg4;
128  PVOID Arg5;
129  LARGE_INTEGER Arg6;
130 
131  ULONG EcpCount;
133 
135 
136 //
137 // What information we actually log.
138 //
139 
140 #pragma warning(push)
141 #pragma warning(disable:4200) // disable warnings for structures with zero length arrays.
142 
143 typedef struct _LOG_RECORD {
144 
145 
146  ULONG Length; // Length of log record. This Does not include
147  ULONG SequenceNumber; // space used by other members of RECORD_LIST
148 
149  ULONG RecordType; // The type of log record this is.
150  ULONG Reserved; // For alignment on IA64
151 
153  WCHAR Name[]; // This is a null terminated string
154 
156 
157 #pragma warning(pop)
158 
159 //
160 // How the mini-filter manages the log records.
161 //
162 
163 typedef struct _RECORD_LIST {
164 
165  LIST_ENTRY List;
166 
167  //
168  // Must always be last item. See MAX_LOG_RECORD_LENGTH macro below.
169  // Must be aligned on PVOID boundary in this structure. This is because the
170  // log records are going to be packed one after another & accessed directly
171  // Size of log record must also be multiple of PVOID size to avoid alignment
172  // faults while accessing the log records on IA64
173  //
174 
176 
178 
179 //
180 // Defines the commands between the utility and the filter
181 //
182 
183 typedef enum _MINISPY_COMMAND {
184 
187 
189 
190 //
191 // Defines the command structure between the utility and the filter.
192 //
193 
194 #pragma warning(push)
195 #pragma warning(disable:4200) // disable warnings for structures with zero length arrays.
196 
197 typedef struct _COMMAND_MESSAGE {
198  MINISPY_COMMAND Command;
199  ULONG Reserved; // Alignment on IA64
200  UCHAR Data[];
202 
203 #pragma warning(pop)
204 
205 //
206 // The maximum number of BYTES that can be used to store the file name in the
207 // RECORD_LIST structure
208 //
209 
210 #define MAX_NAME_SPACE ROUND_TO_SIZE( (RECORD_SIZE - sizeof(RECORD_LIST)), sizeof( PVOID ))
211 
212 //
213 // The maximum space, in bytes and WCHARs, available for the name (and ECP
214 // if present) string, not including the space that must be reserved for a NULL
215 //
216 
217 #define MAX_NAME_SPACE_LESS_NULL (MAX_NAME_SPACE - sizeof(UNICODE_NULL))
218 #define MAX_NAME_WCHARS_LESS_NULL MAX_NAME_SPACE_LESS_NULL / sizeof(WCHAR)
219 
220 //
221 // Returns the number of BYTES unused in the RECORD_LIST structure. Note that
222 // LogRecord->Length already contains the size of LOG_RECORD which is why we
223 // have to remove it.
224 //
225 
226 #define REMAINING_NAME_SPACE(LogRecord) \
227  (FLT_ASSERT((LogRecord)->Length >= sizeof(LOG_RECORD)), \
228  (USHORT)(MAX_NAME_SPACE - ((LogRecord)->Length - sizeof(LOG_RECORD))))
229 
230 #define MAX_LOG_RECORD_LENGTH (RECORD_SIZE - FIELD_OFFSET( RECORD_LIST, LogRecord ))
231 
232 
233 //
234 // Macros available in kernel mode which are not available in user mode
235 //
236 
237 #ifndef Add2Ptr
238 #define Add2Ptr(P,I) ((PVOID)((PUCHAR)(P) + (I)))
239 #endif
240 
241 #ifndef ROUND_TO_SIZE
242 #define ROUND_TO_SIZE(_length, _alignment) \
243  (((_length) + ((_alignment)-1)) & ~((_alignment) - 1))
244 #endif
245 
246 #ifndef FlagOn
247 #define FlagOn(_F,_SF) ((_F) & (_SF))
248 #endif
249 
250 #endif /* __MINISPY_H__ */
251 
FILE_ID ThreadId
Definition: minispy.h:111
USHORT Major
Definition: minispy.h:61
ULONG Length
Definition: minispy.h:146
LOG_RECORD LogRecord
Definition: minispy.h:175
ULONG Flags
Definition: minispy.h:118
struct _MINISPYVER * PMINISPYVER
PVOID Arg4
Definition: minispy.h:127
LARGE_INTEGER Arg6
Definition: minispy.h:129
struct _RECORD_LIST * PRECORD_LIST
FILE_ID FileObject
Definition: minispy.h:107
ULONG_PTR FILE_ID
Definition: minispy.h:76
LIST_ENTRY List
Definition: minispy.h:165
UCHAR CallbackMajorId
Definition: minispy.h:120
struct _COMMAND_MESSAGE * PCOMMAND_MESSAGE
ULONG Reserved
Definition: minispy.h:150
_MINISPY_COMMAND
Definition: minispy.h:183
struct _LOG_RECORD LOG_RECORD
PVOID Arg1
Definition: minispy.h:124
struct _RECORD_DATA RECORD_DATA
ULONG SequenceNumber
Definition: minispy.h:147
PVOID Arg3
Definition: minispy.h:126
struct _RECORD_DATA * PRECORD_DATA
struct _COMMAND_MESSAGE COMMAND_MESSAGE
FILE_ID DeviceObject
Definition: minispy.h:106
NTSTATUS Status
Definition: minispy.h:115
enum _MINISPY_COMMAND MINISPY_COMMAND
struct _RECORD_LIST RECORD_LIST
ULONG KnownEcpMask
Definition: minispy.h:132
ULONG Reserved
Definition: minispy.h:199
ULONG IrpFlags
Definition: minispy.h:117
FILE_ID Transaction
Definition: minispy.h:108
RECORD_DATA Data
Definition: minispy.h:152
FILE_ID ProcessId
Definition: minispy.h:110
struct _MINISPYVER MINISPYVER
ULONG_PTR Information
Definition: minispy.h:113
LARGE_INTEGER CompletionTime
Definition: minispy.h:104
struct _LOG_RECORD * PLOG_RECORD
ULONG EcpCount
Definition: minispy.h:131
PVOID Arg5
Definition: minispy.h:128
typedef _Return_type_success_(return >=0) LONG NTSTATUS
MINISPY_COMMAND Command
Definition: minispy.h:198
USHORT Minor
Definition: minispy.h:62
PVOID Arg2
Definition: minispy.h:125
LARGE_INTEGER OriginatingTime
Definition: minispy.h:103
ULONG RecordType
Definition: minispy.h:149
UCHAR CallbackMinorId
Definition: minispy.h:121

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