/[linux-patches]/genpatches-2.6/trunk/2.6.12-pre/4800_inotify-0.23-8.patch
Gentoo

Contents of /genpatches-2.6/trunk/2.6.12-pre/4800_inotify-0.23-8.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (show annotations) (download)
Sat Jun 11 23:33:28 2005 UTC (9 years, 4 months ago) by dsd
File size: 58719 byte(s)
inotify 0.23-8
1 inotify!
2
3 inotify is intended to correct the deficiencies of dnotify, particularly
4 its inability to scale and its terrible user interface:
5
6 * dnotify requires the opening of one fd per each directory
7 that you intend to watch. This quickly results in too many
8 open files and pins removable media, preventing unmount.
9 * dnotify is directory-based. You only learn about changes to
10 directories. Sure, a change to a file in a directory affects
11 the directory, but you are then forced to keep a cache of
12 stat structures.
13 * dnotify's interface to user-space is awful. Signals?
14
15 inotify provides a more usable, simple, powerful solution to file change
16 notification:
17
18 * inotify's interface is a device node, not SIGIO. You open a
19 single fd to the device node, which is select()-able.
20 * inotify has an event that says "the filesystem that the item
21 you were watching is on was unmounted."
22 * inotify can watch directories or files.
23
24 Inotify is currently used by Beagle (a desktop search infrastructure),
25 Gamin (a FAM replacement), and other projects.
26
27 See Documentation/filesystems/inotify.txt.
28
29 Signed-off-by: Robert Love <rml@novell.com>
30
31 Documentation/filesystems/inotify.txt | 123 ++++
32 fs/Kconfig | 13
33 fs/Makefile | 1
34 fs/attr.c | 33 -
35 fs/compat.c | 12
36 fs/file_table.c | 3
37 fs/inode.c | 6
38 fs/inotify.c | 981 ++++++++++++++++++++++++++++++++++
39 fs/namei.c | 30 -
40 fs/nfsd/vfs.c | 6
41 fs/open.c | 4
42 fs/read_write.c | 15
43 fs/sysfs/file.c | 7
44 fs/xattr.c | 5
45 include/linux/fs.h | 6
46 include/linux/fsnotify.h | 257 ++++++++
47 include/linux/inotify.h | 124 ++++
48 include/linux/sched.h | 4
49 kernel/user.c | 4
50 19 files changed, 1570 insertions(+), 64 deletions(-)
51
52 diff -urN linux-2.6.12-rc6/Documentation/filesystems/inotify.txt linux/Documentation/filesystems/inotify.txt
53 --- linux-2.6.12-rc6/Documentation/filesystems/inotify.txt 1969-12-31 19:00:00.000000000 -0500
54 +++ linux/Documentation/filesystems/inotify.txt 2005-06-07 15:49:02.000000000 -0400
55 @@ -0,0 +1,123 @@
56 + inotify
57 + a powerful yet simple file change notification system
58 +
59 +
60 +
61 +Document started 15 Mar 2005 by Robert Love <rml@novell.com>
62 +
63 +(i) User Interface
64 +
65 +Inotify is controlled by a device node, /dev/inotify. If you do not use udev,
66 +this device may need to be created manually. First step, open it
67 +
68 + int dev_fd = open ("/dev/inotify", O_RDONLY);
69 +
70 +Change events are managed by "watches". A watch is an (object,mask) pair where
71 +the object is a file or directory and the mask is a bitmask of one or more
72 +inotify events that the application wishes to receive. See <linux/inotify.h>
73 +for valid events. A watch is referenced by a watch descriptor, or wd.
74 +
75 +Watches are added via a file descriptor.
76 +
77 +Watches on a directory will return events on any files inside of the directory.
78 +
79 +Adding a watch is simple,
80 +
81 + /* 'wd' represents the watch on fd with mask */
82 + struct inotify_request req = { fd, mask };
83 + int wd = ioctl (dev_fd, INOTIFY_WATCH, &req);
84 +
85 +You can add a large number of files via something like
86 +
87 + for each file to watch {
88 + struct inotify_request req;
89 + int file_fd;
90 +
91 + file_fd = open (file, O_RDONLY);
92 + if (fd < 0) {
93 + perror ("open");
94 + break;
95 + }
96 +
97 + req.fd = file_fd;
98 + req.mask = mask;
99 +
100 + wd = ioctl (dev_fd, INOTIFY_WATCH, &req);
101 +
102 + close (fd);
103 + }
104 +
105 +You can update an existing watch in the same manner, by passing in a new mask.
106 +
107 +An existing watch is removed via the INOTIFY_IGNORE ioctl, for example
108 +
109 + ioctl (dev_fd, INOTIFY_IGNORE, wd);
110 +
111 +Events are provided in the form of an inotify_event structure that is read(2)
112 +from /dev/inotify. The filename is of dynamic length and follows the struct.
113 +It is of size len. The filename is padded with null bytes to ensure proper
114 +alignment. This padding is reflected in len.
115 +
116 +You can slurp multiple events by passing a large buffer, for example
117 +
118 + size_t len = read (fd, buf, BUF_LEN);
119 +
120 +Will return as many events as are available and fit in BUF_LEN.
121 +
122 +/dev/inotify is also select() and poll() able.
123 +
124 +You can find the size of the current event queue via the FIONREAD ioctl.
125 +
126 +All watches are destroyed and cleaned up on close.
127 +
128 +
129 +(ii) Internal Kernel Implementation
130 +
131 +Each open inotify device is associated with an inotify_device structure.
132 +
133 +Each watch is associated with an inotify_watch structure. Watches are chained
134 +off of each associated device and each associated inode.
135 +
136 +See fs/inotify.c for the locking and lifetime rules.
137 +
138 +
139 +(iii) Rationale
140 +
141 +Q: What is the design decision behind not tying the watch to the
142 +open fd of the watched object?
143 +
144 +A: Watches are associated with an open inotify device, not an
145 +open file. This solves the primary problem with dnotify:
146 +keeping the file open pins the file and thus, worse, pins the
147 +mount. Dnotify is therefore infeasible for use on a desktop
148 +system with removable media as the media cannot be unmounted.
149 +
150 +Q: What is the design decision behind using an-fd-per-device as
151 +opposed to an fd-per-watch?
152 +
153 +A: An fd-per-watch quickly consumes more file descriptors than
154 +are allowed, more fd's than are feasible to manage, and more
155 +fd's than are ideally select()-able. Yes, root can bump the
156 +per-process fd limit and yes, users can use epoll, but requiring
157 +both is silly and an extraneous requirement. A watch consumes
158 +less memory than an open file, separating the number spaces is
159 +thus sensible. The current design is what user-space developers
160 +want: Users open the device, once, and add n watches, requiring
161 +but one fd and no twiddling with fd limits.
162 +Opening /dev/inotify two thousand times is silly. If we can
163 +implement user-space's preferences cleanly--and we can, the idr
164 +layer makes stuff like this trivial--then we should.
165 +
166 +Q: Why a device node?
167 +
168 +A: The second biggest problem with dnotify is that the user
169 +interface sucks ass. Signals are a terrible, terrible interface
170 +for file notification. Or for anything, for that matter. The
171 +idea solution, from all perspectives, is a file descriptor based
172 +one that allows basic file I/O and poll/select. Obtaining the
173 +fd and managing the watches could of been done either via a
174 +device file or a family of new system calls. We decided to
175 +implement a device file because adding three or four new system
176 +calls that mirrored open, close, and ioctl seemed silly. A
177 +character device makes sense from user-space and was easy to
178 +implement inside of the kernel.
179 diff -urN linux-2.6.12-rc6/fs/attr.c linux/fs/attr.c
180 --- linux-2.6.12-rc6/fs/attr.c 2005-06-07 15:47:52.000000000 -0400
181 +++ linux/fs/attr.c 2005-06-07 15:49:02.000000000 -0400
182 @@ -10,7 +10,7 @@
183 #include <linux/mm.h>
184 #include <linux/string.h>
185 #include <linux/smp_lock.h>
186 -#include <linux/dnotify.h>
187 +#include <linux/fsnotify.h>
188 #include <linux/fcntl.h>
189 #include <linux/quotaops.h>
190 #include <linux/security.h>
191 @@ -107,31 +107,8 @@
192 out:
193 return error;
194 }
195 -
196 EXPORT_SYMBOL(inode_setattr);
197
198 -int setattr_mask(unsigned int ia_valid)
199 -{
200 - unsigned long dn_mask = 0;
201 -
202 - if (ia_valid & ATTR_UID)
203 - dn_mask |= DN_ATTRIB;
204 - if (ia_valid & ATTR_GID)
205 - dn_mask |= DN_ATTRIB;
206 - if (ia_valid & ATTR_SIZE)
207 - dn_mask |= DN_MODIFY;
208 - /* both times implies a utime(s) call */
209 - if ((ia_valid & (ATTR_ATIME|ATTR_MTIME)) == (ATTR_ATIME|ATTR_MTIME))
210 - dn_mask |= DN_ATTRIB;
211 - else if (ia_valid & ATTR_ATIME)
212 - dn_mask |= DN_ACCESS;
213 - else if (ia_valid & ATTR_MTIME)
214 - dn_mask |= DN_MODIFY;
215 - if (ia_valid & ATTR_MODE)
216 - dn_mask |= DN_ATTRIB;
217 - return dn_mask;
218 -}
219 -
220 int notify_change(struct dentry * dentry, struct iattr * attr)
221 {
222 struct inode *inode = dentry->d_inode;
223 @@ -197,11 +174,9 @@
224 if (ia_valid & ATTR_SIZE)
225 up_write(&dentry->d_inode->i_alloc_sem);
226
227 - if (!error) {
228 - unsigned long dn_mask = setattr_mask(ia_valid);
229 - if (dn_mask)
230 - dnotify_parent(dentry, dn_mask);
231 - }
232 + if (!error)
233 + fsnotify_change(dentry, ia_valid);
234 +
235 return error;
236 }
237
238 diff -urN linux-2.6.12-rc6/fs/compat.c linux/fs/compat.c
239 --- linux-2.6.12-rc6/fs/compat.c 2005-06-07 15:47:52.000000000 -0400
240 +++ linux/fs/compat.c 2005-06-07 15:49:02.000000000 -0400
241 @@ -37,7 +37,7 @@
242 #include <linux/ctype.h>
243 #include <linux/module.h>
244 #include <linux/dirent.h>
245 -#include <linux/dnotify.h>
246 +#include <linux/fsnotify.h>
247 #include <linux/highuid.h>
248 #include <linux/sunrpc/svc.h>
249 #include <linux/nfsd/nfsd.h>
250 @@ -1307,9 +1307,13 @@
251 out:
252 if (iov != iovstack)
253 kfree(iov);
254 - if ((ret + (type == READ)) > 0)
255 - dnotify_parent(file->f_dentry,
256 - (type == READ) ? DN_ACCESS : DN_MODIFY);
257 + if ((ret + (type == READ)) > 0) {
258 + struct dentry *dentry = file->f_dentry;
259 + if (type == READ)
260 + fsnotify_access(dentry);
261 + else
262 + fsnotify_modify(dentry);
263 + }
264 return ret;
265 }
266
267 diff -urN linux-2.6.12-rc6/fs/file_table.c linux/fs/file_table.c
268 --- linux-2.6.12-rc6/fs/file_table.c 2005-03-02 02:37:47.000000000 -0500
269 +++ linux/fs/file_table.c 2005-06-07 15:49:02.000000000 -0400
270 @@ -16,6 +16,7 @@
271 #include <linux/eventpoll.h>
272 #include <linux/mount.h>
273 #include <linux/cdev.h>
274 +#include <linux/fsnotify.h>
275
276 /* sysctl tunables... */
277 struct files_stat_struct files_stat = {
278 @@ -123,6 +124,8 @@
279 struct inode *inode = dentry->d_inode;
280
281 might_sleep();
282 +
283 + fsnotify_close(file);
284 /*
285 * The function eventpoll_release() should be the first called
286 * in the file cleanup chain.
287 diff -urN linux-2.6.12-rc6/fs/inode.c linux/fs/inode.c
288 --- linux-2.6.12-rc6/fs/inode.c 2005-06-07 15:47:52.000000000 -0400
289 +++ linux/fs/inode.c 2005-06-07 15:49:02.000000000 -0400
290 @@ -21,6 +21,7 @@
291 #include <linux/pagemap.h>
292 #include <linux/cdev.h>
293 #include <linux/bootmem.h>
294 +#include <linux/inotify.h>
295
296 /*
297 * This is needed for the following functions:
298 @@ -128,6 +129,10 @@
299 #ifdef CONFIG_QUOTA
300 memset(&inode->i_dquot, 0, sizeof(inode->i_dquot));
301 #endif
302 +#ifdef CONFIG_INOTIFY
303 + INIT_LIST_HEAD(&inode->inotify_watches);
304 + sema_init(&inode->inotify_sem, 1);
305 +#endif
306 inode->i_pipe = NULL;
307 inode->i_bdev = NULL;
308 inode->i_cdev = NULL;
309 @@ -346,6 +351,7 @@
310
311 down(&iprune_sem);
312 spin_lock(&inode_lock);
313 + inotify_unmount_inodes(&sb->s_inodes);
314 busy = invalidate_list(&sb->s_inodes, &throw_away);
315 spin_unlock(&inode_lock);
316
317 diff -urN linux-2.6.12-rc6/fs/inotify.c linux/fs/inotify.c
318 --- linux-2.6.12-rc6/fs/inotify.c 1969-12-31 19:00:00.000000000 -0500
319 +++ linux/fs/inotify.c 2005-06-07 15:49:02.000000000 -0400
320 @@ -0,0 +1,981 @@
321 +/*
322 + * fs/inotify.c - inode-based file event notifications
323 + *
324 + * Authors:
325 + * John McCutchan <ttb@tentacle.dhs.org>
326 + * Robert Love <rml@novell.com>
327 + *
328 + * Copyright (C) 2005 John McCutchan
329 + *
330 + * This program is free software; you can redistribute it and/or modify it
331 + * under the terms of the GNU General Public License as published by the
332 + * Free Software Foundation; either version 2, or (at your option) any
333 + * later version.
334 + *
335 + * This program is distributed in the hope that it will be useful, but
336 + * WITHOUT ANY WARRANTY; without even the implied warranty of
337 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
338 + * General Public License for more details.
339 + */
340 +
341 +#include <linux/module.h>
342 +#include <linux/kernel.h>
343 +#include <linux/sched.h>
344 +#include <linux/spinlock.h>
345 +#include <linux/idr.h>
346 +#include <linux/slab.h>
347 +#include <linux/fs.h>
348 +#include <linux/file.h>
349 +#include <linux/namei.h>
350 +#include <linux/poll.h>
351 +#include <linux/device.h>
352 +#include <linux/miscdevice.h>
353 +#include <linux/init.h>
354 +#include <linux/list.h>
355 +#include <linux/writeback.h>
356 +#include <linux/inotify.h>
357 +
358 +#include <asm/ioctls.h>
359 +
360 +static atomic_t inotify_cookie;
361 +
362 +static kmem_cache_t *watch_cachep;
363 +static kmem_cache_t *event_cachep;
364 +
365 +static int max_user_devices;
366 +static int max_user_watches;
367 +static unsigned int max_queued_events;
368 +
369 +/*
370 + * Lock ordering:
371 + *
372 + * dentry->d_lock (used to keep d_move() away from dentry->d_parent)
373 + * iprune_sem (synchronize shrink_icache_memory())
374 + * inode_lock (protects the super_block->s_inodes list)
375 + * inode->inotify_sem (protects inode->inotify_watches and watches->i_list)
376 + * inotify_dev->sem (protects inotify_device and watches->d_list)
377 + */
378 +
379 +/*
380 + * Lifetimes of the three main data structures--inotify_device, inode, and
381 + * inotify_watch--are managed by reference count.
382 + *
383 + * inotify_device: Lifetime is from open until release. Additional references
384 + * can bump the count via get_inotify_dev() and drop the count via
385 + * put_inotify_dev().
386 + *
387 + * inotify_watch: Lifetime is from create_watch() to destory_watch().
388 + * Additional references can bump the count via get_inotify_watch() and drop
389 + * the count via put_inotify_watch().
390 + *
391 + * inode: Pinned so long as the inode is associated with a watch, from
392 + * create_watch() to put_inotify_watch().
393 + */
394 +
395 +/*
396 + * struct inotify_device - represents an open instance of an inotify device
397 + *
398 + * This structure is protected by the semaphore 'sem'.
399 + */
400 +struct inotify_device {
401 + wait_queue_head_t wq; /* wait queue for i/o */
402 + struct idr idr; /* idr mapping wd -> watch */
403 + struct semaphore sem; /* protects this bad boy */
404 + struct list_head events; /* list of queued events */
405 + struct list_head watches; /* list of watches */
406 + atomic_t count; /* reference count */
407 + struct user_struct *user; /* user who opened this dev */
408 + unsigned int queue_size; /* size of the queue (bytes) */
409 + unsigned int event_count; /* number of pending events */
410 + unsigned int max_events; /* maximum number of events */
411 +};
412 +
413 +/*
414 + * struct inotify_kernel_event - An intofiy event, originating from a watch and
415 + * queued for user-space. A list of these is attached to each instance of the
416 + * device. In read(), this list is walked and all events that can fit in the
417 + * buffer are returned.
418 + *
419 + * Protected by dev->sem of the device in which we are queued.
420 + */
421 +struct inotify_kernel_event {
422 + struct inotify_event event; /* the user-space event */
423 + struct list_head list; /* entry in inotify_device's list */
424 + char *name; /* filename, if any */
425 +};
426 +
427 +/*
428 + * struct inotify_watch - represents a watch request on a specific inode
429 + *
430 + * d_list is protected by dev->sem of the associated watch->dev.
431 + * i_list and mask are protected by inode->inotify_sem of the associated inode.
432 + * dev, inode, and wd are never written to once the watch is created.
433 + */
434 +struct inotify_watch {
435 + struct list_head d_list; /* entry in inotify_device's list */
436 + struct list_head i_list; /* entry in inode's list */
437 + atomic_t count; /* reference count */
438 + struct inotify_device *dev; /* associated device */
439 + struct inode *inode; /* associated inode */
440 + s32 wd; /* watch descriptor */
441 + u32 mask; /* event mask for this watch */
442 +};
443 +
444 +static ssize_t show_max_queued_events(struct class_device *class, char *buf)
445 +{
446 + return sprintf(buf, "%d\n", max_queued_events);
447 +}
448 +
449 +static ssize_t store_max_queued_events(struct class_device *class,
450 + const char *buf, size_t count)
451 +{
452 + unsigned int max;
453 +
454 + if (sscanf(buf, "%u", &max) > 0 && max > 0) {
455 + max_queued_events = max;
456 + return strlen(buf);
457 + }
458 + return -EINVAL;
459 +}
460 +
461 +static ssize_t show_max_user_devices(struct class_device *class, char *buf)
462 +{
463 + return sprintf(buf, "%d\n", max_user_devices);
464 +}
465 +
466 +static ssize_t store_max_user_devices(struct class_device *class,
467 + const char *buf, size_t count)
468 +{
469 + int max;
470 +
471 + if (sscanf(buf, "%d", &max) > 0 && max > 0) {
472 + max_user_devices = max;
473 + return strlen(buf);
474 + }
475 + return -EINVAL;
476 +}
477 +
478 +static ssize_t show_max_user_watches(struct class_device *class, char *buf)
479 +{
480 + return sprintf(buf, "%d\n", max_user_watches);
481 +}
482 +
483 +static ssize_t store_max_user_watches(struct class_device *class,
484 + const char *buf, size_t count)
485 +{
486 + int max;
487 +
488 + if (sscanf(buf, "%d", &max) > 0 && max > 0) {
489 + max_user_watches = max;
490 + return strlen(buf);
491 + }
492 + return -EINVAL;
493 +}
494 +
495 +static CLASS_DEVICE_ATTR(max_queued_events, S_IRUGO | S_IWUSR,
496 + show_max_queued_events, store_max_queued_events);
497 +static CLASS_DEVICE_ATTR(max_user_devices, S_IRUGO | S_IWUSR,
498 + show_max_user_devices, store_max_user_devices);
499 +static CLASS_DEVICE_ATTR(max_user_watches, S_IRUGO | S_IWUSR,
500 + show_max_user_watches, store_max_user_watches);
501 +
502 +static inline void get_inotify_dev(struct inotify_device *dev)
503 +{
504 + atomic_inc(&dev->count);
505 +}
506 +
507 +static inline void put_inotify_dev(struct inotify_device *dev)
508 +{
509 + if (atomic_dec_and_test(&dev->count)) {
510 + atomic_dec(&dev->user->inotify_devs);
511 + free_uid(dev->user);
512 + kfree(dev);
513 + }
514 +}
515 +
516 +static inline void get_inotify_watch(struct inotify_watch *watch)
517 +{
518 + atomic_inc(&watch->count);
519 +}
520 +
521 +/*
522 + * put_inotify_watch - decrements the ref count on a given watch. cleans up
523 + * the watch and its references if the count reaches zero.
524 + */
525 +static inline void put_inotify_watch(struct inotify_watch *watch)
526 +{
527 + if (atomic_dec_and_test(&watch->count)) {
528 + put_inotify_dev(watch->dev);
529 + iput(watch->inode);
530 + kmem_cache_free(watch_cachep, watch);
531 + }
532 +}
533 +
534 +/*
535 + * kernel_event - create a new kernel event with the given parameters
536 + *
537 + * This function can sleep.
538 + */
539 +static struct inotify_kernel_event * kernel_event(s32 wd, u32 mask, u32 cookie,
540 + const char *name)
541 +{
542 + struct inotify_kernel_event *kevent;
543 +
544 + kevent = kmem_cache_alloc(event_cachep, GFP_KERNEL);
545 + if (unlikely(!kevent))
546 + return NULL;
547 +
548 + /* we hand this out to user-space, so zero it just in case */
549 + memset(&kevent->event, 0, sizeof(struct inotify_event));
550 +
551 + kevent->event.wd = wd;
552 + kevent->event.mask = mask;
553 + kevent->event.cookie = cookie;
554 +
555 + INIT_LIST_HEAD(&kevent->list);
556 +
557 + if (name) {
558 + size_t len, rem, event_size = sizeof(struct inotify_event);
559 +
560 + /*
561 + * We need to pad the filename so as to properly align an
562 + * array of inotify_event structures. Because the structure is
563 + * small and the common case is a small filename, we just round
564 + * up to the next multiple of the structure's sizeof. This is
565 + * simple and safe for all architectures.
566 + */
567 + len = strlen(name) + 1;
568 + rem = event_size - len;
569 + if (len > event_size) {
570 + rem = event_size - (len % event_size);
571 + if (len % event_size == 0)
572 + rem = 0;
573 + }
574 +
575 + kevent->name = kmalloc(len + rem, GFP_KERNEL);
576 + if (unlikely(!kevent->name)) {
577 + kmem_cache_free(event_cachep, kevent);
578 + return NULL;
579 + }
580 + memcpy(kevent->name, name, len);
581 + if (rem)
582 + memset(kevent->name + len, 0, rem);
583 + kevent->event.len = len + rem;
584 + } else {
585 + kevent->event.len = 0;
586 + kevent->name = NULL;
587 + }
588 +
589 + return kevent;
590 +}
591 +
592 +/*
593 + * inotify_dev_get_event - return the next event in the given dev's queue
594 + *
595 + * Caller must hold dev->sem.
596 + */
597 +static inline struct inotify_kernel_event *
598 +inotify_dev_get_event(struct inotify_device *dev)
599 +{
600 + return list_entry(dev->events.next, struct inotify_kernel_event, list);
601 +}
602 +
603 +/*
604 + * inotify_dev_queue_event - add a new event to the given device
605 + *
606 + * Caller must hold dev->sem. Can sleep (calls kernel_event()).
607 + */
608 +static void inotify_dev_queue_event(struct inotify_device *dev,
609 + struct inotify_watch *watch, u32 mask,
610 + u32 cookie, const char *name)
611 +{
612 + struct inotify_kernel_event *kevent, *last;
613 +
614 + /* coalescing: drop this event if it is a dupe of the previous */
615 + last = inotify_dev_get_event(dev);
616 + if (last && last->event.mask == mask && last->event.wd == watch->wd &&
617 + last->event.cookie == cookie) {
618 + const char *lastname = last->name;
619 +
620 + if (!name && !lastname)
621 + return;
622 + if (name && lastname && !strcmp(lastname, name))
623 + return;
624 + }
625 +
626 + /* the queue overflowed and we already sent the Q_OVERFLOW event */
627 + if (unlikely(dev->event_count > dev->max_events))
628 + return;
629 +
630 + /* if the queue overflows, we need to notify user space */
631 + if (unlikely(dev->event_count == dev->max_events))
632 + kevent = kernel_event(-1, IN_Q_OVERFLOW, cookie, NULL);
633 + else
634 + kevent = kernel_event(watch->wd, mask, cookie, name);
635 +
636 + if (unlikely(!kevent))
637 + return;
638 +
639 + /* queue the event and wake up anyone waiting */
640 + dev->event_count++;
641 + dev->queue_size += sizeof(struct inotify_event) + kevent->event.len;
642 + list_add_tail(&kevent->list, &dev->events);
643 + wake_up_interruptible(&dev->wq);
644 +}
645 +
646 +/*
647 + * remove_kevent - cleans up and ultimately frees the given kevent
648 + *
649 + * Caller must hold dev->sem.
650 + */
651 +static void remove_kevent(struct inotify_device *dev,
652 + struct inotify_kernel_event *kevent)
653 +{
654 + list_del(&kevent->list);
655 +
656 + dev->event_count--;
657 + dev->queue_size -= sizeof(struct inotify_event) + kevent->event.len;
658 +
659 + kfree(kevent->name);
660 + kmem_cache_free(event_cachep, kevent);
661 +}
662 +
663 +/*
664 + * inotify_dev_event_dequeue - destroy an event on the given device
665 + *
666 + * Caller must hold dev->sem.
667 + */
668 +static void inotify_dev_event_dequeue(struct inotify_device *dev)
669 +{
670 + if (!list_empty(&dev->events)) {
671 + struct inotify_kernel_event *kevent;
672 + kevent = inotify_dev_get_event(dev);
673 + remove_kevent(dev, kevent);
674 + }
675 +}
676 +
677 +/*
678 + * inotify_dev_get_wd - returns the next WD for use by the given dev
679 + *
680 + * Callers must hold dev->sem. This function can sleep.
681 + */
682 +static int inotify_dev_get_wd(struct inotify_device *dev,
683 + struct inotify_watch *watch)
684 +{
685 + int ret;
686 +
687 + do {
688 + if (unlikely(!idr_pre_get(&dev->idr, GFP_KERNEL)))
689 + return -ENOSPC;
690 + ret = idr_get_new(&dev->idr, watch, &watch->wd);
691 + } while (ret == -EAGAIN);
692 +
693 + return ret;
694 +}
695 +
696 +/*
697 + * create_watch - creates a watch on the given device.
698 + *
699 + * Callers must hold dev->sem. Calls inotify_dev_get_wd() so may sleep.
700 + * Both 'dev' and 'inode' (by way of nameidata) need to be pinned.
701 + */
702 +static struct inotify_watch *create_watch(struct inotify_device *dev,
703 + u32 mask, struct inode *inode)
704 +{
705 + struct inotify_watch *watch;
706 + int ret;
707 +
708 + if (atomic_read(&dev->user->inotify_watches) >= max_user_watches)
709 + return ERR_PTR(-ENOSPC);
710 +
711 + watch = kmem_cache_alloc(watch_cachep, GFP_KERNEL);
712 + if (unlikely(!watch))
713 + return ERR_PTR(-ENOMEM);
714 +
715 + ret = inotify_dev_get_wd(dev, watch);
716 + if (unlikely(ret)) {
717 + kmem_cache_free(watch_cachep, watch);
718 + return ERR_PTR(ret);
719 + }
720 +
721 + watch->mask = mask;
722 + atomic_set(&watch->count, 0);
723 + INIT_LIST_HEAD(&watch->d_list);
724 + INIT_LIST_HEAD(&watch->i_list);
725 +
726 + /* save a reference to device and bump the count to make it official */
727 + get_inotify_dev(dev);
728 + watch->dev = dev;
729 +
730 + /*
731 + * Save a reference to the inode and bump the ref count to make it
732 + * official. We hold a reference to nameidata, which makes this safe.
733 + */
734 + watch->inode = igrab(inode);
735 +
736 + /* bump our own count, corresponding to our entry in dev->watches */
737 + get_inotify_watch(watch);
738 +
739 + atomic_inc(&dev->user->inotify_watches);
740 +
741 + return watch;
742 +}
743 +
744 +/*
745 + * inotify_find_dev - find the watch associated with the given inode and dev
746 + *
747 + * Callers must hold inode->inotify_sem.
748 + */
749 +static struct inotify_watch *inode_find_dev(struct inode *inode,
750 + struct inotify_device *dev)
751 +{
752 + struct inotify_watch *watch;
753 +
754 + list_for_each_entry(watch, &inode->inotify_watches, i_list) {
755 + if (watch->dev == dev)
756 + return watch;
757 + }
758 +
759 + return NULL;
760 +}
761 +
762 +/*
763 + * inotify_dev_is_watching_inode - is this device watching this inode?
764 + *
765 + * Callers must hold dev->sem.
766 + */
767 +static inline int inotify_dev_is_watching_inode(struct inotify_device *dev,
768 + struct inode *inode)
769 +{
770 + struct inotify_watch *watch;
771 +
772 + list_for_each_entry(watch, &dev->watches, d_list) {
773 + if (watch->inode == inode)
774 + return 1;
775 + }
776 +
777 + return 0;
778 +}
779 +
780 +/*
781 + * remove_watch_no_event - remove_watch() without the IN_IGNORED event.
782 + */
783 +static void remove_watch_no_event(struct inotify_watch *watch,
784 + struct inotify_device *dev)
785 +{
786 + list_del(&watch->i_list);
787 + list_del(&watch->d_list);
788 +
789 + atomic_dec(&dev->user->inotify_watches);
790 + idr_remove(&dev->idr, watch->wd);
791 + put_inotify_watch(watch);
792 +}
793 +
794 +/*
795 + * remove_watch - Remove a watch from both the device and the inode. Sends
796 + * the IN_IGNORED event to the given device signifying that the inode is no
797 + * longer watched.
798 + *
799 + * Callers must hold both inode->inotify_sem and dev->sem. We drop a
800 + * reference to the inode before returning.
801 + *
802 + * The inode is not iput() so as to remain atomic. If the inode needs to be
803 + * iput(), the call returns one. Otherwise, it returns zero.
804 + */
805 +static void remove_watch(struct inotify_watch *watch,struct inotify_device *dev)
806 +{
807 + inotify_dev_queue_event(dev, watch, IN_IGNORED, 0, NULL);
808 + remove_watch_no_event(watch, dev);
809 +}
810 +
811 +/* Kernel API */
812 +
813 +/**
814 + * inotify_inode_queue_event - queue an event to all watches on this inode
815 + * @inode: inode event is originating from
816 + * @mask: event mask describing this event
817 + * @cookie: cookie for synchronization, or zero
818 + * @name: filename, if any
819 + */
820 +void inotify_inode_queue_event(struct inode *inode, u32 mask, u32 cookie,
821 + const char *name)
822 +{
823 + struct inotify_watch *watch, *next;
824 +
825 + down(&inode->inotify_sem);
826 + list_for_each_entry_safe(watch, next, &inode->inotify_watches, i_list) {
827 + u32 watch_mask = watch->mask;
828 + if (watch_mask & mask) {
829 + struct inotify_device *dev = watch->dev;
830 + get_inotify_watch(watch);
831 + down(&dev->sem);
832 + inotify_dev_queue_event(dev, watch, mask, cookie, name);
833 + if (watch_mask & IN_ONESHOT)
834 + remove_watch_no_event(watch, dev);
835 + up(&dev->sem);
836 + put_inotify_watch(watch);
837 + }
838 + }
839 + up(&inode->inotify_sem);
840 +}
841 +EXPORT_SYMBOL_GPL(inotify_inode_queue_event);
842 +
843 +/**
844 + * inotify_dentry_parent_queue_event - queue an event to a dentry's parent
845 + * @dentry: the dentry in question, we queue against this dentry's parent
846 + * @mask: event mask describing this event
847 + * @cookie: cookie for synchronization, or zero
848 + * @name: filename, if any
849 + */
850 +void inotify_dentry_parent_queue_event(struct dentry *dentry, u32 mask,
851 + u32 cookie, const char *name)
852 +{
853 + struct dentry *parent;
854 + struct inode *inode;
855 +
856 + spin_lock(&dentry->d_lock);
857 + parent = dentry->d_parent;
858 + inode = parent->d_inode;
859 +
860 + /* We intentially do the list_empty() lockless. The race is fine. */
861 + if (!list_empty(&inode->inotify_watches)) {
862 + dget(parent);
863 + spin_unlock(&dentry->d_lock);
864 + inotify_inode_queue_event(inode, mask, cookie, name);
865 + dput(parent);
866 + } else
867 + spin_unlock(&dentry->d_lock);
868 +}
869 +EXPORT_SYMBOL_GPL(inotify_dentry_parent_queue_event);
870 +
871 +/**
872 + * inotify_get_cookie - return a unique cookie for use in synchronizing events.
873 + */
874 +u32 inotify_get_cookie(void)
875 +{
876 + return atomic_inc_return(&inotify_cookie);
877 +}
878 +EXPORT_SYMBOL_GPL(inotify_get_cookie);
879 +
880 +/**
881 + * inotify_unmount_inodes - an sb is unmounting. handle any watched inodes.
882 + * @list: list of inodes being unmounted (sb->s_inodes)
883 + *
884 + * Called with inode_lock held, protecting the unmounting super block's list
885 + * of inodes, and with iprune_sem held, keeping shrink_icache_memory() at bay.
886 + * We temporarily drop inode_lock, however, and CAN block.
887 + */
888 +void inotify_unmount_inodes(struct list_head *list)
889 +{
890 + struct inode *inode, *next_i;
891 +
892 + list_for_each_entry_safe(inode, next_i, list, i_sb_list) {
893 + struct inotify_watch *watch, *next_w;
894 + struct list_head *watches;
895 +
896 + /* In case the remove_watch() drops a reference */
897 + __iget(inode);
898 +
899 + /*
900 + * We can safely drop inode_lock here because the per-sb list
901 + * of inodes must not change during unmount and iprune_sem
902 + * keeps shrink_icache_memory() away.
903 + */
904 + spin_unlock(&inode_lock);
905 +
906 + /* for each watch, send IN_UNMOUNT and then remove it */
907 + down(&inode->inotify_sem);
908 + watches = &inode->inotify_watches;
909 + list_for_each_entry_safe(watch, next_w, watches, i_list) {
910 + struct inotify_device *dev = watch->dev;
911 + down(&dev->sem);
912 + inotify_dev_queue_event(dev, watch, IN_UNMOUNT,0,NULL);
913 + remove_watch(watch, dev);
914 + up(&dev->sem);
915 + }
916 + up(&inode->inotify_sem);
917 + iput(inode);
918 +
919 + spin_lock(&inode_lock);
920 + }
921 +}
922 +EXPORT_SYMBOL_GPL(inotify_unmount_inodes);
923 +
924 +/**
925 + * inotify_inode_is_dead - an inode has been deleted, cleanup any watches
926 + * @inode: inode that is about to be removed
927 + */
928 +void inotify_inode_is_dead(struct inode *inode)
929 +{
930 + struct inotify_watch *watch, *next;
931 +
932 + down(&inode->inotify_sem);
933 + list_for_each_entry_safe(watch, next, &inode->inotify_watches, i_list) {
934 + struct inotify_device *dev = watch->dev;
935 + down(&dev->sem);
936 + remove_watch(watch, dev);
937 + up(&dev->sem);
938 + }
939 + up(&inode->inotify_sem);
940 +}
941 +EXPORT_SYMBOL_GPL(inotify_inode_is_dead);
942 +
943 +/* Device Interface */
944 +
945 +static unsigned int inotify_poll(struct file *file, poll_table *wait)
946 +{
947 + struct inotify_device *dev = file->private_data;
948 + int ret = 0;
949 +
950 + poll_wait(file, &dev->wq, wait);
951 + down(&dev->sem);
952 + if (!list_empty(&dev->events))
953 + ret = POLLIN | POLLRDNORM;
954 + up(&dev->sem);
955 +
956 + return ret;
957 +}
958 +
959 +static ssize_t inotify_read(struct file *file, char __user *buf,
960 + size_t count, loff_t *pos)
961 +{
962 + size_t event_size = sizeof (struct inotify_event);
963 + struct inotify_device *dev;
964 + char __user *start;
965 + int ret;
966 + DEFINE_WAIT(wait);
967 +
968 + start = buf;
969 + dev = file->private_data;
970 +
971 + while (1) {
972 + int events;
973 +
974 + prepare_to_wait(&dev->wq, &wait, TASK_INTERRUPTIBLE);
975 +
976 + down(&dev->sem);
977 + events = !list_empty(&dev->events);
978 + up(&dev->sem);
979 + if (events) {
980 + ret = 0;
981 + break;
982 + }
983 +
984 + if (file->f_flags & O_NONBLOCK) {
985 + ret = -EAGAIN;
986 + break;
987 + }
988 +
989 + if (signal_pending(current)) {
990 + ret = -EINTR;
991 + break;
992 + }
993 +
994 + schedule();
995 + }
996 +
997 + finish_wait(&dev->wq, &wait);
998 + if (ret)
999 + return ret;
1000 +
1001 + down(&dev->sem);
1002 + while (1) {
1003 + struct inotify_kernel_event *kevent;
1004 +
1005 + ret = buf - start;
1006 + if (list_empty(&dev->events))
1007 + break;
1008 +
1009 + kevent = inotify_dev_get_event(dev);
1010 + if (event_size + kevent->event.len > count)
1011 + break;
1012 +
1013 + if (copy_to_user(buf, &kevent->event, event_size)) {
1014 + ret = -EFAULT;
1015 + break;
1016 + }
1017 + buf += event_size;
1018 + count -= event_size;
1019 +
1020 + if (kevent->name) {
1021 + if (copy_to_user(buf, kevent->name, kevent->event.len)){
1022 + ret = -EFAULT;
1023 + break;
1024 + }
1025 + buf += kevent->event.len;
1026 + count -= kevent->event.len;
1027 + }
1028 +
1029 + remove_kevent(dev, kevent);
1030 + }
1031 + up(&dev->sem);
1032 +
1033 + return ret;
1034 +}
1035 +
1036 +static int inotify_open(struct inode *inode, struct file *file)
1037 +{
1038 + struct inotify_device *dev;
1039 + struct user_struct *user;
1040 + int ret;
1041 +
1042 + user = get_uid(current->user);
1043 +
1044 + if (unlikely(atomic_read(&user->inotify_devs) >= max_user_devices)) {
1045 + ret = -EMFILE;
1046 + goto out_err;
1047 + }
1048 +
1049 + dev = kmalloc(sizeof(struct inotify_device), GFP_KERNEL);
1050 + if (unlikely(!dev)) {
1051 + ret = -ENOMEM;
1052 + goto out_err;
1053 + }
1054 +
1055 + idr_init(&dev->idr);
1056 + INIT_LIST_HEAD(&dev->events);
1057 + INIT_LIST_HEAD(&dev->watches);
1058 + init_waitqueue_head(&dev->wq);
1059 + sema_init(&dev->sem, 1);
1060 + dev->event_count = 0;
1061 + dev->queue_size = 0;
1062 + dev->max_events = max_queued_events;
1063 + dev->user = user;
1064 + atomic_set(&dev->count, 0);
1065 +
1066 + get_inotify_dev(dev);
1067 + atomic_inc(&user->inotify_devs);
1068 +
1069 + file->private_data = dev;
1070 +
1071 + nonseekable_open(inode, file);
1072 +
1073 + return 0;
1074 +out_err:
1075 + free_uid(user);
1076 + return ret;
1077 +}
1078 +
1079 +static int inotify_release(struct inode *ignored, struct file *file)
1080 +{
1081 + struct inotify_device *dev = file->private_data;
1082 +
1083 + /*
1084 + * Destroy all of the watches on this device. Unfortunately, not very
1085 + * pretty. We cannot do a simple iteration over the list, because we
1086 + * do not know the inode until we iterate to the watch. But we need to
1087 + * hold inode->inotify_sem before dev->sem. The following works.
1088 + */
1089 + while (1) {
1090 + struct inotify_watch *watch;
1091 + struct list_head *watches;
1092 + struct inode *inode;
1093 +
1094 + down(&dev->sem);
1095 + watches = &dev->watches;
1096 + if (list_empty(watches)) {
1097 + up(&dev->sem);
1098 + break;
1099 + }
1100 + watch = list_entry(watches->next, struct inotify_watch, d_list);
1101 + get_inotify_watch(watch);
1102 + up(&dev->sem);
1103 +
1104 + inode = watch->inode;
1105 + down(&inode->inotify_sem);
1106 + down(&dev->sem);
1107 + remove_watch_no_event(watch, dev);
1108 + up(&dev->sem);
1109 + up(&inode->inotify_sem);
1110 + put_inotify_watch(watch);
1111 + }
1112 +
1113 + /* destroy all of the events on this device */
1114 + down(&dev->sem);
1115 + while (!list_empty(&dev->events))
1116 + inotify_dev_event_dequeue(dev);
1117 + up(&dev->sem);
1118 +
1119 + /* free this device: the put matching the get in inotify_open() */
1120 + put_inotify_dev(dev);
1121 +
1122 + return 0;
1123 +}
1124 +
1125 +static int inotify_add_watch(struct inotify_device *dev, int fd, u32 mask)
1126 +{
1127 + struct inotify_watch *watch, *old;
1128 + struct inode *inode;
1129 + struct file *filp;
1130 + int ret;
1131 +
1132 + filp = fget(fd);
1133 + if (!filp)
1134 + return -EBADF;
1135 + inode = filp->f_dentry->d_inode;
1136 +
1137 + down(&inode->inotify_sem);
1138 + down(&dev->sem);
1139 +
1140 + /* don't let user-space set invalid bits: we don't want flags set */
1141 + mask &= IN_ALL_EVENTS;
1142 + if (!mask) {
1143 + ret = -EINVAL;
1144 + goto out;
1145 + }
1146 +
1147 + /*
1148 + * Handle the case of re-adding a watch on an (inode,dev) pair that we
1149 + * are already watching. We just update the mask and return its wd.
1150 + */
1151 + old = inode_find_dev(inode, dev);
1152 + if (unlikely(old)) {
1153 + old->mask = mask;
1154 + ret = old->wd;
1155 + goto out;
1156 + }
1157 +
1158 + watch = create_watch(dev, mask, inode);
1159 + if (unlikely(IS_ERR(watch))) {
1160 + ret = PTR_ERR(watch);
1161 + goto out;
1162 + }
1163 +
1164 + /* Add the watch to the device's and the inode's list */
1165 + list_add(&watch->d_list, &dev->watches);
1166 + list_add(&watch->i_list, &inode->inotify_watches);
1167 + ret = watch->wd;
1168 +
1169 +out:
1170 + up(&dev->sem);
1171 + up(&inode->inotify_sem);
1172 + fput(filp);
1173 +
1174 + return ret;
1175 +}
1176 +
1177 +/*
1178 + * inotify_ignore - handle the INOTIFY_IGNORE ioctl, asking that a given wd be
1179 + * removed from the device.
1180 + *
1181 + * Can sleep.
1182 + */
1183 +static int inotify_ignore(struct inotify_device *dev, s32 wd)
1184 +{
1185 + struct inotify_watch *watch;
1186 + struct inode *inode;
1187 +
1188 + down(&dev->sem);
1189 + watch = idr_find(&dev->idr, wd);
1190 + if (unlikely(!watch)) {
1191 + up(&dev->sem);
1192 + return -EINVAL;
1193 + }
1194 + get_inotify_watch(watch);
1195 + inode = watch->inode;
1196 + up(&dev->sem);
1197 +
1198 + down(&inode->inotify_sem);
1199 + down(&dev->sem);
1200 +
1201 + /* make sure that we did not race */
1202 + watch = idr_find(&dev->idr, wd);
1203 + if (likely(watch))
1204 + remove_watch(watch, dev);
1205 +
1206 + up(&dev->sem);
1207 + up(&inode->inotify_sem);
1208 + put_inotify_watch(watch);
1209 +
1210 + return 0;
1211 +}
1212 +
1213 +static long inotify_ioctl(struct file *file, unsigned int cmd,
1214 + unsigned long arg)
1215 +{
1216 + struct inotify_device *dev;
1217 + struct inotify_watch_request request;
1218 + void __user *p;
1219 + int ret = -ENOTTY;
1220 + s32 wd;
1221 +
1222 + dev = file->private_data;
1223 + p = (void __user *) arg;
1224 +
1225 + switch (cmd) {
1226 + case INOTIFY_WATCH:
1227 + if (unlikely(copy_from_user(&request, p, sizeof (request)))) {
1228 + ret = -EFAULT;
1229 + break;
1230 + }
1231 + ret = inotify_add_watch(dev, request.fd, request.mask);
1232 + break;
1233 + case INOTIFY_IGNORE:
1234 + if (unlikely(get_user(wd, (int __user *) p))) {
1235 + ret = -EFAULT;
1236 + break;
1237 + }
1238 + ret = inotify_ignore(dev, wd);
1239 + break;
1240 + case FIONREAD:
1241 + ret = put_user(dev->queue_size, (int __user *) p);
1242 + break;
1243 + }
1244 +
1245 + return ret;
1246 +}
1247 +
1248 +static struct file_operations inotify_fops = {
1249 + .owner = THIS_MODULE,
1250 + .poll = inotify_poll,
1251 + .read = inotify_read,
1252 + .open = inotify_open,
1253 + .release = inotify_release,
1254 + .unlocked_ioctl = inotify_ioctl,
1255 + .compat_ioctl = inotify_ioctl,
1256 +};
1257 +
1258 +static struct miscdevice inotify_device = {
1259 + .minor = MISC_DYNAMIC_MINOR,
1260 + .name = "inotify",
1261 + .fops = &inotify_fops,
1262 +};
1263 +
1264 +/*
1265 + * inotify_init - Our initialization function. Note that we cannnot return
1266 + * error because we have compiled-in VFS hooks. So an (unlikely) failure here
1267 + * must result in panic().
1268 + */
1269 +static int __init inotify_init(void)
1270 +{
1271 + struct class_device *class;
1272 + int ret;
1273 +
1274 + ret = misc_register(&inotify_device);
1275 + if (unlikely(ret))
1276 + panic("inotify: misc_register returned %d\n", ret);
1277 +
1278 + max_queued_events = 8192;
1279 + max_user_devices = 128;
1280 + max_user_watches = 8192;
1281 +
1282 + class = inotify_device.class;
1283 + class_device_create_file(class, &class_device_attr_max_queued_events);
1284 + class_device_create_file(class, &class_device_attr_max_user_devices);
1285 + class_device_create_file(class, &class_device_attr_max_user_watches);
1286 +
1287 + atomic_set(&inotify_cookie, 0);
1288 +
1289 + watch_cachep = kmem_cache_create("inotify_watch_cache",
1290 + sizeof(struct inotify_watch),
1291 + 0, SLAB_PANIC, NULL, NULL);
1292 + event_cachep = kmem_cache_create("inotify_event_cache",
1293 + sizeof(struct inotify_kernel_event),
1294 + 0, SLAB_PANIC, NULL, NULL);
1295 +
1296 + printk(KERN_INFO "inotify device minor=%d\n", inotify_device.minor);
1297 +
1298 + return 0;
1299 +}
1300 +
1301 +module_init(inotify_init);
1302 diff -urN linux-2.6.12-rc6/fs/Kconfig linux/fs/Kconfig
1303 --- linux-2.6.12-rc6/fs/Kconfig 2005-06-07 15:47:52.000000000 -0400
1304 +++ linux/fs/Kconfig 2005-06-07 15:49:02.000000000 -0400
1305 @@ -339,6 +339,19 @@
1306 If you don't know whether you need it, then you don't need it:
1307 answer N.
1308
1309 +config INOTIFY
1310 + bool "Inotify file change notification support"
1311 + default y
1312 + ---help---
1313 + Say Y here to enable inotify support and the /dev/inotify character
1314 + device. Inotify is a file change notification system and a
1315 + replacement for dnotify. Inotify fixes numerous shortcomings in
1316 + dnotify and introduces several new features. It allows monitoring
1317 + of both files and directories via a single open fd. Multiple file
1318 + events are supported.
1319 +
1320 + If unsure, say Y.
1321 +
1322 config QUOTA
1323 bool "Quota support"
1324 help
1325 diff -urN linux-2.6.12-rc6/fs/Makefile linux/fs/Makefile
1326 --- linux-2.6.12-rc6/fs/Makefile 2005-03-02 02:38:10.000000000 -0500
1327 +++ linux/fs/Makefile 2005-06-07 15:49:02.000000000 -0400
1328 @@ -11,6 +11,7 @@
1329 attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \
1330 seq_file.o xattr.o libfs.o fs-writeback.o mpage.o direct-io.o \
1331
1332 +obj-$(CONFIG_INOTIFY) += inotify.o
1333 obj-$(CONFIG_EPOLL) += eventpoll.o
1334 obj-$(CONFIG_COMPAT) += compat.o
1335
1336 diff -urN linux-2.6.12-rc6/fs/namei.c linux/fs/namei.c
1337 --- linux-2.6.12-rc6/fs/namei.c 2005-06-07 15:47:52.000000000 -0400
1338 +++ linux/fs/namei.c 2005-06-07 15:49:02.000000000 -0400
1339 @@ -21,7 +21,7 @@
1340 #include <linux/namei.h>
1341 #include <linux/quotaops.h>
1342 #include <linux/pagemap.h>
1343 -#include <linux/dnotify.h>
1344 +#include <linux/fsnotify.h>
1345 #include <linux/smp_lock.h>
1346 #include <linux/personality.h>
1347 #include <linux/security.h>
1348 @@ -1296,7 +1296,7 @@
1349 DQUOT_INIT(dir);
1350 error = dir->i_op->create(dir, dentry, mode, nd);
1351 if (!error) {
1352 - inode_dir_notify(dir, DN_CREATE);
1353 + fsnotify_create(dir, dentry->d_name.name);
1354 security_inode_post_create(dir, dentry, mode);
1355 }
1356 return error;
1357 @@ -1602,7 +1602,7 @@
1358 DQUOT_INIT(dir);
1359 error = dir->i_op->mknod(dir, dentry, mode, dev);
1360 if (!error) {
1361 - inode_dir_notify(dir, DN_CREATE);
1362 + fsnotify_create(dir, dentry->d_name.name);
1363 security_inode_post_mknod(dir, dentry, mode, dev);
1364 }
1365 return error;
1366 @@ -1675,7 +1675,7 @@
1367 DQUOT_INIT(dir);
1368 error = dir->i_op->mkdir(dir, dentry, mode);
1369 if (!error) {
1370 - inode_dir_notify(dir, DN_CREATE);
1371 + fsnotify_mkdir(dir, dentry->d_name.name);
1372 security_inode_post_mkdir(dir,dentry, mode);
1373 }
1374 return error;
1375 @@ -1766,7 +1766,7 @@
1376 }
1377 up(&dentry->d_inode->i_sem);
1378 if (!error) {
1379 - inode_dir_notify(dir, DN_DELETE);
1380 + fsnotify_rmdir(dentry, dentry->d_inode, dir);
1381 d_delete(dentry);
1382 }
1383 dput(dentry);
1384 @@ -1839,9 +1839,10 @@
1385
1386 /* We don't d_delete() NFS sillyrenamed files--they still exist. */
1387 if (!error && !(dentry->d_flags & DCACHE_NFSFS_RENAMED)) {
1388 + fsnotify_unlink(dentry, dir);
1389 d_delete(dentry);
1390 - inode_dir_notify(dir, DN_DELETE);
1391 }
1392 +
1393 return error;
1394 }
1395
1396 @@ -1915,7 +1916,7 @@
1397 DQUOT_INIT(dir);
1398 error = dir->i_op->symlink(dir, dentry, oldname);
1399 if (!error) {
1400 - inode_dir_notify(dir, DN_CREATE);
1401 + fsnotify_create(dir, dentry->d_name.name);
1402 security_inode_post_symlink(dir, dentry, oldname);
1403 }
1404 return error;
1405 @@ -1988,7 +1989,7 @@
1406 error = dir->i_op->link(old_dentry, dir, new_dentry);
1407 up(&old_dentry->d_inode->i_sem);
1408 if (!error) {
1409 - inode_dir_notify(dir, DN_CREATE);
1410 + fsnotify_create(dir, new_dentry->d_name.name);
1411 security_inode_post_link(old_dentry, dir, new_dentry);
1412 }
1413 return error;
1414 @@ -2152,6 +2153,7 @@
1415 {
1416 int error;
1417 int is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
1418 + const char *old_name;
1419
1420 if (old_dentry->d_inode == new_dentry->d_inode)
1421 return 0;
1422 @@ -2173,18 +2175,18 @@
1423 DQUOT_INIT(old_dir);
1424 DQUOT_INIT(new_dir);
1425
1426 + old_name = fsnotify_oldname_init(old_dentry->d_name.name);
1427 +
1428 if (is_dir)
1429 error = vfs_rename_dir(old_dir,old_dentry,new_dir,new_dentry);
1430 else
1431 error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry);
1432 if (!error) {
1433 - if (old_dir == new_dir)
1434 - inode_dir_notify(old_dir, DN_RENAME);
1435 - else {
1436 - inode_dir_notify(old_dir, DN_DELETE);
1437 - inode_dir_notify(new_dir, DN_CREATE);
1438 - }
1439 + const char *new_name = old_dentry->d_name.name;
1440 + fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir);
1441 }
1442 + fsnotify_oldname_free(old_name);
1443 +
1444 return error;
1445 }
1446
1447 diff -urN linux-2.6.12-rc6/fs/nfsd/vfs.c linux/fs/nfsd/vfs.c
1448 --- linux-2.6.12-rc6/fs/nfsd/vfs.c 2005-06-07 15:47:52.000000000 -0400
1449 +++ linux/fs/nfsd/vfs.c 2005-06-07 15:49:02.000000000 -0400
1450 @@ -45,7 +45,7 @@
1451 #endif /* CONFIG_NFSD_V3 */
1452 #include <linux/nfsd/nfsfh.h>
1453 #include <linux/quotaops.h>
1454 -#include <linux/dnotify.h>
1455 +#include <linux/fsnotify.h>
1456 #ifdef CONFIG_NFSD_V4
1457 #include <linux/posix_acl.h>
1458 #include <linux/posix_acl_xattr.h>
1459 @@ -861,7 +861,7 @@
1460 nfsdstats.io_read += err;
1461 *count = err;
1462 err = 0;
1463 - dnotify_parent(file->f_dentry, DN_ACCESS);
1464 + fsnotify_access(file->f_dentry);
1465 } else
1466 err = nfserrno(err);
1467 out:
1468 @@ -917,7 +917,7 @@
1469 set_fs(oldfs);
1470 if (err >= 0) {
1471 nfsdstats.io_write += cnt;
1472 - dnotify_parent(file->f_dentry, DN_MODIFY);
1473 + fsnotify_modify(file->f_dentry);
1474 }
1475
1476 /* clear setuid/setgid flag after write */
1477 diff -urN linux-2.6.12-rc6/fs/open.c linux/fs/open.c
1478 --- linux-2.6.12-rc6/fs/open.c 2005-03-02 02:37:47.000000000 -0500
1479 +++ linux/fs/open.c 2005-06-07 15:49:02.000000000 -0400
1480 @@ -10,7 +10,7 @@
1481 #include <linux/file.h>
1482 #include <linux/smp_lock.h>
1483 #include <linux/quotaops.h>
1484 -#include <linux/dnotify.h>
1485 +#include <linux/fsnotify.h>
1486 #include <linux/module.h>
1487 #include <linux/slab.h>
1488 #include <linux/tty.h>
1489 @@ -944,9 +944,11 @@
1490 fd = get_unused_fd();
1491 if (fd >= 0) {
1492 struct file *f = filp_open(tmp, flags, mode);
1493 +
1494 error = PTR_ERR(f);
1495 if (IS_ERR(f))
1496 goto out_error;
1497 + fsnotify_open(f->f_dentry);
1498 fd_install(fd, f);
1499 }
1500 out:
1501 diff -urN linux-2.6.12-rc6/fs/read_write.c linux/fs/read_write.c
1502 --- linux-2.6.12-rc6/fs/read_write.c 2005-06-07 15:47:52.000000000 -0400
1503 +++ linux/fs/read_write.c 2005-06-07 15:49:02.000000000 -0400
1504 @@ -10,7 +10,7 @@
1505 #include <linux/file.h>
1506 #include <linux/uio.h>
1507 #include <linux/smp_lock.h>
1508 -#include <linux/dnotify.h>
1509 +#include <linux/fsnotify.h>
1510 #include <linux/security.h>
1511 #include <linux/module.h>
1512 #include <linux/syscalls.h>
1513 @@ -239,7 +239,7 @@
1514 else
1515 ret = do_sync_read(file, buf, count, pos);
1516 if (ret > 0) {
1517 - dnotify_parent(file->f_dentry, DN_ACCESS);
1518 + fsnotify_access(file->f_dentry);
1519 current->rchar += ret;
1520 }
1521 current->syscr++;
1522 @@ -287,7 +287,7 @@
1523 else
1524 ret = do_sync_write(file, buf, count, pos);
1525 if (ret > 0) {
1526 - dnotify_parent(file->f_dentry, DN_MODIFY);
1527 + fsnotify_modify(file->f_dentry);
1528 current->wchar += ret;
1529 }
1530 current->syscw++;
1531 @@ -523,9 +523,12 @@
1532 out:
1533 if (iov != iovstack)
1534 kfree(iov);
1535 - if ((ret + (type == READ)) > 0)
1536 - dnotify_parent(file->f_dentry,
1537 - (type == READ) ? DN_ACCESS : DN_MODIFY);
1538 + if ((ret + (type == READ)) > 0) {
1539 + if (type == READ)
1540 + fsnotify_access(file->f_dentry);
1541 + else
1542 + fsnotify_modify(file->f_dentry);
1543 + }
1544 return ret;
1545 Efault:
1546 ret = -EFAULT;
1547 diff -urN linux-2.6.12-rc6/fs/sysfs/file.c linux/fs/sysfs/file.c
1548 --- linux-2.6.12-rc6/fs/sysfs/file.c 2005-06-07 15:47:52.000000000 -0400
1549 +++ linux/fs/sysfs/file.c 2005-06-07 15:49:02.000000000 -0400
1550 @@ -3,7 +3,7 @@
1551 */
1552
1553 #include <linux/module.h>
1554 -#include <linux/dnotify.h>
1555 +#include <linux/fsnotify.h>
1556 #include <linux/kobject.h>
1557 #include <asm/uaccess.h>
1558 #include <asm/semaphore.h>
1559 @@ -389,9 +389,6 @@
1560 * sysfs_update_file - update the modified timestamp on an object attribute.
1561 * @kobj: object we're acting for.
1562 * @attr: attribute descriptor.
1563 - *
1564 - * Also call dnotify for the dentry, which lots of userspace programs
1565 - * use.
1566 */
1567 int sysfs_update_file(struct kobject * kobj, const struct attribute * attr)
1568 {
1569 @@ -406,7 +403,7 @@
1570 if (victim->d_inode &&
1571 (victim->d_parent->d_inode == dir->d_inode)) {
1572 victim->d_inode->i_mtime = CURRENT_TIME;
1573 - dnotify_parent(victim, DN_MODIFY);
1574 + fsnotify_modify(victim);
1575
1576 /**
1577 * Drop reference from initial sysfs_get_dentry().
1578 diff -urN linux-2.6.12-rc6/fs/xattr.c linux/fs/xattr.c
1579 --- linux-2.6.12-rc6/fs/xattr.c 2005-03-02 02:38:07.000000000 -0500
1580 +++ linux/fs/xattr.c 2005-06-07 15:49:02.000000000 -0400
1581 @@ -16,6 +16,7 @@
1582 #include <linux/security.h>
1583 #include <linux/syscalls.h>
1584 #include <linux/module.h>
1585 +#include <linux/fsnotify.h>
1586 #include <asm/uaccess.h>
1587
1588 /*
1589 @@ -57,8 +58,10 @@
1590 if (error)
1591 goto out;
1592 error = d->d_inode->i_op->setxattr(d, kname, kvalue, size, flags);
1593 - if (!error)
1594 + if (!error) {
1595 + fsnotify_xattr(d);
1596 security_inode_post_setxattr(d, kname, kvalue, size, flags);
1597 + }
1598 out:
1599 up(&d->d_inode->i_sem);
1600 }
1601 diff -urN linux-2.6.12-rc6/include/linux/fs.h linux/include/linux/fs.h
1602 --- linux-2.6.12-rc6/include/linux/fs.h 2005-06-07 15:47:53.000000000 -0400
1603 +++ linux/include/linux/fs.h 2005-06-07 15:49:02.000000000 -0400
1604 @@ -471,6 +471,11 @@
1605 struct dnotify_struct *i_dnotify; /* for directory notifications */
1606 #endif
1607
1608 +#ifdef CONFIG_INOTIFY
1609 + struct list_head inotify_watches; /* watches on this inode */
1610 + struct semaphore inotify_sem; /* protects the watches list */
1611 +#endif
1612 +
1613 unsigned long i_state;
1614 unsigned long dirtied_when; /* jiffies of first dirtying */
1615
1616 @@ -1369,7 +1374,6 @@
1617 extern int do_remount_sb(struct super_block *sb, int flags,
1618 void *data, int force);
1619 extern sector_t bmap(struct inode *, sector_t);
1620 -extern int setattr_mask(unsigned int);
1621 extern int notify_change(struct dentry *, struct iattr *);
1622 extern int permission(struct inode *, int, struct nameidata *);
1623 extern int generic_permission(struct inode *, int,
1624 diff -urN linux-2.6.12-rc6/include/linux/fsnotify.h linux/include/linux/fsnotify.h
1625 --- linux-2.6.12-rc6/include/linux/fsnotify.h 1969-12-31 19:00:00.000000000 -0500
1626 +++ linux/include/linux/fsnotify.h 2005-06-07 15:49:02.000000000 -0400
1627 @@ -0,0 +1,257 @@
1628 +#ifndef _LINUX_FS_NOTIFY_H
1629 +#define _LINUX_FS_NOTIFY_H
1630 +
1631 +/*
1632 + * include/linux/fsnotify.h - generic hooks for filesystem notification, to
1633 + * reduce in-source duplication from both dnotify and inotify.
1634 + *
1635 + * We don't compile any of this away in some complicated menagerie of ifdefs.
1636 + * Instead, we rely on the code inside to optimize away as needed.
1637 + *
1638 + * (C) Copyright 2005 Robert Love
1639 + */
1640 +
1641 +#ifdef __KERNEL__
1642 +
1643 +#include <linux/dnotify.h>
1644 +#include <linux/inotify.h>
1645 +
1646 +/*
1647 + * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
1648 + */
1649 +static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
1650 + const char *old_name, const char *new_name,
1651 + int isdir)
1652 +{
1653 + u32 cookie = inotify_get_cookie();
1654 +
1655 + if (old_dir == new_dir)
1656 + inode_dir_notify(old_dir, DN_RENAME);
1657 + else {
1658 + inode_dir_notify(old_dir, DN_DELETE);
1659 + inode_dir_notify(new_dir, DN_CREATE);
1660 + }
1661 +
1662 + if (isdir)
1663 + isdir = IN_ISDIR;
1664 + inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir,cookie,old_name);
1665 + inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, cookie, new_name);
1666 +}
1667 +
1668 +/*
1669 + * fsnotify_unlink - file was unlinked
1670 + */
1671 +static inline void fsnotify_unlink(struct dentry *dentry, struct inode *dir)
1672 +{
1673 + struct inode *inode = dentry->d_inode;
1674 +
1675 + inode_dir_notify(dir, DN_DELETE);
1676 + inotify_inode_queue_event(dir, IN_DELETE, 0, dentry->d_name.name);
1677 + inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL);
1678 +
1679 + inotify_inode_is_dead(inode);
1680 +}
1681 +
1682 +/*
1683 + * fsnotify_rmdir - directory was removed
1684 + */
1685 +static inline void fsnotify_rmdir(struct dentry *dentry, struct inode *inode,
1686 + struct inode *dir)
1687 +{
1688 + inode_dir_notify(dir, DN_DELETE);
1689 + inotify_inode_queue_event(dir,IN_DELETE|IN_ISDIR,0,dentry->d_name.name);
1690 + inotify_inode_queue_event(inode, IN_DELETE_SELF | IN_ISDIR, 0, NULL);
1691 + inotify_inode_is_dead(inode);
1692 +}
1693 +
1694 +/*
1695 + * fsnotify_create - 'name' was linked in
1696 + */
1697 +static inline void fsnotify_create(struct inode *inode, const char *name)
1698 +{
1699 + inode_dir_notify(inode, DN_CREATE);
1700 + inotify_inode_queue_event(inode, IN_CREATE, 0, name);
1701 +}
1702 +
1703 +/*
1704 + * fsnotify_mkdir - directory 'name' was created
1705 + */
1706 +static inline void fsnotify_mkdir(struct inode *inode, const char *name)
1707 +{
1708 + inode_dir_notify(inode, DN_CREATE);
1709 + inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0, name);
1710 +}
1711 +
1712 +/*
1713 + * fsnotify_access - file was read
1714 + */
1715 +static inline void fsnotify_access(struct dentry *dentry)
1716 +{
1717 + struct inode *inode = dentry->d_inode;
1718 + u32 mask = IN_ACCESS;
1719 +
1720 + if (S_ISDIR(inode->i_mode))
1721 + mask |= IN_ISDIR;
1722 +
1723 + dnotify_parent(dentry, DN_ACCESS);
1724 + inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
1725 + inotify_inode_queue_event(inode, mask, 0, NULL);
1726 +}
1727 +
1728 +/*
1729 + * fsnotify_modify - file was modified
1730 + */
1731 +static inline void fsnotify_modify(struct dentry *dentry)
1732 +{
1733 + struct inode *inode = dentry->d_inode;
1734 + u32 mask = IN_MODIFY;
1735 +
1736 + if (S_ISDIR(inode->i_mode))
1737 + mask |= IN_ISDIR;
1738 +
1739 + dnotify_parent(dentry, DN_MODIFY);
1740 + inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
1741 + inotify_inode_queue_event(inode, mask, 0, NULL);
1742 +}
1743 +
1744 +/*
1745 + * fsnotify_open - file was opened
1746 + */
1747 +static inline void fsnotify_open(struct dentry *dentry)
1748 +{
1749 + struct inode *inode = dentry->d_inode;
1750 + u32 mask = IN_OPEN;
1751 +
1752 + if (S_ISDIR(inode->i_mode))
1753 + mask |= IN_ISDIR;
1754 +
1755 + inotify_inode_queue_event(inode, mask, 0, NULL);
1756 + inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
1757 +}
1758 +
1759 +/*
1760 + * fsnotify_close - file was closed
1761 + */
1762 +static inline void fsnotify_close(struct file *file)
1763 +{
1764 + struct dentry *dentry = file->f_dentry;
1765 + struct inode *inode = dentry->d_inode;
1766 + const char *name = dentry->d_name.name;
1767 + mode_t mode = file->f_mode;
1768 + u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE;
1769 +
1770 + if (S_ISDIR(inode->i_mode))
1771 + mask |= IN_ISDIR;
1772 +
1773 + inotify_dentry_parent_queue_event(dentry, mask, 0, name);
1774 + inotify_inode_queue_event(inode, mask, 0, NULL);
1775 +}
1776 +
1777 +/*
1778 + * fsnotify_xattr - extended attributes were changed
1779 + */
1780 +static inline void fsnotify_xattr(struct dentry *dentry)
1781 +{
1782 + struct inode *inode = dentry->d_inode;
1783 + u32 mask = IN_ATTRIB;
1784 +
1785 + if (S_ISDIR(inode->i_mode))
1786 + mask |= IN_ISDIR;
1787 +
1788 + inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
1789 + inotify_inode_queue_event(inode, mask, 0, NULL);
1790 +}
1791 +
1792 +/*
1793 + * fsnotify_change - notify_change event. file was modified and/or metadata
1794 + * was changed.
1795 + */
1796 +static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
1797 +{
1798 + struct inode *inode = dentry->d_inode;
1799 + int dn_mask = 0;
1800 + u32 in_mask = 0;
1801 +
1802 + if (ia_valid & ATTR_UID) {
1803 + in_mask |= IN_ATTRIB;
1804 + dn_mask |= DN_ATTRIB;
1805 + }
1806 + if (ia_valid & ATTR_GID) {
1807 + in_mask |= IN_ATTRIB;
1808 + dn_mask |= DN_ATTRIB;
1809 + }
1810 + if (ia_valid & ATTR_SIZE) {
1811 + in_mask |= IN_MODIFY;
1812 + dn_mask |= DN_MODIFY;
1813 + }
1814 + /* both times implies a utime(s) call */
1815 + if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
1816 + {
1817 + in_mask |= IN_ATTRIB;
1818 + dn_mask |= DN_ATTRIB;
1819 + } else if (ia_valid & ATTR_ATIME) {
1820 + in_mask |= IN_ACCESS;
1821 + dn_mask |= DN_ACCESS;
1822 + } else if (ia_valid & ATTR_MTIME) {
1823 + in_mask |= IN_MODIFY;
1824 + dn_mask |= DN_MODIFY;
1825 + }
1826 + if (ia_valid & ATTR_MODE) {
1827 + in_mask |= IN_ATTRIB;
1828 + dn_mask |= DN_ATTRIB;
1829 + }
1830 +
1831 + if (dn_mask)
1832 + dnotify_parent(dentry, dn_mask);
1833 + if (in_mask) {
1834 + if (S_ISDIR(inode->i_mode))
1835 + in_mask |= IN_ISDIR;
1836 + inotify_inode_queue_event(inode, in_mask, 0, NULL);
1837 + inotify_dentry_parent_queue_event(dentry, in_mask, 0,
1838 + dentry->d_name.name);
1839 + }
1840 +}
1841 +
1842 +#ifdef CONFIG_INOTIFY /* inotify helpers */
1843 +
1844 +/*
1845 + * fsnotify_oldname_init - save off the old filename before we change it
1846 + *
1847 + * XXX: This could be kstrdup if only we could add that to lib/string.c
1848 + */
1849 +static inline const char *fsnotify_oldname_init(const char *name)
1850 +{
1851 + size_t len;
1852 + char *buf;
1853 +
1854 + len = strlen(name) + 1;
1855 + buf = kmalloc(len, GFP_KERNEL);
1856 + if (likely(buf))
1857 + memcpy(buf, name, len);
1858 + return buf;
1859 +}
1860 +
1861 +/*
1862 + * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
1863 + */
1864 +static inline void fsnotify_oldname_free(const char *old_name)
1865 +{
1866 + kfree(old_name);
1867 +}
1868 +
1869 +#else /* CONFIG_INOTIFY */
1870 +
1871 +static inline const char *fsnotify_oldname_init(const char *name)
1872 +{
1873 + return NULL;
1874 +}
1875 +
1876 +static inline void fsnotify_oldname_free(const char *old_name)
1877 +{
1878 +}
1879 +
1880 +#endif /* ! CONFIG_INOTIFY */
1881 +
1882 +#endif /* __KERNEL__ */
1883 +
1884 +#endif /* _LINUX_FS_NOTIFY_H */
1885 diff -urN linux-2.6.12-rc6/include/linux/inotify.h linux/include/linux/inotify.h
1886 --- linux-2.6.12-rc6/include/linux/inotify.h 1969-12-31 19:00:00.000000000 -0500
1887 +++ linux/include/linux/inotify.h 2005-06-07 15:49:02.000000000 -0400
1888 @@ -0,0 +1,124 @@
1889 +/*
1890 + * Inode based directory notification for Linux
1891 + *
1892 + * Copyright (C) 2005 John McCutchan
1893 + */
1894 +
1895 +#ifndef _LINUX_INOTIFY_H
1896 +#define _LINUX_INOTIFY_H
1897 +
1898 +#include <linux/types.h>
1899 +
1900 +/*
1901 + * struct inotify_event - structure read from the inotify device for each event
1902 + *
1903 + * When you are watching a directory, you will receive the filename for events
1904 + * such as IN_CREATE, IN_DELETE, IN_OPEN, IN_CLOSE, ..., relative to the wd.
1905 + */
1906 +struct inotify_event {
1907 + __s32 wd; /* watch descriptor */
1908 + __u32 mask; /* watch mask */
1909 + __u32 cookie; /* cookie to synchronize two events */
1910 + __u32 len; /* length (including nulls) of name */
1911 + char name[0]; /* stub for possible name */
1912 +};
1913 +
1914 +/*
1915 + * struct inotify_watch_request - represents a watch request
1916 + *
1917 + * Pass to the inotify device via the INOTIFY_WATCH ioctl
1918 + */
1919 +struct inotify_watch_request {
1920 + int fd; /* fd of filename to watch */
1921 + __u32 mask; /* event mask */
1922 +};
1923 +
1924 +/* the following are legal, implemented events that user-space can watch for */
1925 +#define IN_ACCESS 0x00000001 /* File was accessed */
1926 +#define IN_MODIFY 0x00000002 /* File was modified */
1927 +#define IN_ATTRIB 0x00000004 /* Metadata changed */
1928 +#define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed */
1929 +#define IN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */
1930 +#define IN_OPEN 0x00000020 /* File was opened */
1931 +#define IN_MOVED_FROM 0x00000040 /* File was moved from X */
1932 +#define IN_MOVED_TO 0x00000080 /* File was moved to Y */
1933 +#define IN_CREATE 0x00000100 /* Subfile was created */
1934 +#define IN_DELETE 0x00000200 /* Subfile was deleted */
1935 +#define IN_DELETE_SELF 0x00000400 /* Self was deleted */
1936 +
1937 +/* the following are legal events. they are sent as needed to any watch */
1938 +#define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted */
1939 +#define IN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */
1940 +#define IN_IGNORED 0x00008000 /* File was ignored */
1941 +
1942 +/* helper events */
1943 +#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* close */
1944 +#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */
1945 +
1946 +/* special flags */
1947 +#define IN_ISDIR 0x40000000 /* event occurred against dir */
1948 +#define IN_ONESHOT 0x80000000 /* only send event once */
1949 +
1950 +/*
1951 + * All of the events - we build the list by hand so that we can add flags in
1952 + * the future and not break backward compatibility. Apps will get only the
1953 + * events that they originally wanted. Be sure to add new events here!
1954 + */
1955 +#define IN_ALL_EVENTS (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \
1956 + IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | \
1957 + IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF)
1958 +
1959 +#define INOTIFY_IOCTL_MAGIC 'Q'
1960 +#define INOTIFY_IOCTL_MAXNR 2
1961 +
1962 +#define INOTIFY_WATCH _IOR(INOTIFY_IOCTL_MAGIC, 1, struct inotify_watch_request)
1963 +#define INOTIFY_IGNORE _IOR(INOTIFY_IOCTL_MAGIC, 2, int)
1964 +
1965 +#ifdef __KERNEL__
1966 +
1967 +#include <linux/dcache.h>
1968 +#include <linux/fs.h>
1969 +#include <linux/config.h>
1970 +
1971 +#ifdef CONFIG_INOTIFY
1972 +
1973 +extern void inotify_inode_queue_event(struct inode *, __u32, __u32,
1974 + const char *);
1975 +extern void inotify_dentry_parent_queue_event(struct dentry *, __u32, __u32,
1976 + const char *);
1977 +extern void inotify_unmount_inodes(struct list_head *);
1978 +extern void inotify_inode_is_dead(struct inode *);
1979 +extern u32 inotify_get_cookie(void);
1980 +
1981 +#else
1982 +
1983 +static inline void inotify_inode_queue_event(struct inode *inode,
1984 + __u32 mask, __u32 cookie,
1985 + const char *filename)
1986 +{
1987 +}
1988 +
1989 +static inline void inotify_dentry_parent_queue_event(struct dentry *dentry,
1990 + __u32 mask, __u32 cookie,
1991 + const char *filename)
1992 +{
1993 +}
1994 +
1995 +static inline void inotify_unmount_inodes(struct list_head *list)
1996 +{
1997 +}
1998 +
1999 +static inline void inotify_inode_is_dead(struct inode *inode)
2000 +{
2001 +}
2002 +
2003 +static inline u32 inotify_get_cookie(void)
2004 +{
2005 + return 0;
2006 +}
2007 +
2008 +#endif /* CONFIG_INOTIFY */
2009 +
2010 +#endif /* __KERNEL __ */
2011 +
2012 +#endif /* _LINUX_INOTIFY_H */
2013 diff -urN linux-2.6.12-rc6/include/linux/sched.h linux/include/linux/sched.h
2014 --- linux-2.6.12-rc6/include/linux/sched.h 2005-06-07 15:47:53.000000000 -0400
2015 +++ linux/include/linux/sched.h 2005-06-07 15:49:02.000000000 -0400
2016 @@ -404,6 +404,10 @@
2017 atomic_t processes; /* How many processes does this user have? */
2018 atomic_t files; /* How many open files does this user have? */
2019 atomic_t sigpending; /* How many pending signals does this user have? */
2020 +#ifdef CONFIG_INOTIFY
2021 + atomic_t inotify_watches; /* How many inotify watches does this user have? */
2022 + atomic_t inotify_devs; /* How many inotify devs does this user have opened? */
2023 +#endif
2024 /* protected by mq_lock */
2025 unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */
2026 unsigned long locked_shm; /* How many pages of mlocked shm ? */
2027 diff -urN linux-2.6.12-rc6/kernel/user.c linux/kernel/user.c
2028 --- linux-2.6.12-rc6/kernel/user.c 2005-06-07 15:47:53.000000000 -0400
2029 +++ linux/kernel/user.c 2005-06-07 15:49:02.000000000 -0400
2030 @@ -120,6 +120,10 @@
2031 atomic_set(&new->processes, 0);
2032 atomic_set(&new->files, 0);
2033 atomic_set(&new->sigpending, 0);
2034 +#ifdef CONFIG_INOTIFY
2035 + atomic_set(&new->inotify_watches, 0);
2036 + atomic_set(&new->inotify_devs, 0);
2037 +#endif
2038
2039 new->mq_bytes = 0;
2040 new->locked_shm = 0;

  ViewVC Help
Powered by ViewVC 1.1.20