Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Server-side change notification management |
| 3 | * |
| 4 | * Copyright (C) 1998 Alexandre Julliard |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 5 | * Copyright (C) 2006 Mike McCormack |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 22 | #include "config.h" |
| 23 | #include "wine/port.h" |
| 24 | |
Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 25 | #include <assert.h> |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 26 | #include <fcntl.h> |
Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 29 | #include <signal.h> |
Hans Leidekker | ff49652 | 2004-02-05 01:45:58 +0000 | [diff] [blame] | 30 | #include <sys/stat.h> |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 31 | #include <sys/types.h> |
| 32 | #include <limits.h> |
| 33 | #include <dirent.h> |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 34 | #include <errno.h> |
| 35 | #ifdef HAVE_SYS_ERRNO_H |
| 36 | #include <sys/errno.h> |
| 37 | #endif |
Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 38 | |
Ge van Geldorp | 1a1583a | 2005-11-28 17:32:54 +0100 | [diff] [blame] | 39 | #include "ntstatus.h" |
| 40 | #define WIN32_NO_STATUS |
Alexandre Julliard | 435e2e6 | 2002-12-10 22:56:43 +0000 | [diff] [blame] | 41 | #include "windef.h" |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 42 | |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 43 | #include "file.h" |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 44 | #include "handle.h" |
| 45 | #include "thread.h" |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 46 | #include "request.h" |
Ge van Geldorp | 1a1583a | 2005-11-28 17:32:54 +0100 | [diff] [blame] | 47 | #include "winternl.h" |
Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 48 | |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 49 | /* dnotify support */ |
| 50 | |
Huw Davies | bdb63ec | 2004-02-10 20:08:24 +0000 | [diff] [blame] | 51 | #ifdef linux |
| 52 | #ifndef F_NOTIFY |
| 53 | #define F_NOTIFY 1026 |
| 54 | #define DN_ACCESS 0x00000001 /* File accessed */ |
| 55 | #define DN_MODIFY 0x00000002 /* File modified */ |
| 56 | #define DN_CREATE 0x00000004 /* File created */ |
| 57 | #define DN_DELETE 0x00000008 /* File removed */ |
| 58 | #define DN_RENAME 0x00000010 /* File renamed */ |
Francois Gouget | 8a18e0e | 2008-04-07 13:01:02 +0200 | [diff] [blame] | 59 | #define DN_ATTRIB 0x00000020 /* File changed attributes */ |
Huw Davies | bdb63ec | 2004-02-10 20:08:24 +0000 | [diff] [blame] | 60 | #define DN_MULTISHOT 0x80000000 /* Don't remove notifier */ |
| 61 | #endif |
| 62 | #endif |
| 63 | |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 64 | /* inotify support */ |
| 65 | |
| 66 | #if defined(__linux__) && defined(__i386__) |
| 67 | |
| 68 | #define SYS_inotify_init 291 |
| 69 | #define SYS_inotify_add_watch 292 |
| 70 | #define SYS_inotify_rm_watch 293 |
| 71 | |
| 72 | struct inotify_event { |
| 73 | int wd; |
| 74 | unsigned int mask; |
| 75 | unsigned int cookie; |
| 76 | unsigned int len; |
| 77 | char name[1]; |
| 78 | }; |
| 79 | |
| 80 | #define IN_ACCESS 0x00000001 |
| 81 | #define IN_MODIFY 0x00000002 |
| 82 | #define IN_ATTRIB 0x00000004 |
| 83 | #define IN_CLOSE_WRITE 0x00000008 |
| 84 | #define IN_CLOSE_NOWRITE 0x00000010 |
| 85 | #define IN_OPEN 0x00000020 |
| 86 | #define IN_MOVED_FROM 0x00000040 |
| 87 | #define IN_MOVED_TO 0x00000080 |
| 88 | #define IN_CREATE 0x00000100 |
| 89 | #define IN_DELETE 0x00000200 |
| 90 | #define IN_DELETE_SELF 0x00000400 |
| 91 | |
| 92 | static inline int inotify_init( void ) |
| 93 | { |
| 94 | int ret; |
| 95 | __asm__ __volatile__( "int $0x80" |
| 96 | : "=a" (ret) |
| 97 | : "0" (SYS_inotify_init)); |
| 98 | if (ret<0) { errno = -ret; ret = -1; } |
| 99 | return ret; |
| 100 | } |
| 101 | |
| 102 | static inline int inotify_add_watch( int fd, const char *name, unsigned int mask ) |
| 103 | { |
| 104 | int ret; |
| 105 | __asm__ __volatile__( "pushl %%ebx;\n\t" |
| 106 | "movl %2,%%ebx;\n\t" |
| 107 | "int $0x80;\n\t" |
| 108 | "popl %%ebx" |
| 109 | : "=a" (ret) : "0" (SYS_inotify_add_watch), |
| 110 | "r" (fd), "c" (name), "d" (mask) ); |
| 111 | if (ret<0) { errno = -ret; ret = -1; } |
| 112 | return ret; |
| 113 | } |
| 114 | |
| 115 | static inline int inotify_remove_watch( int fd, int wd ) |
| 116 | { |
| 117 | int ret; |
| 118 | __asm__ __volatile__( "pushl %%ebx;\n\t" |
| 119 | "movl %2,%%ebx;\n\t" |
| 120 | "int $0x80;\n\t" |
| 121 | "popl %%ebx" |
| 122 | : "=a" (ret) : "0" (SYS_inotify_rm_watch), |
| 123 | "r" (fd), "c" (wd) ); |
| 124 | if (ret<0) { errno = -ret; ret = -1; } |
| 125 | return ret; |
| 126 | } |
| 127 | |
Alexandre Julliard | cf9ced5 | 2006-02-05 12:19:56 +0100 | [diff] [blame] | 128 | #define USE_INOTIFY |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 129 | |
| 130 | #endif |
| 131 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 132 | struct inode; |
| 133 | |
| 134 | static void free_inode( struct inode *inode ); |
| 135 | |
| 136 | static struct fd *inotify_fd; |
| 137 | |
Mike McCormack | 0193211 | 2006-02-06 11:58:55 +0100 | [diff] [blame] | 138 | struct change_record { |
| 139 | struct list entry; |
| 140 | int action; |
| 141 | int len; |
| 142 | char name[1]; |
| 143 | }; |
| 144 | |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 145 | struct dir |
Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 146 | { |
| 147 | struct object obj; /* object header */ |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 148 | struct fd *fd; /* file descriptor to the directory */ |
| 149 | struct list entry; /* entry in global change notifications list */ |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 150 | unsigned int filter; /* notification filter */ |
Alexandre Julliard | 43c6396 | 2005-09-26 13:51:58 +0000 | [diff] [blame] | 151 | int notified; /* SIGIO counter */ |
Mike McCormack | 0790f95 | 2006-02-07 16:50:36 +0100 | [diff] [blame] | 152 | int want_data; /* return change data */ |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 153 | int subtree; /* do we want to watch subdirectories? */ |
Mike McCormack | 0193211 | 2006-02-06 11:58:55 +0100 | [diff] [blame] | 154 | struct list change_records; /* data for the change */ |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 155 | struct list in_entry; /* entry in the inode dirs list */ |
| 156 | struct inode *inode; /* inode of the associated directory */ |
Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 157 | }; |
| 158 | |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 159 | static struct fd *dir_get_fd( struct object *obj ); |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 160 | static void dir_dump( struct object *obj, int verbose ); |
| 161 | static void dir_destroy( struct object *obj ); |
Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 162 | |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 163 | static const struct object_ops dir_ops = |
Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 164 | { |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 165 | sizeof(struct dir), /* size */ |
| 166 | dir_dump, /* dump */ |
Alexandre Julliard | 8382eb0 | 2007-12-05 18:16:42 +0100 | [diff] [blame] | 167 | no_get_type, /* get_type */ |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 168 | add_queue, /* add_queue */ |
| 169 | remove_queue, /* remove_queue */ |
Alexandre Julliard | a867553 | 2007-04-04 19:54:33 +0200 | [diff] [blame] | 170 | default_fd_signaled, /* signaled */ |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 171 | no_satisfied, /* satisfied */ |
Mike McCormack | f92fff6 | 2005-04-24 17:35:52 +0000 | [diff] [blame] | 172 | no_signal, /* signal */ |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 173 | dir_get_fd, /* get_fd */ |
Alexandre Julliard | 24001e8 | 2007-10-02 14:20:15 +0200 | [diff] [blame] | 174 | default_fd_map_access, /* map_access */ |
Rob Shearman | c1707d8 | 2007-10-03 13:10:37 +0100 | [diff] [blame] | 175 | default_get_sd, /* get_sd */ |
| 176 | default_set_sd, /* set_sd */ |
Vitaliy Margolen | baffcb9 | 2005-11-22 14:55:42 +0000 | [diff] [blame] | 177 | no_lookup_name, /* lookup_name */ |
Alexandre Julliard | 7e71c1d | 2007-03-22 11:44:29 +0100 | [diff] [blame] | 178 | no_open_file, /* open_file */ |
Alexandre Julliard | 715d78e | 2006-11-02 20:52:22 +0100 | [diff] [blame] | 179 | fd_close_handle, /* close_handle */ |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 180 | dir_destroy /* destroy */ |
| 181 | }; |
| 182 | |
| 183 | static int dir_get_poll_events( struct fd *fd ); |
Alexandre Julliard | 7a9363a | 2007-04-10 22:26:23 +0200 | [diff] [blame] | 184 | static enum server_fd_type dir_get_fd_type( struct fd *fd ); |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 185 | |
| 186 | static const struct fd_ops dir_fd_ops = |
| 187 | { |
Alexandre Julliard | 72bff2e | 2007-04-10 17:07:27 +0200 | [diff] [blame] | 188 | dir_get_poll_events, /* get_poll_events */ |
| 189 | default_poll_event, /* poll_event */ |
| 190 | no_flush, /* flush */ |
Alexandre Julliard | 7a9363a | 2007-04-10 22:26:23 +0200 | [diff] [blame] | 191 | dir_get_fd_type, /* get_fd_type */ |
Alexandre Julliard | 6357143 | 2007-04-16 14:45:03 +0200 | [diff] [blame] | 192 | default_fd_ioctl, /* ioctl */ |
Alexandre Julliard | 72bff2e | 2007-04-10 17:07:27 +0200 | [diff] [blame] | 193 | default_fd_queue_async, /* queue_async */ |
| 194 | default_fd_reselect_async, /* reselect_async */ |
| 195 | default_fd_cancel_async /* cancel_async */ |
Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 196 | }; |
| 197 | |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 198 | static struct list change_list = LIST_INIT(change_list); |
Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 199 | |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 200 | static void dnotify_adjust_changes( struct dir *dir ) |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 201 | { |
Alexandre Julliard | e8a339c | 2004-03-01 21:32:02 +0000 | [diff] [blame] | 202 | #if defined(F_SETSIG) && defined(F_NOTIFY) |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 203 | int fd = get_unix_fd( dir->fd ); |
| 204 | unsigned int filter = dir->filter; |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 205 | unsigned int val; |
| 206 | if ( 0 > fcntl( fd, F_SETSIG, SIGIO) ) |
| 207 | return; |
| 208 | |
| 209 | val = DN_MULTISHOT; |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 210 | if (filter & FILE_NOTIFY_CHANGE_FILE_NAME) |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 211 | val |= DN_RENAME | DN_DELETE | DN_CREATE; |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 212 | if (filter & FILE_NOTIFY_CHANGE_DIR_NAME) |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 213 | val |= DN_RENAME | DN_DELETE | DN_CREATE; |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 214 | if (filter & FILE_NOTIFY_CHANGE_ATTRIBUTES) |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 215 | val |= DN_ATTRIB; |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 216 | if (filter & FILE_NOTIFY_CHANGE_SIZE) |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 217 | val |= DN_MODIFY; |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 218 | if (filter & FILE_NOTIFY_CHANGE_LAST_WRITE) |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 219 | val |= DN_MODIFY; |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 220 | if (filter & FILE_NOTIFY_CHANGE_LAST_ACCESS) |
Hans Leidekker | ff49652 | 2004-02-05 01:45:58 +0000 | [diff] [blame] | 221 | val |= DN_ACCESS; |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 222 | if (filter & FILE_NOTIFY_CHANGE_CREATION) |
Hans Leidekker | ff49652 | 2004-02-05 01:45:58 +0000 | [diff] [blame] | 223 | val |= DN_CREATE; |
Robert Shearman | 3795709 | 2005-06-10 19:54:46 +0000 | [diff] [blame] | 224 | if (filter & FILE_NOTIFY_CHANGE_SECURITY) |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 225 | val |= DN_ATTRIB; |
| 226 | fcntl( fd, F_NOTIFY, val ); |
| 227 | #endif |
| 228 | } |
| 229 | |
| 230 | /* insert change in the global list */ |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 231 | static inline void insert_change( struct dir *dir ) |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 232 | { |
| 233 | sigset_t sigset; |
| 234 | |
| 235 | sigemptyset( &sigset ); |
| 236 | sigaddset( &sigset, SIGIO ); |
| 237 | sigprocmask( SIG_BLOCK, &sigset, NULL ); |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 238 | list_add_head( &change_list, &dir->entry ); |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 239 | sigprocmask( SIG_UNBLOCK, &sigset, NULL ); |
| 240 | } |
| 241 | |
| 242 | /* remove change from the global list */ |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 243 | static inline void remove_change( struct dir *dir ) |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 244 | { |
| 245 | sigset_t sigset; |
| 246 | |
| 247 | sigemptyset( &sigset ); |
| 248 | sigaddset( &sigset, SIGIO ); |
| 249 | sigprocmask( SIG_BLOCK, &sigset, NULL ); |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 250 | list_remove( &dir->entry ); |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 251 | sigprocmask( SIG_UNBLOCK, &sigset, NULL ); |
| 252 | } |
| 253 | |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 254 | static void dir_dump( struct object *obj, int verbose ) |
Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 255 | { |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 256 | struct dir *dir = (struct dir *)obj; |
| 257 | assert( obj->ops == &dir_ops ); |
Alexandre Julliard | a867553 | 2007-04-04 19:54:33 +0200 | [diff] [blame] | 258 | fprintf( stderr, "Dirfile fd=%p filter=%08x\n", dir->fd, dir->filter ); |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /* enter here directly from SIGIO signal handler */ |
| 262 | void do_change_notify( int unix_fd ) |
| 263 | { |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 264 | struct dir *dir; |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 265 | |
| 266 | /* FIXME: this is O(n) ... probably can be improved */ |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 267 | LIST_FOR_EACH_ENTRY( dir, &change_list, struct dir, entry ) |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 268 | { |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 269 | if (get_unix_fd( dir->fd ) != unix_fd) continue; |
| 270 | interlocked_xchg_add( &dir->notified, 1 ); |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 271 | break; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | /* SIGIO callback, called synchronously with the poll loop */ |
| 276 | void sigio_callback(void) |
| 277 | { |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 278 | struct dir *dir; |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 279 | |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 280 | LIST_FOR_EACH_ENTRY( dir, &change_list, struct dir, entry ) |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 281 | { |
Alexandre Julliard | a867553 | 2007-04-04 19:54:33 +0200 | [diff] [blame] | 282 | if (interlocked_xchg( &dir->notified, 0 )) |
| 283 | fd_async_wake_up( dir->fd, ASYNC_TYPE_WAIT, STATUS_NOTIFY_ENUM_DIR ); |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 284 | } |
Alexandre Julliard | 63cb0f8 | 1998-12-31 15:43:48 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 287 | static struct fd *dir_get_fd( struct object *obj ) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 288 | { |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 289 | struct dir *dir = (struct dir *)obj; |
| 290 | assert( obj->ops == &dir_ops ); |
| 291 | return (struct fd *)grab_object( dir->fd ); |
Alexandre Julliard | 3e588e3 | 2003-03-26 23:41:43 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Mike McCormack | 0193211 | 2006-02-06 11:58:55 +0100 | [diff] [blame] | 294 | static struct change_record *get_first_change_record( struct dir *dir ) |
| 295 | { |
| 296 | struct list *ptr = list_head( &dir->change_records ); |
| 297 | if (!ptr) return NULL; |
| 298 | list_remove( ptr ); |
| 299 | return LIST_ENTRY( ptr, struct change_record, entry ); |
| 300 | } |
| 301 | |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 302 | static void dir_destroy( struct object *obj ) |
| 303 | { |
Mike McCormack | 0193211 | 2006-02-06 11:58:55 +0100 | [diff] [blame] | 304 | struct change_record *record; |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 305 | struct dir *dir = (struct dir *)obj; |
| 306 | assert (obj->ops == &dir_ops); |
| 307 | |
| 308 | if (dir->filter) |
| 309 | remove_change( dir ); |
| 310 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 311 | if (dir->inode) |
| 312 | { |
| 313 | list_remove( &dir->in_entry ); |
| 314 | free_inode( dir->inode ); |
| 315 | } |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 316 | |
Mike McCormack | 0193211 | 2006-02-06 11:58:55 +0100 | [diff] [blame] | 317 | while ((record = get_first_change_record( dir ))) free( record ); |
| 318 | |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 319 | release_object( dir->fd ); |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 320 | |
| 321 | if (inotify_fd && list_empty( &change_list )) |
| 322 | { |
| 323 | release_object( inotify_fd ); |
| 324 | inotify_fd = NULL; |
| 325 | } |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static struct dir * |
| 329 | get_dir_obj( struct process *process, obj_handle_t handle, unsigned int access ) |
| 330 | { |
| 331 | return (struct dir *)get_handle_obj( process, handle, access, &dir_ops ); |
| 332 | } |
| 333 | |
| 334 | static int dir_get_poll_events( struct fd *fd ) |
| 335 | { |
| 336 | return 0; |
| 337 | } |
| 338 | |
Alexandre Julliard | 7a9363a | 2007-04-10 22:26:23 +0200 | [diff] [blame] | 339 | static enum server_fd_type dir_get_fd_type( struct fd *fd ) |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 340 | { |
Alexandre Julliard | 8930427 | 2006-11-20 14:14:04 +0100 | [diff] [blame] | 341 | return FD_TYPE_DIR; |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 342 | } |
| 343 | |
Alexandre Julliard | cf9ced5 | 2006-02-05 12:19:56 +0100 | [diff] [blame] | 344 | #ifdef USE_INOTIFY |
| 345 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 346 | #define HASH_SIZE 31 |
| 347 | |
| 348 | struct inode { |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 349 | struct list ch_entry; /* entry in the children list */ |
| 350 | struct list children; /* children of this inode */ |
| 351 | struct inode *parent; /* parent of this inode */ |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 352 | struct list dirs; /* directory handles watching this inode */ |
| 353 | struct list ino_entry; /* entry in the inode hash */ |
| 354 | struct list wd_entry; /* entry in the watch descriptor hash */ |
| 355 | dev_t dev; /* device number */ |
| 356 | ino_t ino; /* device's inode number */ |
| 357 | int wd; /* inotify's watch descriptor */ |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 358 | char *name; /* basename name of the inode */ |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 359 | }; |
| 360 | |
| 361 | struct list inode_hash[ HASH_SIZE ]; |
| 362 | struct list wd_hash[ HASH_SIZE ]; |
| 363 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 364 | static int inotify_add_dir( char *path, unsigned int filter ); |
| 365 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 366 | static struct inode *inode_from_wd( int wd ) |
| 367 | { |
| 368 | struct list *bucket = &wd_hash[ wd % HASH_SIZE ]; |
| 369 | struct inode *inode; |
| 370 | |
| 371 | LIST_FOR_EACH_ENTRY( inode, bucket, struct inode, wd_entry ) |
| 372 | if (inode->wd == wd) |
| 373 | return inode; |
| 374 | |
| 375 | return NULL; |
| 376 | } |
| 377 | |
| 378 | static inline struct list *get_hash_list( dev_t dev, ino_t ino ) |
| 379 | { |
| 380 | return &inode_hash[ (ino ^ dev) % HASH_SIZE ]; |
| 381 | } |
| 382 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 383 | static struct inode *find_inode( dev_t dev, ino_t ino ) |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 384 | { |
| 385 | struct list *bucket = get_hash_list( dev, ino ); |
| 386 | struct inode *inode; |
| 387 | |
| 388 | LIST_FOR_EACH_ENTRY( inode, bucket, struct inode, ino_entry ) |
| 389 | if (inode->ino == ino && inode->dev == dev) |
| 390 | return inode; |
| 391 | |
| 392 | return NULL; |
| 393 | } |
| 394 | |
| 395 | static struct inode *create_inode( dev_t dev, ino_t ino ) |
| 396 | { |
| 397 | struct inode *inode; |
| 398 | |
| 399 | inode = malloc( sizeof *inode ); |
| 400 | if (inode) |
| 401 | { |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 402 | list_init( &inode->children ); |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 403 | list_init( &inode->dirs ); |
| 404 | inode->ino = ino; |
| 405 | inode->dev = dev; |
| 406 | inode->wd = -1; |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 407 | inode->parent = NULL; |
| 408 | inode->name = NULL; |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 409 | list_add_tail( get_hash_list( dev, ino ), &inode->ino_entry ); |
| 410 | } |
| 411 | return inode; |
| 412 | } |
| 413 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 414 | static struct inode *get_inode( dev_t dev, ino_t ino ) |
| 415 | { |
| 416 | struct inode *inode; |
| 417 | |
| 418 | inode = find_inode( dev, ino ); |
| 419 | if (inode) |
| 420 | return inode; |
| 421 | return create_inode( dev, ino ); |
| 422 | } |
| 423 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 424 | static void inode_set_wd( struct inode *inode, int wd ) |
| 425 | { |
| 426 | if (inode->wd != -1) |
| 427 | list_remove( &inode->wd_entry ); |
| 428 | inode->wd = wd; |
| 429 | list_add_tail( &wd_hash[ wd % HASH_SIZE ], &inode->wd_entry ); |
| 430 | } |
| 431 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 432 | static void inode_set_name( struct inode *inode, const char *name ) |
| 433 | { |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 434 | free (inode->name); |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 435 | inode->name = name ? strdup( name ) : NULL; |
| 436 | } |
| 437 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 438 | static void free_inode( struct inode *inode ) |
| 439 | { |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 440 | int subtree = 0, watches = 0; |
Alexandre Julliard | 037afca | 2008-02-28 10:47:14 +0100 | [diff] [blame] | 441 | struct inode *tmp, *next; |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 442 | struct dir *dir; |
| 443 | |
| 444 | LIST_FOR_EACH_ENTRY( dir, &inode->dirs, struct dir, in_entry ) |
| 445 | { |
| 446 | subtree |= dir->subtree; |
| 447 | watches++; |
| 448 | } |
| 449 | |
| 450 | if (!subtree && !inode->parent) |
| 451 | { |
Mike McCormack | 309a9bf | 2006-02-22 23:11:17 +0900 | [diff] [blame] | 452 | LIST_FOR_EACH_ENTRY_SAFE( tmp, next, &inode->children, |
| 453 | struct inode, ch_entry ) |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 454 | { |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 455 | assert( tmp != inode ); |
| 456 | assert( tmp->parent == inode ); |
| 457 | free_inode( tmp ); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | if (watches) |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 462 | return; |
| 463 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 464 | if (inode->parent) |
| 465 | list_remove( &inode->ch_entry ); |
| 466 | |
Alexandre Julliard | 037afca | 2008-02-28 10:47:14 +0100 | [diff] [blame] | 467 | /* disconnect remaining children from the parent */ |
| 468 | LIST_FOR_EACH_ENTRY_SAFE( tmp, next, &inode->children, struct inode, ch_entry ) |
| 469 | { |
| 470 | list_remove( &tmp->ch_entry ); |
| 471 | tmp->parent = NULL; |
| 472 | } |
| 473 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 474 | if (inode->wd != -1) |
| 475 | { |
| 476 | inotify_remove_watch( get_unix_fd( inotify_fd ), inode->wd ); |
| 477 | list_remove( &inode->wd_entry ); |
| 478 | } |
| 479 | list_remove( &inode->ino_entry ); |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 480 | |
| 481 | free( inode->name ); |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 482 | free( inode ); |
| 483 | } |
| 484 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 485 | static struct inode *inode_add( struct inode *parent, |
| 486 | dev_t dev, ino_t ino, const char *name ) |
| 487 | { |
| 488 | struct inode *inode; |
| 489 | |
| 490 | inode = get_inode( dev, ino ); |
| 491 | if (!inode) |
| 492 | return NULL; |
| 493 | |
| 494 | if (!inode->parent) |
| 495 | { |
| 496 | list_add_tail( &parent->children, &inode->ch_entry ); |
| 497 | inode->parent = parent; |
| 498 | assert( inode != parent ); |
| 499 | } |
| 500 | inode_set_name( inode, name ); |
| 501 | |
| 502 | return inode; |
| 503 | } |
| 504 | |
| 505 | static struct inode *inode_from_name( struct inode *inode, const char *name ) |
| 506 | { |
| 507 | struct inode *i; |
| 508 | |
| 509 | LIST_FOR_EACH_ENTRY( i, &inode->children, struct inode, ch_entry ) |
| 510 | if (i->name && !strcmp( i->name, name )) |
| 511 | return i; |
| 512 | return NULL; |
| 513 | } |
| 514 | |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 515 | static int inotify_get_poll_events( struct fd *fd ); |
| 516 | static void inotify_poll_event( struct fd *fd, int event ); |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 517 | |
| 518 | static const struct fd_ops inotify_fd_ops = |
| 519 | { |
Alexandre Julliard | 72bff2e | 2007-04-10 17:07:27 +0200 | [diff] [blame] | 520 | inotify_get_poll_events, /* get_poll_events */ |
| 521 | inotify_poll_event, /* poll_event */ |
Alexandre Julliard | 3f05759 | 2007-04-12 20:21:53 +0200 | [diff] [blame] | 522 | NULL, /* flush */ |
| 523 | NULL, /* get_fd_type */ |
Alexandre Julliard | 6357143 | 2007-04-16 14:45:03 +0200 | [diff] [blame] | 524 | NULL, /* ioctl */ |
Alexandre Julliard | 3f05759 | 2007-04-12 20:21:53 +0200 | [diff] [blame] | 525 | NULL, /* queue_async */ |
| 526 | NULL, /* reselect_async */ |
| 527 | NULL, /* cancel_async */ |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 528 | }; |
| 529 | |
| 530 | static int inotify_get_poll_events( struct fd *fd ) |
| 531 | { |
| 532 | return POLLIN; |
| 533 | } |
| 534 | |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 535 | static void inotify_do_change_notify( struct dir *dir, unsigned int action, |
| 536 | const char *relpath ) |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 537 | { |
Mike McCormack | 0193211 | 2006-02-06 11:58:55 +0100 | [diff] [blame] | 538 | struct change_record *record; |
| 539 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 540 | assert( dir->obj.ops == &dir_ops ); |
| 541 | |
Mike McCormack | 0790f95 | 2006-02-07 16:50:36 +0100 | [diff] [blame] | 542 | if (dir->want_data) |
| 543 | { |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 544 | size_t len = strlen(relpath); |
Alexandre Julliard | e979832 | 2006-02-08 15:06:42 +0100 | [diff] [blame] | 545 | record = malloc( offsetof(struct change_record, name[len]) ); |
Mike McCormack | 0790f95 | 2006-02-07 16:50:36 +0100 | [diff] [blame] | 546 | if (!record) |
| 547 | return; |
Mike McCormack | 0193211 | 2006-02-06 11:58:55 +0100 | [diff] [blame] | 548 | |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 549 | record->action = action; |
| 550 | memcpy( record->name, relpath, len ); |
Alexandre Julliard | e979832 | 2006-02-08 15:06:42 +0100 | [diff] [blame] | 551 | record->len = len; |
Mike McCormack | 0193211 | 2006-02-06 11:58:55 +0100 | [diff] [blame] | 552 | |
Mike McCormack | 0790f95 | 2006-02-07 16:50:36 +0100 | [diff] [blame] | 553 | list_add_tail( &dir->change_records, &record->entry ); |
| 554 | } |
Mike McCormack | 0193211 | 2006-02-06 11:58:55 +0100 | [diff] [blame] | 555 | |
Alexandre Julliard | df09ac5 | 2007-04-02 20:09:29 +0200 | [diff] [blame] | 556 | fd_async_wake_up( dir->fd, ASYNC_TYPE_WAIT, STATUS_ALERTED ); |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 557 | } |
| 558 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 559 | static unsigned int filter_from_event( struct inotify_event *ie ) |
| 560 | { |
| 561 | unsigned int filter = 0; |
| 562 | |
| 563 | if (ie->mask & (IN_MOVED_FROM | IN_MOVED_TO | IN_DELETE | IN_CREATE)) |
| 564 | filter |= FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME; |
| 565 | if (ie->mask & IN_MODIFY) |
| 566 | filter |= FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE; |
| 567 | if (ie->mask & IN_ATTRIB) |
| 568 | filter |= FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SECURITY; |
| 569 | if (ie->mask & IN_ACCESS) |
| 570 | filter |= FILE_NOTIFY_CHANGE_LAST_ACCESS; |
| 571 | if (ie->mask & IN_CREATE) |
| 572 | filter |= FILE_NOTIFY_CHANGE_CREATION; |
| 573 | |
| 574 | return filter; |
| 575 | } |
| 576 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 577 | /* scan up the parent directories for watches */ |
| 578 | static unsigned int filter_from_inode( struct inode *inode, int is_parent ) |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 579 | { |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 580 | unsigned int filter = 0; |
| 581 | struct dir *dir; |
| 582 | |
| 583 | /* combine filters from parents watching subtrees */ |
| 584 | while (inode) |
| 585 | { |
| 586 | LIST_FOR_EACH_ENTRY( dir, &inode->dirs, struct dir, in_entry ) |
| 587 | if (dir->subtree || !is_parent) |
| 588 | filter |= dir->filter; |
| 589 | is_parent = 1; |
| 590 | inode = inode->parent; |
| 591 | } |
| 592 | |
| 593 | return filter; |
| 594 | } |
| 595 | |
| 596 | static char *inode_get_path( struct inode *inode, int sz ) |
| 597 | { |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 598 | struct list *head; |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 599 | char *path; |
| 600 | int len; |
| 601 | |
| 602 | if (!inode) |
| 603 | return NULL; |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 604 | |
| 605 | head = list_head( &inode->dirs ); |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 606 | if (head) |
| 607 | { |
| 608 | int unix_fd = get_unix_fd( LIST_ENTRY( head, struct dir, in_entry )->fd ); |
| 609 | path = malloc ( 32 + sz ); |
| 610 | if (path) |
| 611 | sprintf( path, "/proc/self/fd/%u/", unix_fd ); |
| 612 | return path; |
| 613 | } |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 614 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 615 | if (!inode->name) |
| 616 | return NULL; |
| 617 | |
| 618 | len = strlen( inode->name ); |
| 619 | path = inode_get_path( inode->parent, sz + len + 1 ); |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 620 | if (!path) |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 621 | return NULL; |
| 622 | |
| 623 | strcat( path, inode->name ); |
| 624 | strcat( path, "/" ); |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 625 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 626 | return path; |
| 627 | } |
| 628 | |
| 629 | static int inode_check_dir( struct inode *parent, const char *name ) |
| 630 | { |
| 631 | char *path; |
| 632 | unsigned int filter; |
| 633 | struct inode *inode; |
| 634 | struct stat st; |
| 635 | int wd = -1, r = -1; |
| 636 | |
| 637 | path = inode_get_path( parent, strlen(name) ); |
| 638 | if (!path) |
| 639 | return r; |
| 640 | |
| 641 | strcat( path, name ); |
| 642 | |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 643 | r = stat( path, &st ); |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 644 | if (r < 0) goto end; |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 645 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 646 | if (!S_ISDIR(st.st_mode)) |
| 647 | { |
| 648 | r = 0; |
| 649 | goto end; |
| 650 | } |
| 651 | |
| 652 | r = 1; |
| 653 | |
| 654 | filter = filter_from_inode( parent, 1 ); |
| 655 | if (!filter) |
| 656 | goto end; |
| 657 | |
| 658 | inode = inode_add( parent, st.st_dev, st.st_ino, name ); |
| 659 | if (!inode || inode->wd != -1) |
| 660 | goto end; |
| 661 | |
| 662 | wd = inotify_add_dir( path, filter ); |
| 663 | if (wd != -1) |
| 664 | inode_set_wd( inode, wd ); |
| 665 | else |
| 666 | free_inode( inode ); |
| 667 | |
| 668 | end: |
| 669 | free( path ); |
| 670 | return r; |
| 671 | } |
| 672 | |
| 673 | static int prepend( char **path, const char *segment ) |
| 674 | { |
| 675 | int extra; |
| 676 | char *p; |
| 677 | |
| 678 | extra = strlen( segment ) + 1; |
| 679 | if (*path) |
| 680 | { |
| 681 | int len = strlen( *path ) + 1; |
| 682 | p = realloc( *path, len + extra ); |
| 683 | if (!p) return 0; |
| 684 | memmove( &p[ extra ], p, len ); |
| 685 | p[ extra - 1 ] = '/'; |
| 686 | memcpy( p, segment, extra - 1 ); |
| 687 | } |
| 688 | else |
| 689 | { |
| 690 | p = malloc( extra ); |
| 691 | if (!p) return 0; |
| 692 | memcpy( p, segment, extra ); |
| 693 | } |
| 694 | |
| 695 | *path = p; |
| 696 | |
| 697 | return 1; |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 698 | } |
| 699 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 700 | static void inotify_notify_all( struct inotify_event *ie ) |
| 701 | { |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 702 | unsigned int filter, action; |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 703 | struct inode *inode, *i; |
| 704 | char *path = NULL; |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 705 | struct dir *dir; |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 706 | |
| 707 | inode = inode_from_wd( ie->wd ); |
| 708 | if (!inode) |
| 709 | { |
| 710 | fprintf( stderr, "no inode matches %d\n", ie->wd); |
| 711 | return; |
| 712 | } |
| 713 | |
| 714 | filter = filter_from_event( ie ); |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 715 | |
| 716 | if (ie->mask & IN_CREATE) |
| 717 | { |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 718 | switch (inode_check_dir( inode, ie->name )) |
Mike McCormack | a2813f7 | 2006-02-20 12:28:46 +0100 | [diff] [blame] | 719 | { |
| 720 | case 1: |
| 721 | filter &= ~FILE_NOTIFY_CHANGE_FILE_NAME; |
| 722 | break; |
| 723 | case 0: |
| 724 | filter &= ~FILE_NOTIFY_CHANGE_DIR_NAME; |
| 725 | break; |
| 726 | default: |
| 727 | break; |
| 728 | /* Maybe the file disappeared before we could check it? */ |
| 729 | } |
| 730 | action = FILE_ACTION_ADDED; |
| 731 | } |
| 732 | else if (ie->mask & IN_DELETE) |
| 733 | action = FILE_ACTION_REMOVED; |
| 734 | else |
| 735 | action = FILE_ACTION_MODIFIED; |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 736 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 737 | /* |
Francois Gouget | 4aa6418 | 2006-02-24 16:11:36 +0100 | [diff] [blame] | 738 | * Work our way up the inode hierarchy |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 739 | * extending the relative path as we go |
Francois Gouget | 4aa6418 | 2006-02-24 16:11:36 +0100 | [diff] [blame] | 740 | * and notifying all recursive watches. |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 741 | */ |
| 742 | if (!prepend( &path, ie->name )) |
| 743 | return; |
| 744 | |
| 745 | for (i = inode; i; i = i->parent) |
| 746 | { |
| 747 | LIST_FOR_EACH_ENTRY( dir, &i->dirs, struct dir, in_entry ) |
| 748 | if ((filter & dir->filter) && (i==inode || dir->subtree)) |
| 749 | inotify_do_change_notify( dir, action, path ); |
| 750 | |
| 751 | if (!i->name || !prepend( &path, i->name )) |
| 752 | break; |
| 753 | } |
| 754 | |
| 755 | free( path ); |
| 756 | |
| 757 | if (ie->mask & IN_DELETE) |
| 758 | { |
| 759 | i = inode_from_name( inode, ie->name ); |
| 760 | if (i) |
| 761 | free_inode( i ); |
| 762 | } |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 763 | } |
| 764 | |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 765 | static void inotify_poll_event( struct fd *fd, int event ) |
| 766 | { |
| 767 | int r, ofs, unix_fd; |
| 768 | char buffer[0x1000]; |
| 769 | struct inotify_event *ie; |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 770 | |
| 771 | unix_fd = get_unix_fd( fd ); |
| 772 | r = read( unix_fd, buffer, sizeof buffer ); |
| 773 | if (r < 0) |
| 774 | { |
| 775 | fprintf(stderr,"inotify_poll_event(): inotify read failed!\n"); |
| 776 | return; |
| 777 | } |
| 778 | |
Alexandre Julliard | e979832 | 2006-02-08 15:06:42 +0100 | [diff] [blame] | 779 | for( ofs = 0; ofs < r - offsetof(struct inotify_event, name); ) |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 780 | { |
| 781 | ie = (struct inotify_event*) &buffer[ofs]; |
| 782 | if (!ie->len) |
| 783 | break; |
Alexandre Julliard | e979832 | 2006-02-08 15:06:42 +0100 | [diff] [blame] | 784 | ofs += offsetof( struct inotify_event, name[ie->len] ); |
| 785 | if (ofs > r) break; |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 786 | inotify_notify_all( ie ); |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 790 | static inline struct fd *create_inotify_fd( void ) |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 791 | { |
Alexandre Julliard | cf9ced5 | 2006-02-05 12:19:56 +0100 | [diff] [blame] | 792 | int unix_fd; |
| 793 | |
| 794 | unix_fd = inotify_init(); |
| 795 | if (unix_fd<0) |
| 796 | return NULL; |
Alexandre Julliard | f85437c | 2007-04-10 22:25:07 +0200 | [diff] [blame] | 797 | return create_anonymous_fd( &inotify_fd_ops, unix_fd, NULL, 0 ); |
Alexandre Julliard | cf9ced5 | 2006-02-05 12:19:56 +0100 | [diff] [blame] | 798 | } |
| 799 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 800 | static int map_flags( unsigned int filter ) |
Alexandre Julliard | cf9ced5 | 2006-02-05 12:19:56 +0100 | [diff] [blame] | 801 | { |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 802 | unsigned int mask; |
Alexandre Julliard | cf9ced5 | 2006-02-05 12:19:56 +0100 | [diff] [blame] | 803 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 804 | /* always watch these so we can track subdirectories in recursive watches */ |
| 805 | mask = (IN_MOVED_FROM | IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF); |
| 806 | |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 807 | if (filter & FILE_NOTIFY_CHANGE_ATTRIBUTES) |
| 808 | mask |= IN_ATTRIB; |
| 809 | if (filter & FILE_NOTIFY_CHANGE_SIZE) |
| 810 | mask |= IN_MODIFY; |
| 811 | if (filter & FILE_NOTIFY_CHANGE_LAST_WRITE) |
| 812 | mask |= IN_MODIFY; |
| 813 | if (filter & FILE_NOTIFY_CHANGE_LAST_ACCESS) |
| 814 | mask |= IN_ACCESS; |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 815 | if (filter & FILE_NOTIFY_CHANGE_SECURITY) |
| 816 | mask |= IN_ATTRIB; |
| 817 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 818 | return mask; |
| 819 | } |
| 820 | |
| 821 | static int inotify_add_dir( char *path, unsigned int filter ) |
| 822 | { |
| 823 | int wd = inotify_add_watch( get_unix_fd( inotify_fd ), |
| 824 | path, map_flags( filter ) ); |
| 825 | if (wd != -1) |
| 826 | set_fd_events( inotify_fd, POLLIN ); |
| 827 | return wd; |
| 828 | } |
| 829 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 830 | static int init_inotify( void ) |
| 831 | { |
| 832 | int i; |
| 833 | |
| 834 | if (inotify_fd) |
| 835 | return 1; |
| 836 | |
| 837 | inotify_fd = create_inotify_fd(); |
| 838 | if (!inotify_fd) |
| 839 | return 0; |
| 840 | |
| 841 | for (i=0; i<HASH_SIZE; i++) |
| 842 | { |
| 843 | list_init( &inode_hash[i] ); |
| 844 | list_init( &wd_hash[i] ); |
| 845 | } |
| 846 | |
Alexandre Julliard | cf9ced5 | 2006-02-05 12:19:56 +0100 | [diff] [blame] | 847 | return 1; |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 848 | } |
| 849 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 850 | static int inotify_adjust_changes( struct dir *dir ) |
| 851 | { |
| 852 | unsigned int filter; |
| 853 | struct inode *inode; |
| 854 | struct stat st; |
| 855 | char path[32]; |
| 856 | int wd, unix_fd; |
| 857 | |
| 858 | if (!inotify_fd) |
| 859 | return 0; |
| 860 | |
| 861 | unix_fd = get_unix_fd( dir->fd ); |
| 862 | |
| 863 | inode = dir->inode; |
| 864 | if (!inode) |
| 865 | { |
| 866 | /* check if this fd is already being watched */ |
| 867 | if (-1 == fstat( unix_fd, &st )) |
| 868 | return 0; |
| 869 | |
| 870 | inode = get_inode( st.st_dev, st.st_ino ); |
| 871 | if (!inode) |
| 872 | inode = create_inode( st.st_dev, st.st_ino ); |
| 873 | if (!inode) |
| 874 | return 0; |
| 875 | list_add_tail( &inode->dirs, &dir->in_entry ); |
| 876 | dir->inode = inode; |
| 877 | } |
| 878 | |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 879 | filter = filter_from_inode( inode, 0 ); |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 880 | |
| 881 | sprintf( path, "/proc/self/fd/%u", unix_fd ); |
| 882 | wd = inotify_add_dir( path, filter ); |
| 883 | if (wd == -1) return 0; |
| 884 | |
| 885 | inode_set_wd( inode, wd ); |
| 886 | |
| 887 | return 1; |
| 888 | } |
| 889 | |
Mike McCormack | 4212108 | 2006-02-23 00:45:34 +0900 | [diff] [blame] | 890 | static char *get_basename( const char *link ) |
| 891 | { |
| 892 | char *buffer, *name = NULL; |
| 893 | int r, n = 0x100; |
| 894 | |
| 895 | while (1) |
| 896 | { |
| 897 | buffer = malloc( n ); |
Alexandre Julliard | c9cc7e3 | 2006-03-02 18:03:32 +0100 | [diff] [blame] | 898 | if (!buffer) return NULL; |
Mike McCormack | 4212108 | 2006-02-23 00:45:34 +0900 | [diff] [blame] | 899 | |
| 900 | r = readlink( link, buffer, n ); |
| 901 | if (r < 0) |
| 902 | break; |
| 903 | |
| 904 | if (r < n) |
| 905 | { |
| 906 | name = buffer; |
| 907 | break; |
| 908 | } |
| 909 | free( buffer ); |
| 910 | n *= 2; |
| 911 | } |
| 912 | |
| 913 | if (name) |
| 914 | { |
| 915 | while (r > 0 && name[ r - 1 ] == '/' ) |
| 916 | r--; |
| 917 | name[ r ] = 0; |
| 918 | |
| 919 | name = strrchr( name, '/' ); |
| 920 | if (name) |
| 921 | name = strdup( &name[1] ); |
| 922 | } |
| 923 | |
| 924 | free( buffer ); |
| 925 | return name; |
| 926 | } |
| 927 | |
| 928 | static int dir_add_to_existing_notify( struct dir *dir ) |
| 929 | { |
| 930 | struct inode *inode, *parent; |
| 931 | unsigned int filter = 0; |
| 932 | struct stat st, st_new; |
| 933 | char link[35], *name; |
| 934 | int wd, unix_fd; |
| 935 | |
| 936 | if (!inotify_fd) |
| 937 | return 0; |
| 938 | |
| 939 | unix_fd = get_unix_fd( dir->fd ); |
| 940 | |
| 941 | /* check if it's in the list of inodes we want to watch */ |
| 942 | if (-1 == fstat( unix_fd, &st_new )) |
| 943 | return 0; |
| 944 | inode = find_inode( st_new.st_dev, st_new.st_ino ); |
| 945 | if (inode) |
| 946 | return 0; |
| 947 | |
| 948 | /* lookup the parent */ |
| 949 | sprintf( link, "/proc/self/fd/%u/..", unix_fd ); |
| 950 | if (-1 == stat( link, &st )) |
| 951 | return 0; |
| 952 | |
| 953 | /* |
| 954 | * If there's no parent, stop. We could keep going adding |
| 955 | * ../ to the path until we hit the root of the tree or |
| 956 | * find a recursively watched ancestor. |
| 957 | * Assume it's too expensive to search up the tree for now. |
| 958 | */ |
| 959 | parent = find_inode( st.st_dev, st.st_ino ); |
| 960 | if (!parent) |
| 961 | return 0; |
| 962 | |
| 963 | if (parent->wd == -1) |
| 964 | return 0; |
| 965 | |
| 966 | filter = filter_from_inode( parent, 1 ); |
| 967 | if (!filter) |
| 968 | return 0; |
| 969 | |
| 970 | sprintf( link, "/proc/self/fd/%u", unix_fd ); |
| 971 | name = get_basename( link ); |
| 972 | if (!name) |
| 973 | return 0; |
| 974 | inode = inode_add( parent, st_new.st_dev, st_new.st_ino, name ); |
| 975 | free( name ); |
| 976 | if (!inode) |
| 977 | return 0; |
| 978 | |
| 979 | /* Couldn't find this inode at the start of the function, must be new */ |
| 980 | assert( inode->wd == -1 ); |
| 981 | |
| 982 | wd = inotify_add_dir( link, filter ); |
| 983 | if (wd != -1) |
| 984 | inode_set_wd( inode, wd ); |
| 985 | |
| 986 | return 1; |
| 987 | } |
| 988 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 989 | #else |
| 990 | |
| 991 | static int init_inotify( void ) |
| 992 | { |
| 993 | return 0; |
| 994 | } |
| 995 | |
| 996 | static int inotify_adjust_changes( struct dir *dir ) |
| 997 | { |
| 998 | return 0; |
| 999 | } |
| 1000 | |
| 1001 | static void free_inode( struct inode *inode ) |
| 1002 | { |
| 1003 | assert( 0 ); |
| 1004 | } |
| 1005 | |
Mike McCormack | 4212108 | 2006-02-23 00:45:34 +0900 | [diff] [blame] | 1006 | static int dir_add_to_existing_notify( struct dir *dir ) |
| 1007 | { |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
Alexandre Julliard | cf9ced5 | 2006-02-05 12:19:56 +0100 | [diff] [blame] | 1011 | #endif /* USE_INOTIFY */ |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 1012 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 1013 | struct object *create_dir_obj( struct fd *fd ) |
| 1014 | { |
| 1015 | struct dir *dir; |
| 1016 | |
| 1017 | dir = alloc_object( &dir_ops ); |
| 1018 | if (!dir) |
| 1019 | return NULL; |
| 1020 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 1021 | list_init( &dir->change_records ); |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 1022 | dir->filter = 0; |
| 1023 | dir->notified = 0; |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 1024 | dir->want_data = 0; |
| 1025 | dir->inode = NULL; |
| 1026 | grab_object( fd ); |
| 1027 | dir->fd = fd; |
| 1028 | set_fd_user( fd, &dir_fd_ops, &dir->obj ); |
| 1029 | |
Mike McCormack | 4212108 | 2006-02-23 00:45:34 +0900 | [diff] [blame] | 1030 | dir_add_to_existing_notify( dir ); |
| 1031 | |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 1032 | return &dir->obj; |
| 1033 | } |
| 1034 | |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 1035 | /* enable change notifications for a directory */ |
| 1036 | DECL_HANDLER(read_directory_changes) |
| 1037 | { |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 1038 | struct dir *dir; |
Alexandre Julliard | 0aae1ca | 2007-04-02 20:41:59 +0200 | [diff] [blame] | 1039 | struct async *async; |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 1040 | |
| 1041 | if (!req->filter) |
| 1042 | { |
| 1043 | set_error(STATUS_INVALID_PARAMETER); |
| 1044 | return; |
| 1045 | } |
| 1046 | |
| 1047 | dir = get_dir_obj( current->process, req->handle, 0 ); |
| 1048 | if (!dir) |
| 1049 | return; |
| 1050 | |
Mike McCormack | 0193211 | 2006-02-06 11:58:55 +0100 | [diff] [blame] | 1051 | /* requests don't timeout */ |
Alexandre Julliard | 0aae1ca | 2007-04-02 20:41:59 +0200 | [diff] [blame] | 1052 | if (!(async = fd_queue_async( dir->fd, &req->async, ASYNC_TYPE_WAIT, 0 ))) goto end; |
Mike McCormack | 0193211 | 2006-02-06 11:58:55 +0100 | [diff] [blame] | 1053 | |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 1054 | /* assign it once */ |
| 1055 | if (!dir->filter) |
| 1056 | { |
Mike McCormack | fbc00db | 2006-02-17 11:40:38 +0100 | [diff] [blame] | 1057 | init_inotify(); |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 1058 | insert_change( dir ); |
| 1059 | dir->filter = req->filter; |
Mike McCormack | e4faabf | 2006-02-21 16:58:19 +0900 | [diff] [blame] | 1060 | dir->subtree = req->subtree; |
Mike McCormack | 0790f95 | 2006-02-07 16:50:36 +0100 | [diff] [blame] | 1061 | dir->want_data = req->want_data; |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 1062 | } |
| 1063 | |
Mike McCormack | f5c1381 | 2006-03-28 17:58:07 +0900 | [diff] [blame] | 1064 | /* if there's already a change in the queue, send it */ |
Alexandre Julliard | d99ee34 | 2007-04-02 12:49:45 +0200 | [diff] [blame] | 1065 | if (!list_empty( &dir->change_records )) |
Alexandre Julliard | df09ac5 | 2007-04-02 20:09:29 +0200 | [diff] [blame] | 1066 | fd_async_wake_up( dir->fd, ASYNC_TYPE_WAIT, STATUS_ALERTED ); |
Mike McCormack | f5c1381 | 2006-03-28 17:58:07 +0900 | [diff] [blame] | 1067 | |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 1068 | /* setup the real notification */ |
Alexandre Julliard | cf9ced5 | 2006-02-05 12:19:56 +0100 | [diff] [blame] | 1069 | if (!inotify_adjust_changes( dir )) |
Mike McCormack | fdf0c68 | 2006-01-30 18:15:31 +0100 | [diff] [blame] | 1070 | dnotify_adjust_changes( dir ); |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 1071 | |
Alexandre Julliard | 0aae1ca | 2007-04-02 20:41:59 +0200 | [diff] [blame] | 1072 | release_object( async ); |
Mike McCormack | 0835107 | 2006-01-27 12:13:56 +0100 | [diff] [blame] | 1073 | set_error(STATUS_PENDING); |
| 1074 | |
| 1075 | end: |
| 1076 | release_object( dir ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1077 | } |
Mike McCormack | 0193211 | 2006-02-06 11:58:55 +0100 | [diff] [blame] | 1078 | |
| 1079 | DECL_HANDLER(read_change) |
| 1080 | { |
| 1081 | struct change_record *record; |
| 1082 | struct dir *dir; |
| 1083 | |
| 1084 | dir = get_dir_obj( current->process, req->handle, 0 ); |
| 1085 | if (!dir) |
| 1086 | return; |
| 1087 | |
| 1088 | if ((record = get_first_change_record( dir )) != NULL) |
| 1089 | { |
| 1090 | reply->action = record->action; |
| 1091 | set_reply_data( record->name, record->len ); |
| 1092 | free( record ); |
| 1093 | } |
| 1094 | else |
| 1095 | set_error( STATUS_NO_DATA_DETECTED ); |
| 1096 | |
Mike McCormack | 0193211 | 2006-02-06 11:58:55 +0100 | [diff] [blame] | 1097 | release_object( dir ); |
| 1098 | } |