ReactOS 0.4.15-dev-7842-g558ab78
filter.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: File system filter implementation of the original service.c file
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 * Ged Murphy <gedmurphy@reactos.org>
7 */
8
9//#include <fltuser.h>
10#include <kmt_test.h>
11#include "kmtest.h"
12
13#include <assert.h>
14
15#define SERVICE_ACCESS (SERVICE_START | SERVICE_STOP | DELETE)
16
17
18
32{
33 HRESULT hResult;
35
37
38 hResult = FilterLoad(ServiceName);
39 Error = SCODE_CODE(hResult);
40
41 return Error;
42}
43#if 0
63KmtFltCreateAndStartService(
65 _In_z_ PCWSTR ServicePath,
66 _In_z_ PCWSTR DisplayName OPTIONAL,
67 _Out_ SC_HANDLE *ServiceHandle,
68 _In_ BOOLEAN RestartIfRunning)
69{
71
72 assert(ServiceHandle);
73
74 Error = KmtFltCreateService(ServiceName, ServicePath, DisplayName, ServiceHandle);
75
78
80 goto cleanup;
81
83
85 goto cleanup;
86
88
89 if (!RestartIfRunning)
90 goto cleanup;
91
93 if (Error)
94 goto cleanup;
95
97 if (Error)
98 goto cleanup;
99
100cleanup:
101 assert(Error);
102 return Error;
103}
104#endif
105
118DWORD
121 _Out_ HANDLE *hPort)
122{
123 HRESULT hResult;
124 DWORD Error;
125
127 assert(hPort);
128
130 0,
131 NULL,
132 0,
133 NULL,
134 hPort);
135 Error = SCODE_CODE(hResult);
136
137 return Error;
138}
139
150DWORD
152 _In_ HANDLE hPort)
153{
155
156 assert(hPort);
157
158 if (!CloseHandle(hPort))
159 {
161 }
162
163 return Error;
164}
165
186DWORD
188 _In_ HANDLE hPort,
189 _In_reads_bytes_(dwInBufferSize) LPVOID InBuffer,
194{
195 DWORD BytesRet;
196 HRESULT hResult;
197 DWORD Error;
198
199 assert(hPort);
200 assert(InBuffer);
202
204
205 hResult = FilterSendMessage(hPort,
206 InBuffer,
208 OutBuffer,
210 &BytesRet);
211
212 Error = SCODE_CODE(hResult);
213 if (Error == ERROR_SUCCESS)
214 {
215 if (BytesRet)
216 {
217 *BytesReturned = BytesRet;
218 }
219 }
220
221 return Error;
222}
223
240DWORD
242 _In_ HANDLE hPort,
243 _Out_writes_bytes_(MessageBufferSize) PFILTER_MESSAGE_HEADER MessageBuffer,
244 _In_ DWORD MessageBufferSize,
245 _In_opt_ LPOVERLAPPED Overlapped)
246{
247 HRESULT hResult;
248 DWORD Error;
249
250 assert(hPort);
251 assert(MessageBuffer);
252
253 hResult = FilterGetMessage(hPort,
254 MessageBuffer,
255 MessageBufferSize,
256 Overlapped);
257 Error = SCODE_CODE(hResult);
258 return Error;
259}
260
275DWORD
277 _In_ HANDLE hPort,
278 _In_reads_bytes_(ReplyBufferSize) PFILTER_REPLY_HEADER ReplyBuffer,
279 _In_ DWORD ReplyBufferSize)
280{
281 HRESULT hResult;
282 DWORD Error;
283
284 hResult = FilterReplyMessage(hPort,
286 ReplyBufferSize);
287 Error = SCODE_CODE(hResult);
288 return Error;
289}
290
305DWORD
307 _In_ HANDLE hPort,
308 _In_ LPOVERLAPPED Overlapped,
310{
313
314 *BytesTransferred = 0;
315
316 Success = GetOverlappedResult(hPort, Overlapped, BytesTransferred, TRUE);
317 if (!Success)
318 {
320 }
321
322 return Error;
323}
324
335DWORD
338{
339 HRESULT hResult;
341
343
344 hResult = FilterUnload(ServiceName);
345 Error = SCODE_CODE(hResult);
346
347 return Error;
348}
unsigned char BOOLEAN
static WCHAR ServiceName[]
Definition: browser.c:19
BOOL Error
Definition: chkdsk.c:66
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:739
_Must_inspect_result_ HRESULT WINAPI FilterSendMessage(_In_ HANDLE hPort, _In_reads_bytes_(dwInBufferSize) LPVOID lpInBuffer, _In_ DWORD dwInBufferSize, _Out_writes_bytes_to_opt_(dwOutBufferSize, *lpBytesReturned) LPVOID lpOutBuffer, _In_ DWORD dwOutBufferSize, _Out_ LPDWORD lpBytesReturned)
Definition: message.c:131
_Must_inspect_result_ HRESULT WINAPI FilterConnectCommunicationPort(_In_ LPCWSTR lpPortName, _In_ DWORD dwOptions, _In_reads_bytes_opt_(wSizeOfContext) LPCVOID lpContext, _In_ WORD wSizeOfContext, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Outptr_ HANDLE *hPort)
Definition: message.c:25
_Must_inspect_result_ HRESULT WINAPI FilterGetMessage(_In_ HANDLE hPort, _Out_writes_bytes_(dwMessageBufferSize) PFILTER_MESSAGE_HEADER lpMessageBuffer, _In_ DWORD dwMessageBufferSize, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition: message.c:150
_Must_inspect_result_ HRESULT WINAPI FilterReplyMessage(_In_ HANDLE hPort, _In_reads_bytes_(dwReplyBufferSize) PFILTER_REPLY_HEADER lpReplyBuffer, _In_ DWORD dwReplyBufferSize)
Definition: message.c:165
static void cleanup(void)
Definition: main.c:1335
#define assert(x)
Definition: debug.h:53
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_ PFLT_PORT _In_ ULONG _Out_writes_bytes_opt_ ReplyLength PVOID ReplyBuffer
Definition: fltkernel.h:1902
_Must_inspect_result_ HRESULT WINAPI FilterLoad(_In_ LPCWSTR lpFilterName)
Definition: fltlib.c:42
_Must_inspect_result_ HRESULT WINAPI FilterUnload(_In_ LPCWSTR lpFilterName)
Definition: fltlib.c:50
DWORD KmtFltCreateService(_In_z_ PCWSTR ServiceName, _In_z_ PCWSTR DisplayName, _Out_ SC_HANDLE *ServiceHandle)
Definition: fltsupport.c:63
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:221
DWORD KmtFltReplyMessage(_In_ HANDLE hPort, _In_reads_bytes_(ReplyBufferSize) PFILTER_REPLY_HEADER ReplyBuffer, _In_ DWORD ReplyBufferSize)
Definition: filter.c:276
DWORD KmtFltDisconnect(_In_ HANDLE hPort)
Definition: filter.c:151
DWORD KmtFltLoad(_In_z_ PCWSTR ServiceName)
Definition: filter.c:30
DWORD KmtFltSendMessage(_In_ HANDLE hPort, _In_reads_bytes_(dwInBufferSize) LPVOID InBuffer, _In_ DWORD InBufferSize, _Out_writes_bytes_to_opt_(dutBufferSize, *BytesReturned) LPVOID OutBuffer, _In_ DWORD OutBufferSize, _Out_opt_ LPDWORD BytesReturned)
Definition: filter.c:187
DWORD KmtFltGetMessageResult(_In_ HANDLE hPort, _In_ LPOVERLAPPED Overlapped, _Out_ LPDWORD BytesTransferred)
Definition: filter.c:306
DWORD KmtFltGetMessage(_In_ HANDLE hPort, _Out_writes_bytes_(MessageBufferSize) PFILTER_MESSAGE_HEADER MessageBuffer, _In_ DWORD MessageBufferSize, _In_opt_ LPOVERLAPPED Overlapped)
Definition: filter.c:241
#define SERVICE_ACCESS
Definition: filter.c:15
DWORD KmtFltUnload(_In_z_ PCWSTR ServiceName)
Definition: filter.c:336
DWORD KmtFltConnect(_In_z_ PCWSTR ServiceName, _Out_ HANDLE *hPort)
Definition: filter.c:119
static SC_HANDLE ScmHandle
Definition: service.c:30
#define _Out_opt_
Definition: ms_sal.h:346
#define _In_reads_bytes_(size)
Definition: ms_sal.h:321
#define _Out_writes_bytes_(size)
Definition: ms_sal.h:350
#define _In_z_
Definition: ms_sal.h:313
#define _Out_
Definition: ms_sal.h:345
#define _Out_writes_bytes_to_opt_(size, count)
Definition: ms_sal.h:361
#define _In_
Definition: ms_sal.h:308
#define _In_opt_
Definition: ms_sal.h:309
_In_ UCHAR _In_ ULONG _Out_ PUCHAR _Outptr_result_bytebuffer_ OutBufferLength PVOID * OutBuffer
Definition: scsi.h:4071
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
const uint16_t * PCWSTR
Definition: typedefs.h:57
uint32_t * LPDWORD
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_ ULONG _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesReturned
Definition: wdfiotarget.h:1052
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET _In_opt_ PWDF_MEMORY_DESCRIPTOR _Out_opt_ PULONG BytesTransferred
Definition: wdfusb.h:1342
_In_ ULONG OutBufferSize
Definition: wdfwmi.h:87
_In_ ULONG InBufferSize
Definition: wdfwmi.h:106
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_SERVICE_ALREADY_RUNNING
Definition: winerror.h:607
#define ERROR_SERVICE_EXISTS
Definition: winerror.h:624
#define SCODE_CODE(sc)
Definition: winerror.h:77
#define OpenService
Definition: winsvc.h:576