2 * Win32 file change notification functions
4 * Copyright 1998 Ulrich Weigand
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define WIN32_NO_STATUS
33 #include "kernel_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(file);
38 /****************************************************************************
39 * FindFirstChangeNotificationA (KERNEL32.@)
41 HANDLE WINAPI FindFirstChangeNotificationA( LPCSTR lpPathName, BOOL bWatchSubtree,
42 DWORD dwNotifyFilter )
46 if (!(pathW = FILE_name_AtoW( lpPathName, FALSE ))) return INVALID_HANDLE_VALUE;
47 return FindFirstChangeNotificationW( pathW, bWatchSubtree, dwNotifyFilter );
50 /****************************************************************************
51 * FindFirstChangeNotificationW (KERNEL32.@)
53 HANDLE WINAPI FindFirstChangeNotificationW( LPCWSTR lpPathName, BOOL bWatchSubtree,
56 UNICODE_STRING nt_name;
57 OBJECT_ATTRIBUTES attr;
60 HANDLE handle = INVALID_HANDLE_VALUE;
62 TRACE( "%s %d %lx\n", debugstr_w(lpPathName), bWatchSubtree, dwNotifyFilter );
64 if (!RtlDosPathNameToNtPathName_U( lpPathName, &nt_name, NULL, NULL ))
66 SetLastError( ERROR_PATH_NOT_FOUND );
70 attr.Length = sizeof(attr);
71 attr.RootDirectory = 0;
72 attr.Attributes = OBJ_CASE_INSENSITIVE;
73 attr.ObjectName = &nt_name;
74 attr.SecurityDescriptor = NULL;
75 attr.SecurityQualityOfService = NULL;
77 status = NtOpenFile( &handle, SYNCHRONIZE, &attr, &io,
78 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
79 FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
80 RtlFreeUnicodeString( &nt_name );
82 if (status != STATUS_SUCCESS)
84 SetLastError( RtlNtStatusToDosError(status) );
85 return INVALID_HANDLE_VALUE;
88 status = NtNotifyChangeDirectoryFile( handle, NULL, NULL, NULL, &io,
89 NULL, 0, dwNotifyFilter, bWatchSubtree );
90 if (status != STATUS_PENDING)
93 SetLastError( RtlNtStatusToDosError(status) );
94 return INVALID_HANDLE_VALUE;
99 /****************************************************************************
100 * FindNextChangeNotification (KERNEL32.@)
102 BOOL WINAPI FindNextChangeNotification( HANDLE handle )
107 TRACE("%p\n",handle);
109 status = NtNotifyChangeDirectoryFile( handle, NULL, NULL, NULL, &io,
110 NULL, 0, FILE_NOTIFY_CHANGE_SIZE, 0 );
111 if (status != STATUS_PENDING)
113 SetLastError( RtlNtStatusToDosError(status) );
119 /****************************************************************************
120 * FindCloseChangeNotification (KERNEL32.@)
122 BOOL WINAPI FindCloseChangeNotification( HANDLE handle )
124 return CloseHandle( handle );
127 BOOL WINAPI ReadDirectoryChangesW( HANDLE handle, LPVOID buffer, DWORD len, BOOL subtree,
128 DWORD filter, LPDWORD returned, LPOVERLAPPED overlapped,
129 LPOVERLAPPED_COMPLETION_ROUTINE completion )
136 TRACE("%p %p %08lx %d %08lx %p %p %p\n", handle, buffer, len, subtree, filter,
137 returned, overlapped, completion );
140 event = overlapped->hEvent;
142 event = CreateEventW( NULL, 0, 0, NULL );
144 status = NtNotifyChangeDirectoryFile( handle, event, NULL, NULL,
145 &io, buffer, len, filter, subtree );
146 if (status != STATUS_PENDING)
148 SetLastError( RtlNtStatusToDosError(status) );
151 else if (!overlapped)
152 WaitForSingleObject( event, INFINITE );
155 CloseHandle( event );