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>
15 #define SERVICE_ACCESS (SERVICE_START | SERVICE_STOP | DELETE)
22 * Start the specified filter driver by name
25 * The name of the filter to start
27 * @return Win32 error code
31 _In_z_ PCWSTR ServiceName
)
34 DWORD Error
= ERROR_SUCCESS
;
38 hResult
= FilterLoad(ServiceName
);
39 Error
= SCODE_CODE(hResult
);
45 * @name KmtFltCreateAndStartService
47 * Create and load the specified filter driver and return a handle to it
50 * Name of the service to create
52 * File name of the driver, relative to the current directory
54 * Service display name
55 * @param ServiceHandle
56 * Pointer to a variable to receive the handle to the service
57 * @param RestartIfRunning
58 * TRUE to stop and restart the service if it is already running
60 * @return Win32 error code
63 KmtFltCreateAndStartService(
64 _In_z_ PCWSTR ServiceName
,
65 _In_z_ PCWSTR ServicePath
,
66 _In_z_ PCWSTR DisplayName OPTIONAL
,
67 _Out_ SC_HANDLE
*ServiceHandle
,
68 _In_ BOOLEAN RestartIfRunning
)
70 DWORD Error
= ERROR_SUCCESS
;
72 assert(ServiceHandle
);
74 Error
= KmtFltCreateService(ServiceName
, ServicePath
, DisplayName
, ServiceHandle
);
76 if (Error
== ERROR_SERVICE_EXISTS
)
77 *ServiceHandle
= OpenService(ScmHandle
, ServiceName
, SERVICE_ACCESS
);
79 if (Error
&& Error
!= ERROR_SERVICE_EXISTS
)
82 Error
= KmtFltLoad(ServiceName
);
84 if (Error
!= ERROR_SERVICE_ALREADY_RUNNING
)
87 Error
= ERROR_SUCCESS
;
89 if (!RestartIfRunning
)
92 Error
= KmtFltUnload(ServiceName
);
96 Error
= KmtFltLoad(ServiceName
);
107 * @name KmtFltConnect
109 * Create a comms connection to the specified filter
112 * Name of the filter to connect to
114 * Handle to the filter's comms port
116 * @return Win32 error code
120 _In_z_ PCWSTR ServiceName
,
129 hResult
= FilterConnectCommunicationPort(ServiceName
,
135 Error
= SCODE_CODE(hResult
);
141 * @name KmtFltDisconnect
143 * Disconenct from the comms port
146 * Handle to the filter's comms port
148 * @return Win32 error code
154 DWORD Error
= ERROR_SUCCESS
;
158 if (!CloseHandle(hPort
))
160 Error
= GetLastError();
167 * @name KmtFltSendMessage
169 * Sneds a message to a filter driver
172 * Handle to the filter's comms port
174 * Pointer to a buffer to send to the filter
176 * Size of the buffer pointed to by InBuffer
178 * Pointer to a buffer to receive reply data from the filter
180 * Size of the buffer pointed to by OutBuffer
182 * Number of bytes written in the reply buffer
184 * @return Win32 error code
189 _In_reads_bytes_(dwInBufferSize
) LPVOID InBuffer
,
190 _In_ DWORD InBufferSize
,
191 _Out_writes_bytes_to_opt_(dutBufferSize
, *BytesReturned
) LPVOID OutBuffer
,
192 _In_ DWORD OutBufferSize
,
193 _Out_opt_ LPDWORD BytesReturned
)
201 assert(InBufferSize
);
203 if (BytesReturned
) *BytesReturned
= 0;
205 hResult
= FilterSendMessage(hPort
,
212 Error
= SCODE_CODE(hResult
);
213 if (Error
== ERROR_SUCCESS
)
217 *BytesReturned
= BytesRet
;
225 * @name KmtFltGetMessage
227 * Gets a message from a filter driver
230 * Handle to the filter's comms port
232 * Pointer to a buffer to receive the data from the filter
234 * Size of the buffer pointed to by MessageBuffer
236 * Pointer to an overlapped structure
238 * @return Win32 error code
243 _Out_writes_bytes_(MessageBufferSize
) PFILTER_MESSAGE_HEADER MessageBuffer
,
244 _In_ DWORD MessageBufferSize
,
245 _In_opt_ LPOVERLAPPED Overlapped
)
251 assert(MessageBuffer
);
253 hResult
= FilterGetMessage(hPort
,
257 Error
= SCODE_CODE(hResult
);
262 * @name KmtFltReplyMessage
264 * Replies to a message from a filter driver
267 * Handle to the filter's comms port
269 * Pointer to a buffer to return to the filter
271 * Size of the buffer pointed to by ReplyBuffer
273 * @return Win32 error code
278 _In_reads_bytes_(ReplyBufferSize
) PFILTER_REPLY_HEADER ReplyBuffer
,
279 _In_ DWORD ReplyBufferSize
)
284 hResult
= FilterReplyMessage(hPort
,
287 Error
= SCODE_CODE(hResult
);
292 * @name KmtFltGetMessageResult
294 * Gets the overlapped result from the IO
297 * Handle to the filter's comms port
299 * Pointer to the overlapped structure usdd in the IO
301 * Number of bytes transferred in the IO
303 * @return Win32 error code
306 KmtFltGetMessageResult(
308 _In_ LPOVERLAPPED Overlapped
,
309 _Out_ LPDWORD BytesTransferred
)
312 DWORD Error
= ERROR_SUCCESS
;
314 *BytesTransferred
= 0;
316 Success
= GetOverlappedResult(hPort
, Overlapped
, BytesTransferred
, TRUE
);
319 Error
= GetLastError();
328 * Unload the specified filter driver
331 * The name of the filter to unload
333 * @return Win32 error code
337 _In_z_ PCWSTR ServiceName
)
340 DWORD Error
= ERROR_SUCCESS
;
344 hResult
= FilterUnload(ServiceName
);
345 Error
= SCODE_CODE(hResult
);