1 #include <linux/fdtable.h>
2 #include <linux/fsnotify_backend.h>
3 #include <linux/init.h>
4 #include <linux/kernel.h> /* UINT_MAX */
5 #include <linux/types.h>
9 static int fanotify_handle_event(struct fsnotify_group *group, struct fsnotify_event *event)
14 BUILD_BUG_ON(FAN_ACCESS != FS_ACCESS);
15 BUILD_BUG_ON(FAN_MODIFY != FS_MODIFY);
16 BUILD_BUG_ON(FAN_CLOSE_NOWRITE != FS_CLOSE_NOWRITE);
17 BUILD_BUG_ON(FAN_CLOSE_WRITE != FS_CLOSE_WRITE);
18 BUILD_BUG_ON(FAN_OPEN != FS_OPEN);
19 BUILD_BUG_ON(FAN_EVENT_ON_CHILD != FS_EVENT_ON_CHILD);
20 BUILD_BUG_ON(FAN_Q_OVERFLOW != FS_Q_OVERFLOW);
22 pr_debug("%s: group=%p event=%p\n", __func__, group, event);
24 ret = fsnotify_add_notify_event(group, event, NULL, NULL);
29 static bool fanotify_should_send_event(struct fsnotify_group *group, struct inode *inode,
30 struct vfsmount *mnt, __u32 mask, void *data,
33 struct fsnotify_mark *fsn_mark;
36 pr_debug("%s: group=%p inode=%p mask=%x data=%p data_type=%d\n",
37 __func__, group, inode, mask, data, data_type);
39 /* sorry, fanotify only gives a damn about files and dirs */
40 if (!S_ISREG(inode->i_mode) &&
41 !S_ISDIR(inode->i_mode))
44 /* if we don't have enough info to send an event to userspace say no */
45 if (data_type != FSNOTIFY_EVENT_PATH)
48 fsn_mark = fsnotify_find_mark(group, inode);
52 /* if the event is for a child and this inode doesn't care about
53 * events on the child, don't send it! */
54 if ((mask & FS_EVENT_ON_CHILD) &&
55 !(fsn_mark->mask & FS_EVENT_ON_CHILD)) {
59 * We care about children, but do we care about this particular
62 mask = (mask & ~FS_EVENT_ON_CHILD);
63 send = (fsn_mark->mask & mask);
66 /* find took a reference */
67 fsnotify_put_mark(fsn_mark);
72 const struct fsnotify_ops fanotify_fsnotify_ops = {
73 .handle_event = fanotify_handle_event,
74 .should_send_event = fanotify_should_send_event,
75 .free_group_priv = NULL,
76 .free_event_priv = NULL,