ReactOS 0.4.15-dev-5666-gc548b97
cnotify.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for cnotify.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID WINAPI BasepIoCompletion (IN PVOID ApcContext, IN PIO_STATUS_BLOCK IoStatusBlock, IN DWORD Reserved)
 
VOID WINAPI BasepIoCompletionSimple (IN PVOID ApcContext, IN PIO_STATUS_BLOCK IoStatusBlock, IN DWORD Reserved)
 
BOOL WINAPI FindCloseChangeNotification (IN HANDLE hChangeHandle)
 
HANDLE WINAPI FindFirstChangeNotificationA (IN LPCSTR lpPathName, IN BOOL bWatchSubtree, IN DWORD dwNotifyFilter)
 
HANDLE WINAPI FindFirstChangeNotificationW (IN LPCWSTR lpPathName, IN BOOL bWatchSubtree, IN DWORD dwNotifyFilter)
 
BOOL WINAPI FindNextChangeNotification (IN HANDLE hChangeHandle)
 
BOOL WINAPI ReadDirectoryChangesW (IN HANDLE hDirectory, IN LPVOID lpBuffer OPTIONAL, IN DWORD nBufferLength, IN BOOL bWatchSubtree, IN DWORD dwNotifyFilter, OUT LPDWORD lpBytesReturned, IN LPOVERLAPPED lpOverlapped OPTIONAL, IN LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
 

Variables

CHAR staticchangebuff [sizeof(FILE_NOTIFY_INFORMATION)+16]
 
IO_STATUS_BLOCK staticIoStatusBlock
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file cnotify.c.

Function Documentation

◆ BasepIoCompletion()

VOID WINAPI BasepIoCompletion ( IN PVOID  ApcContext,
IN PIO_STATUS_BLOCK  IoStatusBlock,
IN DWORD  Reserved 
)

Definition at line 26 of file cnotify.c.

29{
30 PBASEP_ACTCTX_BLOCK ActivationBlock = ApcContext;
32 DWORD BytesTransfered, Result;
33 RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME ActCtx;
34 PVOID ActivationContext = NULL;
35
36 /* Setup the activation frame */
37 RtlZeroMemory(&ActCtx, sizeof(ActCtx));
38 ActCtx.Size = sizeof(ActCtx);
40
41 /* Check if the routine returned an error */
43 {
44 /* Convert the error code and don't copy anything */
46 BytesTransfered = 0;
47 }
48 else
49 {
50 /* Set success code and copy the bytes transferred */
52 BytesTransfered = IoStatusBlock->Information;
53 }
54
55 /* Read context and routine out from the activation block */
56 ActivationContext = ActivationBlock->ActivationContext;
57 CompletionRoutine = ActivationBlock->CompletionRoutine;
58
59 /* Check if the block should be freed */
60 if (!(ActivationBlock->Flags & 1))
61 {
62 /* Free it */
64 }
65
66 /* Activate the context, call the routine, and then deactivate the context */
70}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
VOID NTAPI BasepFreeActivationContextActivationBlock(IN PBASEP_ACTCTX_BLOCK ActivationBlock)
Definition: actctx.c:26
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
_In_ PCWSTR _Out_ PVOID * ActCtx
Definition: ldrtypes.h:247
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:727
#define RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER
Definition: rtltypes.h:101
PRTL_ACTIVATION_CONTEXT_STACK_FRAME FASTCALL RtlActivateActivationContextUnsafeFast(IN PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED Frame, IN PVOID Context)
Definition: actctx.c:5934
PRTL_ACTIVATION_CONTEXT_STACK_FRAME FASTCALL RtlDeactivateActivationContextUnsafeFast(IN PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED Frame)
Definition: actctx.c:6011
PVOID ActivationContext
Definition: kernel32.h:102
LPOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine
Definition: kernel32.h:104
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define NT_ERROR(Status)
Definition: umtypes.h:106
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE CompletionRoutine
Definition: wdfrequest.h:895
void(CALLBACK * LPOVERLAPPED_COMPLETION_ROUTINE)(DWORD, DWORD, LPOVERLAPPED)
Definition: winbase.h:1439
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426

Referenced by ReadDirectoryChangesW().

◆ BasepIoCompletionSimple()

VOID WINAPI BasepIoCompletionSimple ( IN PVOID  ApcContext,
IN PIO_STATUS_BLOCK  IoStatusBlock,
IN DWORD  Reserved 
)

Definition at line 74 of file cnotify.c.

77{
79 DWORD Result, BytesTransfered;
80
81 /* Check if the routine returned an error */
83 {
84 /* Convert the error code and don't copy anything */
86 BytesTransfered = 0;
87 }
88 else
89 {
90 /* Set success code and copy the bytes transferred */
92 BytesTransfered = IoStatusBlock->Information;
93 }
94
95 /* Call the callback routine */
97}

Referenced by ReadDirectoryChangesW().

◆ FindCloseChangeNotification()

BOOL WINAPI FindCloseChangeNotification ( IN HANDLE  hChangeHandle)

Definition at line 106 of file cnotify.c.

107{
108 /* Just close the handle */
109 return CloseHandle(hChangeHandle);
110}
#define CloseHandle
Definition: compat.h:739

Referenced by NotificationThread(), test_ffcn(), test_ffcn_directory_overlap(), and test_FindFirstChangeNotification().

◆ FindFirstChangeNotificationA()

HANDLE WINAPI FindFirstChangeNotificationA ( IN LPCSTR  lpPathName,
IN BOOL  bWatchSubtree,
IN DWORD  dwNotifyFilter 
)

Definition at line 117 of file cnotify.c.

120{
121 /* Call the W(ide) function */
123 lpPathName,
124 bWatchSubtree,
125 dwNotifyFilter);
126}
#define ConvertWin32AnsiChangeApiToUnicodeApi(obj, name,...)
Definition: base_x.h:76
#define FindFirstChangeNotification
Definition: winbase.h:3652

