fsnotify: include pathnames with entries when possible
When inotify wants to send events to a directory about a child it includes
the name of the original file. This patch collects that filename and makes
it available for notification.
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index 7fc7600..675129f 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -114,7 +114,8 @@
* specifies these are events which came from a child. */
mask |= FS_EVENT_ON_CHILD;
- fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE);
+ fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE,
+ dentry->d_name.name);
dput(parent);
}
@@ -131,7 +132,7 @@
* out to all of the registered fsnotify_group. Those groups can then use the
* notification event in whatever means they feel necessary.
*/
-void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is)
+void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, const char *file_name)
{
struct fsnotify_group *group;
struct fsnotify_event *event = NULL;
@@ -156,7 +157,7 @@
if (!group->ops->should_send_event(group, to_tell, mask))
continue;
if (!event) {
- event = fsnotify_create_event(to_tell, mask, data, data_is);
+ event = fsnotify_create_event(to_tell, mask, data, data_is, file_name);
/* shit, we OOM'd and now we can't tell, maybe
* someday someone else will want to do something
* here */
diff --git a/fs/notify/notification.c b/fs/notify/notification.c
index dddecc7..c69b18b 100644
--- a/fs/notify/notification.c
+++ b/fs/notify/notification.c
@@ -78,6 +78,7 @@
if (event->data_type == FSNOTIFY_EVENT_PATH)
path_put(&event->path);
+ kfree(event->file_name);
kmem_cache_free(fsnotify_event_cachep, event);
}
}
@@ -262,6 +263,9 @@
event->data_type = FSNOTIFY_EVENT_NONE;
event->to_tell = NULL;
+
+ event->file_name = NULL;
+ event->name_len = 0;
}
/*
@@ -274,9 +278,10 @@
* @mask what actually happened.
* @data pointer to the object which was actually affected
* @data_type flag indication if the data is a file, path, inode, nothing...
+ * @name the filename, if available
*/
struct fsnotify_event *fsnotify_create_event(struct inode *to_tell, __u32 mask,
- void *data, int data_type)
+ void *data, int data_type, const char *name)
{
struct fsnotify_event *event;
@@ -285,6 +290,15 @@
return NULL;
initialize_event(event);
+
+ if (name) {
+ event->file_name = kstrdup(name, GFP_KERNEL);
+ if (!event->file_name) {
+ kmem_cache_free(fsnotify_event_cachep, event);
+ return NULL;
+ }
+ event->name_len = strlen(event->file_name);
+ }
event->to_tell = to_tell;
switch (data_type) {