2 * Server-side change notification management
4 * Copyright (C) 1998 Alexandre Julliard
5 * Copyright (C) 2006 Mike McCormack
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.
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.
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
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
31 #include <sys/types.h>
35 #ifdef HAVE_SYS_ERRNO_H
36 #include <sys/errno.h>
40 #define WIN32_NO_STATUS
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 */
59 #define DN_ATTRIB 0x00000020 /* File changed attibutes */
60 #define DN_MULTISHOT 0x80000000 /* Don't remove notifier */
66 #if defined(__linux__) && defined(__i386__)
68 #define SYS_inotify_init 291
69 #define SYS_inotify_add_watch 292
70 #define SYS_inotify_rm_watch 293
72 struct inotify_event
{
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
92 static inline int inotify_init( void )
95 __asm__
__volatile__( "int $0x80"
97 : "0" (SYS_inotify_init
));
98 if (ret
<0) { errno
= -ret
; ret
= -1; }
102 static inline int inotify_add_watch( int fd
, const char *name
, unsigned int mask
)
105 __asm__
__volatile__( "pushl %%ebx;\n\t"
109 : "=a" (ret
) : "0" (SYS_inotify_add_watch
),
110 "r" (fd
), "c" (name
), "d" (mask
) );
111 if (ret
<0) { errno
= -ret
; ret
= -1; }
115 static inline int inotify_remove_watch( int fd
, int wd
)
118 __asm__
__volatile__( "pushl %%ebx;\n\t"
122 : "=a" (ret
) : "0" (SYS_inotify_rm_watch
),
123 "r" (fd
), "c" (wd
) );
124 if (ret
<0) { errno
= -ret
; ret
= -1; }
134 static void free_inode( struct inode
*inode
);
136 static struct fd
*inotify_fd
;
138 struct change_record
{
147 struct object obj
; /* object header */
148 struct fd
*fd
; /* file descriptor to the directory */
149 struct list entry
; /* entry in global change notifications list */
150 unsigned int filter
; /* notification filter */
151 int notified
; /* SIGIO counter */
152 int want_data
; /* return change data */
153 int subtree
; /* do we want to watch subdirectories? */
154 struct list change_records
; /* data for the change */
155 struct list in_entry
; /* entry in the inode dirs list */
156 struct inode
*inode
; /* inode of the associated directory */
159 static struct fd
*dir_get_fd( struct object
*obj
);
160 static unsigned int dir_map_access( struct object
*obj
, unsigned int access
);
161 static void dir_dump( struct object
*obj
, int verbose
);
162 static void dir_destroy( struct object
*obj
);
164 static const struct object_ops dir_ops
=
166 sizeof(struct dir
), /* size */
168 add_queue
, /* add_queue */
169 remove_queue
, /* remove_queue */
170 default_fd_signaled
, /* signaled */
171 no_satisfied
, /* satisfied */
172 no_signal
, /* signal */
173 dir_get_fd
, /* get_fd */
174 dir_map_access
, /* map_access */
175 no_lookup_name
, /* lookup_name */
176 no_open_file
, /* open_file */
177 fd_close_handle
, /* close_handle */
178 dir_destroy
/* destroy */
181 static int dir_get_poll_events( struct fd
*fd
);
182 static enum server_fd_type
dir_get_fd_type( struct fd
*fd
);
184 static const struct fd_ops dir_fd_ops
=
186 dir_get_poll_events
, /* get_poll_events */
187 default_poll_event
, /* poll_event */
188 no_flush
, /* flush */
189 dir_get_fd_type
, /* get_fd_type */
190 default_fd_queue_async
, /* queue_async */
191 default_fd_reselect_async
, /* reselect_async */
192 default_fd_cancel_async
/* cancel_async */
195 static struct list change_list
= LIST_INIT(change_list
);
197 static void dnotify_adjust_changes( struct dir
*dir
)
199 #if defined(F_SETSIG) && defined(F_NOTIFY)
200 int fd
= get_unix_fd( dir
->fd
);
201 unsigned int filter
= dir
->filter
;
203 if ( 0 > fcntl( fd
, F_SETSIG
, SIGIO
) )
207 if (filter
& FILE_NOTIFY_CHANGE_FILE_NAME
)
208 val
|= DN_RENAME
| DN_DELETE
| DN_CREATE
;
209 if (filter
& FILE_NOTIFY_CHANGE_DIR_NAME
)
210 val
|= DN_RENAME
| DN_DELETE
| DN_CREATE
;
211 if (filter
& FILE_NOTIFY_CHANGE_ATTRIBUTES
)
213 if (filter
& FILE_NOTIFY_CHANGE_SIZE
)
215 if (filter
& FILE_NOTIFY_CHANGE_LAST_WRITE
)
217 if (filter
& FILE_NOTIFY_CHANGE_LAST_ACCESS
)
219 if (filter
& FILE_NOTIFY_CHANGE_CREATION
)
221 if (filter
& FILE_NOTIFY_CHANGE_SECURITY
)
223 fcntl( fd
, F_NOTIFY
, val
);
227 /* insert change in the global list */
228 static inline void insert_change( struct dir
*dir
)
232 sigemptyset( &sigset
);
233 sigaddset( &sigset
, SIGIO
);
234 sigprocmask( SIG_BLOCK
, &sigset
, NULL
);
235 list_add_head( &change_list
, &dir
->entry
);
236 sigprocmask( SIG_UNBLOCK
, &sigset
, NULL
);
239 /* remove change from the global list */
240 static inline void remove_change( struct dir
*dir
)
244 sigemptyset( &sigset
);
245 sigaddset( &sigset
, SIGIO
);
246 sigprocmask( SIG_BLOCK
, &sigset
, NULL
);
247 list_remove( &dir
->entry
);
248 sigprocmask( SIG_UNBLOCK
, &sigset
, NULL
);
251 static void dir_dump( struct object
*obj
, int verbose
)
253 struct dir
*dir
= (struct dir
*)obj
;
254 assert( obj
->ops
== &dir_ops
);
255 fprintf( stderr
, "Dirfile fd=%p filter=%08x\n", dir
->fd
, dir
->filter
);
258 /* enter here directly from SIGIO signal handler */
259 void do_change_notify( int unix_fd
)
263 /* FIXME: this is O(n) ... probably can be improved */
264 LIST_FOR_EACH_ENTRY( dir
, &change_list
, struct dir
, entry
)
266 if (get_unix_fd( dir
->fd
) != unix_fd
) continue;
267 interlocked_xchg_add( &dir
->notified
, 1 );
272 /* SIGIO callback, called synchronously with the poll loop */
273 void sigio_callback(void)
277 LIST_FOR_EACH_ENTRY( dir
, &change_list
, struct dir
, entry
)
279 if (interlocked_xchg( &dir
->notified
, 0 ))
280 fd_async_wake_up( dir
->fd
, ASYNC_TYPE_WAIT
, STATUS_NOTIFY_ENUM_DIR
);
284 static struct fd
*dir_get_fd( struct object
*obj
)
286 struct dir
*dir
= (struct dir
*)obj
;
287 assert( obj
->ops
== &dir_ops
);
288 return (struct fd
*)grab_object( dir
->fd
);
291 static unsigned int dir_map_access( struct object
*obj
, unsigned int access
)
293 if (access
& GENERIC_READ
) access
|= FILE_GENERIC_READ
;
294 if (access
& GENERIC_WRITE
) access
|= FILE_GENERIC_WRITE
;
295 if (access
& GENERIC_EXECUTE
) access
|= FILE_GENERIC_EXECUTE
;
296 if (access
& GENERIC_ALL
) access
|= FILE_ALL_ACCESS
;
297 return access
& ~(GENERIC_READ
| GENERIC_WRITE
| GENERIC_EXECUTE
| GENERIC_ALL
);
300 static struct change_record
*get_first_change_record( struct dir
*dir
)
302 struct list
*ptr
= list_head( &dir
->change_records
);
303 if (!ptr
) return NULL
;
305 return LIST_ENTRY( ptr
, struct change_record
, entry
);
308 static void dir_destroy( struct object
*obj
)
310 struct change_record
*record
;
311 struct dir
*dir
= (struct dir
*)obj
;
312 assert (obj
->ops
== &dir_ops
);
315 remove_change( dir
);
319 list_remove( &dir
->in_entry
);
320 free_inode( dir
->inode
);
323 while ((record
= get_first_change_record( dir
))) free( record
);
325 release_object( dir
->fd
);
327 if (inotify_fd
&& list_empty( &change_list
))
329 release_object( inotify_fd
);
335 get_dir_obj( struct process
*process
, obj_handle_t handle
, unsigned int access
)
337 return (struct dir
*)get_handle_obj( process
, handle
, access
, &dir_ops
);
340 static int dir_get_poll_events( struct fd
*fd
)
345 static enum server_fd_type
dir_get_fd_type( struct fd
*fd
)
355 struct list ch_entry
; /* entry in the children list */
356 struct list children
; /* children of this inode */
357 struct inode
*parent
; /* parent of this inode */
358 struct list dirs
; /* directory handles watching this inode */
359 struct list ino_entry
; /* entry in the inode hash */
360 struct list wd_entry
; /* entry in the watch descriptor hash */
361 dev_t dev
; /* device number */
362 ino_t ino
; /* device's inode number */
363 int wd
; /* inotify's watch descriptor */
364 char *name
; /* basename name of the inode */
367 struct list inode_hash
[ HASH_SIZE
];
368 struct list wd_hash
[ HASH_SIZE
];
370 static int inotify_add_dir( char *path
, unsigned int filter
);
372 static struct inode
*inode_from_wd( int wd
)
374 struct list
*bucket
= &wd_hash
[ wd
% HASH_SIZE
];
377 LIST_FOR_EACH_ENTRY( inode
, bucket
, struct inode
, wd_entry
)
384 static inline struct list
*get_hash_list( dev_t dev
, ino_t ino
)
386 return &inode_hash
[ (ino
^ dev
) % HASH_SIZE
];
389 static struct inode
*find_inode( dev_t dev
, ino_t ino
)
391 struct list
*bucket
= get_hash_list( dev
, ino
);
394 LIST_FOR_EACH_ENTRY( inode
, bucket
, struct inode
, ino_entry
)
395 if (inode
->ino
== ino
&& inode
->dev
== dev
)
401 static struct inode
*create_inode( dev_t dev
, ino_t ino
)
405 inode
= malloc( sizeof *inode
);
408 list_init( &inode
->children
);
409 list_init( &inode
->dirs
);
413 inode
->parent
= NULL
;
415 list_add_tail( get_hash_list( dev
, ino
), &inode
->ino_entry
);
420 static struct inode
*get_inode( dev_t dev
, ino_t ino
)
424 inode
= find_inode( dev
, ino
);
427 return create_inode( dev
, ino
);
430 static void inode_set_wd( struct inode
*inode
, int wd
)
433 list_remove( &inode
->wd_entry
);
435 list_add_tail( &wd_hash
[ wd
% HASH_SIZE
], &inode
->wd_entry
);
438 static void inode_set_name( struct inode
*inode
, const char *name
)
441 inode
->name
= name
? strdup( name
) : NULL
;
444 static void free_inode( struct inode
*inode
)
446 int subtree
= 0, watches
= 0;
449 LIST_FOR_EACH_ENTRY( dir
, &inode
->dirs
, struct dir
, in_entry
)
451 subtree
|= dir
->subtree
;
455 if (!subtree
&& !inode
->parent
)
457 struct inode
*tmp
, *next
;
458 LIST_FOR_EACH_ENTRY_SAFE( tmp
, next
, &inode
->children
,
459 struct inode
, ch_entry
)
461 assert( tmp
!= inode
);
462 assert( tmp
->parent
== inode
);
471 list_remove( &inode
->ch_entry
);
475 inotify_remove_watch( get_unix_fd( inotify_fd
), inode
->wd
);
476 list_remove( &inode
->wd_entry
);
478 list_remove( &inode
->ino_entry
);
484 static struct inode
*inode_add( struct inode
*parent
,
485 dev_t dev
, ino_t ino
, const char *name
)
489 inode
= get_inode( dev
, ino
);
495 list_add_tail( &parent
->children
, &inode
->ch_entry
);
496 inode
->parent
= parent
;
497 assert( inode
!= parent
);
499 inode_set_name( inode
, name
);
504 static struct inode
*inode_from_name( struct inode
*inode
, const char *name
)
508 LIST_FOR_EACH_ENTRY( i
, &inode
->children
, struct inode
, ch_entry
)
509 if (i
->name
&& !strcmp( i
->name
, name
))
514 static int inotify_get_poll_events( struct fd
*fd
);
515 static void inotify_poll_event( struct fd
*fd
, int event
);
517 static const struct fd_ops inotify_fd_ops
=
519 inotify_get_poll_events
, /* get_poll_events */
520 inotify_poll_event
, /* poll_event */
522 NULL
, /* get_fd_type */
523 NULL
, /* queue_async */
524 NULL
, /* reselect_async */
525 NULL
, /* cancel_async */
528 static int inotify_get_poll_events( struct fd
*fd
)
533 static void inotify_do_change_notify( struct dir
*dir
, unsigned int action
,
534 const char *relpath
)
536 struct change_record
*record
;
538 assert( dir
->obj
.ops
== &dir_ops
);
542 size_t len
= strlen(relpath
);
543 record
= malloc( offsetof(struct change_record
, name
[len
]) );
547 record
->action
= action
;
548 memcpy( record
->name
, relpath
, len
);
551 list_add_tail( &dir
->change_records
, &record
->entry
);
554 fd_async_wake_up( dir
->fd
, ASYNC_TYPE_WAIT
, STATUS_ALERTED
);
557 static unsigned int filter_from_event( struct inotify_event
*ie
)
559 unsigned int filter
= 0;
561 if (ie
->mask
& (IN_MOVED_FROM
| IN_MOVED_TO
| IN_DELETE
| IN_CREATE
))
562 filter
|= FILE_NOTIFY_CHANGE_FILE_NAME
| FILE_NOTIFY_CHANGE_DIR_NAME
;
563 if (ie
->mask
& IN_MODIFY
)
564 filter
|= FILE_NOTIFY_CHANGE_SIZE
| FILE_NOTIFY_CHANGE_LAST_WRITE
;
565 if (ie
->mask
& IN_ATTRIB
)
566 filter
|= FILE_NOTIFY_CHANGE_ATTRIBUTES
| FILE_NOTIFY_CHANGE_SECURITY
;
567 if (ie
->mask
& IN_ACCESS
)
568 filter
|= FILE_NOTIFY_CHANGE_LAST_ACCESS
;
569 if (ie
->mask
& IN_CREATE
)
570 filter
|= FILE_NOTIFY_CHANGE_CREATION
;
575 /* scan up the parent directories for watches */
576 static unsigned int filter_from_inode( struct inode
*inode
, int is_parent
)
578 unsigned int filter
= 0;
581 /* combine filters from parents watching subtrees */
584 LIST_FOR_EACH_ENTRY( dir
, &inode
->dirs
, struct dir
, in_entry
)
585 if (dir
->subtree
|| !is_parent
)
586 filter
|= dir
->filter
;
588 inode
= inode
->parent
;
594 static char *inode_get_path( struct inode
*inode
, int sz
)
603 head
= list_head( &inode
->dirs
);
606 int unix_fd
= get_unix_fd( LIST_ENTRY( head
, struct dir
, in_entry
)->fd
);
607 path
= malloc ( 32 + sz
);
609 sprintf( path
, "/proc/self/fd/%u/", unix_fd
);
616 len
= strlen( inode
->name
);
617 path
= inode_get_path( inode
->parent
, sz
+ len
+ 1 );
621 strcat( path
, inode
->name
);
627 static int inode_check_dir( struct inode
*parent
, const char *name
)
635 path
= inode_get_path( parent
, strlen(name
) );
639 strcat( path
, name
);
641 r
= stat( path
, &st
);
644 if (!S_ISDIR(st
.st_mode
))
652 filter
= filter_from_inode( parent
, 1 );
656 inode
= inode_add( parent
, st
.st_dev
, st
.st_ino
, name
);
657 if (!inode
|| inode
->wd
!= -1)
660 wd
= inotify_add_dir( path
, filter
);
662 inode_set_wd( inode
, wd
);
671 static int prepend( char **path
, const char *segment
)
676 extra
= strlen( segment
) + 1;
679 int len
= strlen( *path
) + 1;
680 p
= realloc( *path
, len
+ extra
);
682 memmove( &p
[ extra
], p
, len
);
683 p
[ extra
- 1 ] = '/';
684 memcpy( p
, segment
, extra
- 1 );
690 memcpy( p
, segment
, extra
);
698 static void inotify_notify_all( struct inotify_event
*ie
)
700 unsigned int filter
, action
;
701 struct inode
*inode
, *i
;
705 inode
= inode_from_wd( ie
->wd
);
708 fprintf( stderr
, "no inode matches %d\n", ie
->wd
);
712 filter
= filter_from_event( ie
);
714 if (ie
->mask
& IN_CREATE
)
716 switch (inode_check_dir( inode
, ie
->name
))
719 filter
&= ~FILE_NOTIFY_CHANGE_FILE_NAME
;
722 filter
&= ~FILE_NOTIFY_CHANGE_DIR_NAME
;
726 /* Maybe the file disappeared before we could check it? */
728 action
= FILE_ACTION_ADDED
;
730 else if (ie
->mask
& IN_DELETE
)
731 action
= FILE_ACTION_REMOVED
;
733 action
= FILE_ACTION_MODIFIED
;
736 * Work our way up the inode hierarchy
737 * extending the relative path as we go
738 * and notifying all recursive watches.
740 if (!prepend( &path
, ie
->name
))
743 for (i
= inode
; i
; i
= i
->parent
)
745 LIST_FOR_EACH_ENTRY( dir
, &i
->dirs
, struct dir
, in_entry
)
746 if ((filter
& dir
->filter
) && (i
==inode
|| dir
->subtree
))
747 inotify_do_change_notify( dir
, action
, path
);
749 if (!i
->name
|| !prepend( &path
, i
->name
))
755 if (ie
->mask
& IN_DELETE
)
757 i
= inode_from_name( inode
, ie
->name
);
763 static void inotify_poll_event( struct fd
*fd
, int event
)
767 struct inotify_event
*ie
;
769 unix_fd
= get_unix_fd( fd
);
770 r
= read( unix_fd
, buffer
, sizeof buffer
);
773 fprintf(stderr
,"inotify_poll_event(): inotify read failed!\n");
777 for( ofs
= 0; ofs
< r
- offsetof(struct inotify_event
, name
); )
779 ie
= (struct inotify_event
*) &buffer
[ofs
];
782 ofs
+= offsetof( struct inotify_event
, name
[ie
->len
] );
784 inotify_notify_all( ie
);
788 static inline struct fd
*create_inotify_fd( void )
792 unix_fd
= inotify_init();
795 return create_anonymous_fd( &inotify_fd_ops
, unix_fd
, NULL
, 0 );
798 static int map_flags( unsigned int filter
)
802 /* always watch these so we can track subdirectories in recursive watches */
803 mask
= (IN_MOVED_FROM
| IN_MOVED_TO
| IN_DELETE
| IN_CREATE
| IN_DELETE_SELF
);
805 if (filter
& FILE_NOTIFY_CHANGE_ATTRIBUTES
)
807 if (filter
& FILE_NOTIFY_CHANGE_SIZE
)
809 if (filter
& FILE_NOTIFY_CHANGE_LAST_WRITE
)
811 if (filter
& FILE_NOTIFY_CHANGE_LAST_ACCESS
)
813 if (filter
& FILE_NOTIFY_CHANGE_SECURITY
)
819 static int inotify_add_dir( char *path
, unsigned int filter
)
821 int wd
= inotify_add_watch( get_unix_fd( inotify_fd
),
822 path
, map_flags( filter
) );
824 set_fd_events( inotify_fd
, POLLIN
);
828 static int init_inotify( void )
835 inotify_fd
= create_inotify_fd();
839 for (i
=0; i
<HASH_SIZE
; i
++)
841 list_init( &inode_hash
[i
] );
842 list_init( &wd_hash
[i
] );
848 static int inotify_adjust_changes( struct dir
*dir
)
859 unix_fd
= get_unix_fd( dir
->fd
);
864 /* check if this fd is already being watched */
865 if (-1 == fstat( unix_fd
, &st
))
868 inode
= get_inode( st
.st_dev
, st
.st_ino
);
870 inode
= create_inode( st
.st_dev
, st
.st_ino
);
873 list_add_tail( &inode
->dirs
, &dir
->in_entry
);
877 filter
= filter_from_inode( inode
, 0 );
879 sprintf( path
, "/proc/self/fd/%u", unix_fd
);
880 wd
= inotify_add_dir( path
, filter
);
881 if (wd
== -1) return 0;
883 inode_set_wd( inode
, wd
);
888 static char *get_basename( const char *link
)
890 char *buffer
, *name
= NULL
;
895 buffer
= malloc( n
);
896 if (!buffer
) return NULL
;
898 r
= readlink( link
, buffer
, n
);
913 while (r
> 0 && name
[ r
- 1 ] == '/' )
917 name
= strrchr( name
, '/' );
919 name
= strdup( &name
[1] );
926 static int dir_add_to_existing_notify( struct dir
*dir
)
928 struct inode
*inode
, *parent
;
929 unsigned int filter
= 0;
930 struct stat st
, st_new
;
931 char link
[35], *name
;
937 unix_fd
= get_unix_fd( dir
->fd
);
939 /* check if it's in the list of inodes we want to watch */
940 if (-1 == fstat( unix_fd
, &st_new
))
942 inode
= find_inode( st_new
.st_dev
, st_new
.st_ino
);
946 /* lookup the parent */
947 sprintf( link
, "/proc/self/fd/%u/..", unix_fd
);
948 if (-1 == stat( link
, &st
))
952 * If there's no parent, stop. We could keep going adding
953 * ../ to the path until we hit the root of the tree or
954 * find a recursively watched ancestor.
955 * Assume it's too expensive to search up the tree for now.
957 parent
= find_inode( st
.st_dev
, st
.st_ino
);
961 if (parent
->wd
== -1)
964 filter
= filter_from_inode( parent
, 1 );
968 sprintf( link
, "/proc/self/fd/%u", unix_fd
);
969 name
= get_basename( link
);
972 inode
= inode_add( parent
, st_new
.st_dev
, st_new
.st_ino
, name
);
977 /* Couldn't find this inode at the start of the function, must be new */
978 assert( inode
->wd
== -1 );
980 wd
= inotify_add_dir( link
, filter
);
982 inode_set_wd( inode
, wd
);
989 static int init_inotify( void )
994 static int inotify_adjust_changes( struct dir
*dir
)
999 static void free_inode( struct inode
*inode
)
1004 static int dir_add_to_existing_notify( struct dir
*dir
)
1009 #endif /* USE_INOTIFY */
1011 struct object
*create_dir_obj( struct fd
*fd
)
1015 dir
= alloc_object( &dir_ops
);
1019 list_init( &dir
->change_records
);
1026 set_fd_user( fd
, &dir_fd_ops
, &dir
->obj
);
1028 dir_add_to_existing_notify( dir
);
1033 /* enable change notifications for a directory */
1034 DECL_HANDLER(read_directory_changes
)
1037 struct async
*async
;
1041 set_error(STATUS_INVALID_PARAMETER
);
1045 dir
= get_dir_obj( current
->process
, req
->handle
, 0 );
1049 /* requests don't timeout */
1050 if (!(async
= fd_queue_async( dir
->fd
, &req
->async
, ASYNC_TYPE_WAIT
, 0 ))) goto end
;
1052 /* assign it once */
1056 insert_change( dir
);
1057 dir
->filter
= req
->filter
;
1058 dir
->subtree
= req
->subtree
;
1059 dir
->want_data
= req
->want_data
;
1062 /* if there's already a change in the queue, send it */
1063 if (!list_empty( &dir
->change_records
))
1064 fd_async_wake_up( dir
->fd
, ASYNC_TYPE_WAIT
, STATUS_ALERTED
);
1066 /* setup the real notification */
1067 if (!inotify_adjust_changes( dir
))
1068 dnotify_adjust_changes( dir
);
1070 release_object( async
);
1071 set_error(STATUS_PENDING
);
1074 release_object( dir
);
1077 DECL_HANDLER(read_change
)
1079 struct change_record
*record
;
1082 dir
= get_dir_obj( current
->process
, req
->handle
, 0 );
1086 if ((record
= get_first_change_record( dir
)) != NULL
)
1088 reply
->action
= record
->action
;
1089 set_reply_data( record
->name
, record
->len
);
1093 set_error( STATUS_NO_DATA_DETECTED
);
1095 release_object( dir
);