Referenced by StartNotificationThread(), test_ffcn_directory_overlap(), test_ffcnMultipleThreads(), and test_FindFirstChangeNotification().

◆ FindFirstChangeNotificationW()

HANDLE WINAPI FindFirstChangeNotificationW ( IN LPCWSTR  lpPathName,
IN BOOL  bWatchSubtree,
IN DWORD  dwNotifyFilter 
)

Definition at line 133 of file cnotify.c.

136{
138 UNICODE_STRING NtPathU;
140 HANDLE hDir;
141 RTL_RELATIVE_NAME_U RelativeName;
142 PWCHAR PathBuffer;
144
145 /* Convert to NT path and get the relative name too */
146 if (!RtlDosPathNameToNtPathName_U(lpPathName,
147 &NtPathU,
148 NULL,
149 &RelativeName))
150 {
151 /* Bail out if the path name makes no sense */
154 }
155
156 /* Save the path buffer in case we free it later */
157 PathBuffer = NtPathU.Buffer;
158
159 /* If we have a relative name... */
160 if (RelativeName.RelativeName.Length)
161 {
162 /* Do a relative open with only the relative path set */
163 NtPathU = RelativeName.RelativeName;
164 }
165 else
166 {
167 /* Do a full path open with no containing directory */
168 RelativeName.ContainingDirectory = NULL;
169 }
170
171 /* Now open the directory name that was passed in */
173 &NtPathU,
175 RelativeName.ContainingDirectory,
176 NULL);
177 Status = NtOpenFile(&hDir,
183
184 /* Release our buffer and relative name structure */
185 RtlReleaseRelativeName(&RelativeName);
186 RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
187
188 /* Check if the open failed */
189 if (!NT_SUCCESS(Status))
190 {
191 /* Bail out in that case */
194 }
195
196 /* Now setup the notification on the directory as requested */
198 NULL,
199 NULL,
200 NULL,
203 sizeof(staticchangebuff),
204 dwNotifyFilter,
205 (BOOLEAN)bWatchSubtree);
206 if (!NT_SUCCESS(Status))
207 {
208 /* We failed, close the handle and convert the error */
209 NtClose(hDir);
212 }
213
214 /* Return the directory handle on success, or invalid handle otherwise */
215 return hDir;
216}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
IO_STATUS_BLOCK staticIoStatusBlock
Definition: cnotify.c:20
CHAR staticchangebuff[sizeof(FILE_NOTIFY_INFORMATION)+16]
Definition: cnotify.c:19
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define FILE_SHARE_READ
Definition: compat.h:136
#define FILE_OPEN_FOR_BACKUP_INTENT
Definition: from_kernel.h:42
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSTATUS NTAPI NtNotifyChangeDirectoryFile(IN HANDLE FileHandle, IN HANDLE EventHandle OPTIONAL, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID Buffer, IN ULONG BufferSize, IN ULONG CompletionFilter, IN BOOLEAN WatchTree)
Definition: iofunc.c:1622
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
VOID NTAPI RtlReleaseRelativeName(_In_ PRTL_RELATIVE_NAME_U RelativeName)
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3952
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_LIST_DIRECTORY
Definition: nt_native.h:629
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
UNICODE_STRING RelativeName
Definition: rtltypes.h:1380
HANDLE ContainingDirectory
Definition: rtltypes.h:1381
uint16_t * PWCHAR
Definition: typedefs.h:56
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106

Referenced by test_ffcn().

◆ FindNextChangeNotification()

BOOL WINAPI FindNextChangeNotification ( IN HANDLE  hChangeHandle)

Definition at line 223 of file cnotify.c.

224{
226
227 /* Just call the native API directly, dealing with the non-optional parameters */
228 Status = NtNotifyChangeDirectoryFile(hChangeHandle,
229 NULL,
230 NULL,
231 NULL,
234 sizeof(staticchangebuff),
236 TRUE);
237 if (!NT_SUCCESS(Status))
238 {
239 /* Convert the error code and fail */
241 return FALSE;
242 }
243
244 /* All went well */
245 return TRUE;
246}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define FILE_NOTIFY_CHANGE_SECURITY

Referenced by NotificationThread(), test_ffcn(), test_FindFirstChangeNotification(), and WatchDirectory().

