20 #include <linux/module.h>
21 #include <linux/sched.h>
25 #include <linux/slab.h>
54 static void dnotify_recalc_inode_mask(
struct fsnotify_mark *fsn_mark)
56 __u32 new_mask, old_mask;
64 old_mask = fsn_mark->mask;
67 new_mask |= (dn->
dn_mask & ~FS_DN_MULTISHOT);
70 if (old_mask == new_mask)
73 if (fsn_mark->i.inode)
85 static int dnotify_handle_event(
struct fsnotify_group *
group,
86 struct fsnotify_mark *inode_mark,
87 struct fsnotify_mark *vfsmount_mark,
88 struct fsnotify_event *
event)
91 struct inode *to_tell;
95 __u32 test_mask =
event->mask & ~FS_EVENT_ON_CHILD;
99 to_tell =
event->to_tell;
103 spin_lock(&inode_mark->lock);
105 while ((dn = *prev) !=
NULL) {
106 if ((dn->
dn_mask & test_mask) == 0) {
112 if (dn->
dn_mask & FS_DN_MULTISHOT)
117 dnotify_recalc_inode_mask(inode_mark);
121 spin_unlock(&inode_mark->lock);
130 static bool dnotify_should_send_event(
struct fsnotify_group *group,
132 struct fsnotify_mark *inode_mark,
133 struct fsnotify_mark *vfsmount_mark,
143 static void dnotify_free_mark(
struct fsnotify_mark *fsn_mark)
154 static struct fsnotify_ops dnotify_fsnotify_ops = {
155 .handle_event = dnotify_handle_event,
156 .should_send_event = dnotify_should_send_event,
157 .free_group_priv =
NULL,
158 .freeing_mark =
NULL,
159 .free_event_priv =
NULL,
171 struct fsnotify_mark *fsn_mark;
177 inode = filp->
f_path.dentry->d_inode;
188 spin_lock(&fsn_mark->lock);
190 while ((dn = *prev) !=
NULL) {
194 dnotify_recalc_inode_mask(fsn_mark);
200 spin_unlock(&fsn_mark->lock);
212 static __u32 convert_arg(
unsigned long arg)
214 __u32 new_mask = FS_EVENT_ON_CHILD;
217 new_mask |= FS_DN_MULTISHOT;
219 new_mask |= (FS_DELETE | FS_MOVED_FROM);
221 new_mask |= FS_MODIFY;
223 new_mask |= FS_ACCESS;
225 new_mask |= FS_ATTRIB;
227 new_mask |= FS_DN_RENAME;
229 new_mask |= (FS_CREATE | FS_MOVED_TO);
246 while (odn !=
NULL) {
274 struct fsnotify_mark *new_fsn_mark, *fsn_mark;
286 if (!dir_notify_enable) {
292 if ((arg & ~DN_MULTISHOT) == 0) {
299 inode = filp->
f_path.dentry->d_inode;
320 mask = convert_arg(arg);
323 new_fsn_mark = &new_dn_mark->
fsn_mark;
325 new_fsn_mark->mask =
mask;
335 spin_lock(&fsn_mark->lock);
338 spin_lock(&new_fsn_mark->lock);
339 fsn_mark = new_fsn_mark;
340 dn_mark = new_dn_mark;
361 if (dn_mark == new_dn_mark)
369 if (dn_mark == new_dn_mark)
374 error = attach_dn(dn, dn_mark,
id, fd, filp, mask);
383 dnotify_recalc_inode_mask(fsn_mark);
385 spin_unlock(&fsn_mark->lock);
400 static int __init dnotify_init(
void)
406 if (IS_ERR(dnotify_group))
407 panic(
"unable to allocate fsnotify group for dnotify\n");