1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
/*
* Win32 file change notification functions
*
* Copyright 1998 Ulrich Weigand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "ntstatus.h"
#define WIN32_NO_STATUS
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "winternl.h"
#include "kernel_private.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(file);
/****************************************************************************
* FindFirstChangeNotificationA (KERNEL32.@)
*/
HANDLE WINAPI FindFirstChangeNotificationA( LPCSTR lpPathName, BOOL bWatchSubtree,
DWORD dwNotifyFilter )
{
WCHAR *pathW;
if (!(pathW = FILE_name_AtoW( lpPathName, FALSE ))) return INVALID_HANDLE_VALUE;
return FindFirstChangeNotificationW( pathW, bWatchSubtree, dwNotifyFilter );
}
/*
* NtNotifyChangeDirectoryFile may write back to the IO_STATUS_BLOCK
* asynchronously. We don't care about the contents, but it can't
* be placed on the stack since it will go out of scope when we return.
*/
static IO_STATUS_BLOCK FindFirstChange_iosb;
/****************************************************************************
* FindFirstChangeNotificationW (KERNEL32.@)
*/
HANDLE WINAPI FindFirstChangeNotificationW( LPCWSTR lpPathName, BOOL bWatchSubtree,
DWORD dwNotifyFilter)
{
UNICODE_STRING nt_name;
OBJECT_ATTRIBUTES attr;
NTSTATUS status;
HANDLE handle = INVALID_HANDLE_VALUE;
TRACE( "%s %d %x\n", debugstr_w(lpPathName), bWatchSubtree, dwNotifyFilter );
if (!RtlDosPathNameToNtPathName_U( lpPathName, &nt_name, NULL, NULL ))
{
SetLastError( ERROR_PATH_NOT_FOUND );
return handle;
}
attr.Length = sizeof(attr);
attr.RootDirectory = 0;
attr.Attributes = OBJ_CASE_INSENSITIVE;
attr.ObjectName = &nt_name;
attr.SecurityDescriptor = NULL;
attr.SecurityQualityOfService = NULL;
status = NtOpenFile( &handle, FILE_LIST_DIRECTORY | SYNCHRONIZE,
&attr, &FindFirstChange_iosb,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
RtlFreeUnicodeString( &nt_name );
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return INVALID_HANDLE_VALUE;
}
status = NtNotifyChangeDirectoryFile( handle, NULL, NULL, NULL,
&FindFirstChange_iosb,
NULL, 0, dwNotifyFilter, bWatchSubtree );
if (status != STATUS_PENDING)
{
NtClose( handle );
SetLastError( RtlNtStatusToDosError(status) );
return INVALID_HANDLE_VALUE;
}
return handle;
}
/****************************************************************************
* FindNextChangeNotification (KERNEL32.@)
*/
BOOL WINAPI FindNextChangeNotification( HANDLE handle )
{
NTSTATUS status;
TRACE("%p\n",handle);
status = NtNotifyChangeDirectoryFile( handle, NULL, NULL, NULL,
&FindFirstChange_iosb,
NULL, 0, FILE_NOTIFY_CHANGE_SIZE, 0 );
if (status != STATUS_PENDING)
{
SetLastError( RtlNtStatusToDosError(status) );
return FALSE;
}
return TRUE;
}
/****************************************************************************
* FindCloseChangeNotification (KERNEL32.@)
*/
BOOL WINAPI FindCloseChangeNotification( HANDLE handle )
{
return CloseHandle( handle );
}
/****************************************************************************
* ReadDirectoryChangesW (KERNEL32.@)
*
* NOTES
*
* The filter is remember from the first run and ignored on successive runs.
*
* If there's no output buffer on the first run, it's ignored successive runs
* and STATUS_NOTIFY_ENUM_DIRECTORY is returned with an empty buffer.
*
* If a NULL overlapped->hEvent is passed, the directory handle is used
* for signalling.
*/
BOOL WINAPI ReadDirectoryChangesW( HANDLE handle, LPVOID buffer, DWORD len, BOOL subtree,
DWORD filter, LPDWORD returned, LPOVERLAPPED overlapped,
LPOVERLAPPED_COMPLETION_ROUTINE completion )
{
OVERLAPPED ov, *pov;
IO_STATUS_BLOCK *ios;
NTSTATUS status;
BOOL ret = TRUE;
LPVOID cvalue = NULL;
TRACE("%p %p %08x %d %08x %p %p %p\n", handle, buffer, len, subtree, filter,
returned, overlapped, completion );
if (!overlapped)
{
memset( &ov, 0, sizeof ov );
ov.hEvent = CreateEventW( NULL, 0, 0, NULL );
pov = &ov;
}
else
{
pov = overlapped;
if (!completion && ((ULONG_PTR)overlapped->hEvent & 1) == 0) cvalue = overlapped;
}
ios = (PIO_STATUS_BLOCK) pov;
ios->u.Status = STATUS_PENDING;
status = NtNotifyChangeDirectoryFile( handle, pov->hEvent, NULL, cvalue,
ios, buffer, len, filter, subtree );
if (status == STATUS_PENDING)
{
if (overlapped)
return TRUE;
WaitForSingleObjectEx( ov.hEvent, INFINITE, TRUE );
CloseHandle( ov.hEvent );
if (returned)
*returned = ios->Information;
status = ios->u.Status;
}
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
ret = FALSE;
}
return ret;
}
|