◆ ReadDirectoryChangesW()

BOOL WINAPI ReadDirectoryChangesW ( IN HANDLE  hDirectory,
IN LPVOID lpBuffer  OPTIONAL,
IN DWORD  nBufferLength,
IN BOOL  bWatchSubtree,
IN DWORD  dwNotifyFilter,
OUT LPDWORD  lpBytesReturned,
IN LPOVERLAPPED lpOverlapped  OPTIONAL,
IN LPOVERLAPPED_COMPLETION_ROUTINE  lpCompletionRoutine 
)

Definition at line 253 of file cnotify.c.

261{
262
267 PBASEP_ACTCTX_BLOCK ActivationContext = NULL;
268 BOOL Result = TRUE;
270
271 /* Is the caller doing this synchronously? */
272 if (!lpOverlapped)
273 {
274 /* Great, just pass in the parameters */
276 NULL,
277 NULL,
278 NULL,
280 lpBuffer,
282 dwNotifyFilter,
283 bWatchSubtree);
284 if (Status == STATUS_PENDING)
285 {
286 /* Wait for completion since we are synchronous */
287 Status = NtWaitForSingleObject(hDirectory, FALSE, NULL);
288 if (!NT_SUCCESS(Status))
289 {
290 /* The wait failed, bail out */
292 return FALSE;
293 }
294
295 /* Retrieve the final status code */
297 }
298
299 /* Did the operation succeed? */
300 if (NT_SUCCESS(Status))
301 {
302 /* Return the bytes transferd and success */
304 return Result;
305 }
306
307 /* Convert error code and return failure */
309 return FALSE;
310 }
311
312 /* Does the caller want an APC callback? */
313 if (lpCompletionRoutine)
314 {
315 /* Don't use an event in this case */
317
318 /* Allocate a Fusion/SxS activation context for the callback routine */
320 lpCompletionRoutine,
322 &ActivationContext);
323 if (!NT_SUCCESS(Status))
324 {
325 /* This failed, so abandon the call */
327 return FALSE;
328 }
329
330 /* Use the SxS context as the APC context */
331 ApcContext = ActivationContext;
332 if (ActivationContext)
333 {
334 /* And use a special stub routine that deals with activation */
336 }
337 else
338 {
339 /* If there was no context, however, use the simple stub routine */
340 ApcContext = lpCompletionRoutine;
342 }
343 }
344 else
345 {
346 /* Use the even with no APC routine */
347 EventHandle = lpOverlapped->hEvent;
348 ApcRoutine = 0;
349
350 /* LPOVERLAPPED should be ignored if event is ORed with 1 */
352 }
353
354 /* Set the initial status to pending and call the native API */
355 lpOverlapped->Internal = STATUS_PENDING;
361 lpBuffer,
363 dwNotifyFilter,
364 (BOOLEAN)bWatchSubtree);
365 if (NT_ERROR(Status))
366 {
367 /* Normally we cleanup the context in the completion routine, but we failed */
368 if (ActivationContext) BasepFreeActivationContextActivationBlock(ActivationContext);
369
370 /* Convert the error and fail */
372 return FALSE;
373 }
374
375 /* Return success */
376 return Result;
377}
VOID WINAPI BasepIoCompletion(IN PVOID ApcContext, IN PIO_STATUS_BLOCK IoStatusBlock, IN DWORD Reserved)
Definition: cnotify.c:26
VOID WINAPI BasepIoCompletionSimple(IN PVOID ApcContext, IN PIO_STATUS_BLOCK IoStatusBlock, IN DWORD Reserved)
Definition: cnotify.c:74
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
NTSTATUS NTAPI BasepAllocateActivationContextActivationBlock(IN DWORD Flags, IN PVOID CompletionRoutine, IN PVOID CompletionContext, OUT PBASEP_ACTCTX_BLOCK *ActivationBlock)
Definition: actctx.c:45
#define ULONG_PTR
Definition: config.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:93
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:726
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)
VOID(* PIO_APC_ROUTINE)(IN PVOID ApcContext, IN PIO_STATUS_BLOCK IoStatusBlock, IN ULONG Reserved)
Definition: nt_native.h:877
#define STATUS_PENDING
Definition: ntstatus.h:82
_In_ LPCSTR _In_opt_ LPCSTR _In_ DWORD nBufferLength
Definition: winbase.h:3060
_In_ DWORD _In_ DWORD _In_ DWORD _Out_ LPDWORD lpBytesReturned
Definition: winddi.h:1705
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:857

Referenced by CDirectoryWatcher::RestartWatching().

Variable Documentation

◆ staticchangebuff

CHAR staticchangebuff[sizeof(FILE_NOTIFY_INFORMATION)+16]

Definition at line 19 of file cnotify.c.

Referenced by FindFirstChangeNotificationW(), and FindNextChangeNotification().

◆ staticIoStatusBlock

IO_STATUS_BLOCK staticIoStatusBlock

Definition at line 20 of file cnotify.c.

Referenced by FindFirstChangeNotificationW(), and FindNextChangeNotification().