9ef6fa99040c7c4e9eb80600de203936a955a1a3
[reactos.git] / reactos / lib / kernel32 / file / cnotify.c
1 /* $Id: cnotify.c,v 1.6 2003/06/07 16:16:39 chorns Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/file/find.c
6 * PURPOSE: Find functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
8 * UPDATE HISTORY:
9 * Created 01/11/98
10 */
11
12 #include <k32.h>
13
14 #define NDEBUG
15 #include <kernel32/kernel32.h>
16
17 WINBOOL STDCALL
18 FindCloseChangeNotification (HANDLE hChangeHandle)
19 {
20 NtClose(hChangeHandle);
21 return TRUE;
22 }
23
24
25 HANDLE
26 STDCALL
27 FindFirstChangeNotificationA (
28 LPCSTR lpPathName,
29 WINBOOL bWatchSubtree,
30 DWORD dwNotifyFilter
31 )
32 {
33 UNICODE_STRING PathNameU;
34 ANSI_STRING PathName;
35 HANDLE hNotify;
36
37 RtlInitAnsiString (&PathName,
38 (LPSTR)lpPathName);
39
40 /* convert ansi (or oem) string to unicode */
41 if (bIsFileApiAnsi)
42 {
43 RtlAnsiStringToUnicodeString (&PathNameU,
44 &PathName,
45 TRUE);
46 }
47 else
48 {
49 RtlOemStringToUnicodeString (&PathNameU,
50 &PathName,
51 TRUE);
52 }
53
54 hNotify = FindFirstChangeNotificationW (PathNameU.Buffer,
55 bWatchSubtree,
56 dwNotifyFilter);
57
58 RtlFreeUnicodeString(&PathNameU);
59
60 return hNotify;
61 }
62
63
64 HANDLE
65 STDCALL
66 FindFirstChangeNotificationW (
67 LPCWSTR lpPathName,
68 WINBOOL bWatchSubtree,
69 DWORD dwNotifyFilter
70 )
71 {
72 NTSTATUS Status;
73 UNICODE_STRING NtPathU;
74 IO_STATUS_BLOCK IoStatus;
75 OBJECT_ATTRIBUTES ObjectAttributes;
76 HANDLE hDir;
77
78 /*
79 RtlDosPathNameToNtPathName takes a fully qualified file name "C:\Projects\LoadLibrary\Debug\TestDll.dll"
80 and returns something like "\??\C:\Projects\LoadLibrary\Debug\TestDll.dll."
81 If the file name cannot be interpreted, then the routine returns STATUS_OBJECT_PATH_SYNTAX_BAD and
82 ends execution.
83 */
84
85 if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpPathName,
86 &NtPathU,
87 NULL,
88 NULL))
89 {
90 SetLastErrorByStatus(STATUS_OBJECT_PATH_SYNTAX_BAD);
91 return INVALID_HANDLE_VALUE;
92 }
93
94 InitializeObjectAttributes (&ObjectAttributes,
95 &NtPathU,
96 0,
97 NULL,
98 NULL);
99
100 Status = NtOpenFile (hDir,
101 SYNCHRONIZE|FILE_LIST_DIRECTORY,
102 &ObjectAttributes,
103 &IoStatus,
104 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
105 FILE_DIRECTORY_FILE);
106
107 if (!NT_SUCCESS(Status))
108 {
109 SetLastErrorByStatus(Status);
110 return INVALID_HANDLE_VALUE;
111 }
112
113 Status = NtNotifyChangeDirectoryFile(hDir,
114 NULL,
115 NULL,
116 NULL,
117 &IoStatus,
118 NULL,//Buffer,
119 0,//BufferLength,
120 dwNotifyFilter,
121 bWatchSubtree);
122 if (!NT_SUCCESS(Status))
123 {
124 SetLastErrorByStatus(Status);
125 return INVALID_HANDLE_VALUE;
126 }
127
128 return hDir;
129 }
130
131
132 WINBOOL
133 STDCALL
134 FindNextChangeNotification (
135 HANDLE hChangeHandle
136 )
137 {
138 IO_STATUS_BLOCK IoStatus;
139 NTSTATUS Status;
140
141 Status = NtNotifyChangeDirectoryFile(hChangeHandle,
142 NULL,
143 NULL,
144 NULL,
145 &IoStatus,
146 NULL,//Buffer,
147 0,//BufferLength,
148 FILE_NOTIFY_CHANGE_SECURITY,//meaningless for subsequent calls, but must contain a valid flag(s)
149 0//meaningless for subsequent calls
150 );
151 if (!NT_SUCCESS(Status))
152 {
153 SetLastErrorByStatus(Status);
154 return FALSE;
155 }
156
157 return TRUE;
158 }
159
160 /* EOF */