[patch] oneshot for inotify.

From: Robert Love
Date: Thu Apr 21 2005 - 18:47:44 EST


The Samba guys want dnotify-like oneshot/multishot support.

That is not hard to add, so the following patch adds "oneshot" support
to inotify. If IN_ONESHOT is set on a watch, the watch is automatically
removed after the first event. Default behavior remains "multishot."

Best,

Robert Love


Signed-off-by: Robert Love <rml@xxxxxxxxxx>

fs/inotify.c | 2 ++
include/linux/inotify.h | 7 ++++---
2 files changed, 6 insertions(+), 3 deletions(-)

diff -urN linux-2.6.12-rc3-inotify/fs/inotify.c linux/fs/inotify.c
--- linux-2.6.12-rc3-inotify/fs/inotify.c 2005-04-21 19:40:44.000000000 -0400
+++ linux/fs/inotify.c 2005-04-21 19:37:24.000000000 -0400
@@ -509,6 +509,8 @@
struct inotify_device *dev = watch->dev;
down(&dev->sem);
inotify_dev_queue_event(dev, watch, mask, cookie, name);
+ if (watch->mask & IN_ONESHOT)
+ remove_watch_no_event(watch, dev);
up(&dev->sem);
}
}
diff -urN linux-2.6.12-rc3-inotify/include/linux/inotify.h linux/include/linux/inotify.h
--- linux-2.6.12-rc3-inotify/include/linux/inotify.h 2005-04-21 19:40:44.000000000 -0400
+++ linux/include/linux/inotify.h 2005-04-21 19:37:25.000000000 -0400
@@ -49,11 +49,12 @@
#define IN_DELETE_SELF 0x00001000 /* Self was deleted */
#define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted */
#define IN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */
-#define IN_IGNORED 0x00008000 /* File was ignored */

/* special flags */
-#define IN_ALL_EVENTS 0xffffffff /* All the events */
-#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE)
+#define IN_IGNORED 0x00008000 /* File was ignored */
+#define IN_ONESHOT 0x80000000 /* only send event once */
+#define IN_ALL_EVENTS (0xffffffff & ~IN_ONESHOT) /* All the events */
+#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* close */

#define INOTIFY_IOCTL_MAGIC 'Q'
#define INOTIFY_IOCTL_MAXNR 2


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/