1 #include <linux/fcntl.h>
3 #include <linux/anon_inodes.h>
4 #include <linux/fsnotify_backend.h>
5 #include <linux/security.h>
6 #include <linux/syscalls.h>
10 static int fanotify_release(struct inode *ignored, struct file *file)
12 struct fsnotify_group *group = file->private_data;
14 pr_debug("%s: file=%p group=%p\n", __func__, file, group);
16 /* matches the fanotify_init->fsnotify_alloc_group */
17 fsnotify_put_group(group);
22 static const struct file_operations fanotify_fops = {
26 .release = fanotify_release,
27 .unlocked_ioctl = NULL,
31 /* fanotify syscalls */
32 SYSCALL_DEFINE3(fanotify_init, unsigned int, flags, unsigned int, event_f_flags,
33 unsigned int, priority)
35 struct fsnotify_group *group;
38 pr_debug("%s: flags=%d event_f_flags=%d priority=%d\n",
39 __func__, flags, event_f_flags, priority);
46 if (!capable(CAP_SYS_ADMIN))
49 if (flags & ~FAN_ALL_INIT_FLAGS)
52 f_flags = (O_RDONLY | FMODE_NONOTIFY);
53 if (flags & FAN_CLOEXEC)
55 if (flags & FAN_NONBLOCK)
56 f_flags |= O_NONBLOCK;
58 /* fsnotify_alloc_group takes a ref. Dropped in fanotify_release */
59 group = fsnotify_alloc_group(&fanotify_fsnotify_ops);
61 return PTR_ERR(group);
63 fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags);
70 fsnotify_put_group(group);