diff options
author | Eric Paris <eparis@redhat.com> | 2009-12-17 21:24:26 -0500 |
---|---|---|
committer | Eric Paris <eparis@redhat.com> | 2010-07-28 09:58:55 -0400 |
commit | 52c923dd079df49f58016a9e56df184b132611d6 (patch) | |
tree | 29263174337bd3c2b99a7c9452e8e0708635432b /fs/notify | |
parent | 11637e4b7dc098e9a863f0a619d55ebc60f5949e (diff) |
fanotify: fanotify_init syscall implementation
NAME
fanotify_init - initialize an fanotify group
SYNOPSIS
int fanotify_init(unsigned int flags, unsigned int event_f_flags, int priority);
DESCRIPTION
fanotify_init() initializes a new fanotify instance and returns a file
descriptor associated with the new fanotify event queue.
The following values can be OR'd into the flags field:
FAN_NONBLOCK Set the O_NONBLOCK file status flag on the new open file description.
Using this flag saves extra calls to fcntl(2) to achieve the same
result.
FAN_CLOEXEC Set the close-on-exec (FD_CLOEXEC) flag on the new file descriptor.
See the description of the O_CLOEXEC flag in open(2) for reasons why
this may be useful.
The event_f_flags argument is unused and must be set to 0
The priority argument is unused and must be set to 0
RETURN VALUE
On success, this system call return a new file descriptor. On error, -1 is
returned, and errno is set to indicate the error.
ERRORS
EINVAL An invalid value was specified in flags.
EINVAL A non-zero valid was passed in event_f_flags or in priority
ENFILE The system limit on the total number of file descriptors has been reached.
ENOMEM Insufficient kernel memory is available.
CONFORMING TO
These system calls are Linux-specific.
Signed-off-by: Eric Paris <eparis@redhat.com>
Diffstat (limited to 'fs/notify')
-rw-r--r-- | fs/notify/fanotify/fanotify.h | 2 | ||||
-rw-r--r-- | fs/notify/fanotify/fanotify_user.c | 61 |
2 files changed, 62 insertions, 1 deletions
diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 50765eb30fe4..dd656cfab1ba 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h | |||
@@ -4,6 +4,8 @@ | |||
4 | #include <linux/kernel.h> | 4 | #include <linux/kernel.h> |
5 | #include <linux/types.h> | 5 | #include <linux/types.h> |
6 | 6 | ||
7 | extern const struct fsnotify_ops fanotify_fsnotify_ops; | ||
8 | |||
7 | static inline bool fanotify_mask_valid(__u32 mask) | 9 | static inline bool fanotify_mask_valid(__u32 mask) |
8 | { | 10 | { |
9 | if (mask & ~((__u32)FAN_ALL_INCOMING_EVENTS)) | 11 | if (mask & ~((__u32)FAN_ALL_INCOMING_EVENTS)) |
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index cf176fc7086b..67c0b5e4a488 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c | |||
@@ -1,13 +1,72 @@ | |||
1 | #include <linux/fcntl.h> | 1 | #include <linux/fcntl.h> |
2 | #include <linux/fs.h> | 2 | #include <linux/fs.h> |
3 | #include <linux/anon_inodes.h> | ||
3 | #include <linux/fsnotify_backend.h> | 4 | #include <linux/fsnotify_backend.h> |
4 | #include <linux/security.h> | 5 | #include <linux/security.h> |
5 | #include <linux/syscalls.h> | 6 | #include <linux/syscalls.h> |
6 | 7 | ||
7 | #include "fanotify.h" | 8 | #include "fanotify.h" |
8 | 9 | ||
10 | static int fanotify_release(struct inode *ignored, struct file *file) | ||
11 | { | ||
12 | struct fsnotify_group *group = file->private_data; | ||
13 | |||
14 | pr_debug("%s: file=%p group=%p\n", __func__, file, group); | ||
15 | |||
16 | /* matches the fanotify_init->fsnotify_alloc_group */ | ||
17 | fsnotify_put_group(group); | ||
18 | |||
19 | return 0; | ||
20 | } | ||
21 | |||
22 | static const struct file_operations fanotify_fops = { | ||
23 | .poll = NULL, | ||
24 | .read = NULL, | ||
25 | .fasync = NULL, | ||
26 | .release = fanotify_release, | ||
27 | .unlocked_ioctl = NULL, | ||
28 | .compat_ioctl = NULL, | ||
29 | }; | ||
30 | |||
31 | /* fanotify syscalls */ | ||
9 | SYSCALL_DEFINE3(fanotify_init, unsigned int, flags, unsigned int, event_f_flags, | 32 | SYSCALL_DEFINE3(fanotify_init, unsigned int, flags, unsigned int, event_f_flags, |
10 | unsigned int, priority) | 33 | unsigned int, priority) |
11 | { | 34 | { |
12 | return -ENOSYS; | 35 | struct fsnotify_group *group; |
36 | int f_flags, fd; | ||
37 | |||
38 | pr_debug("%s: flags=%d event_f_flags=%d priority=%d\n", | ||
39 | __func__, flags, event_f_flags, priority); | ||
40 | |||
41 | if (event_f_flags) | ||
42 | return -EINVAL; | ||
43 | if (priority) | ||
44 | return -EINVAL; | ||
45 | |||
46 | if (!capable(CAP_SYS_ADMIN)) | ||
47 | return -EACCES; | ||
48 | |||
49 | if (flags & ~FAN_ALL_INIT_FLAGS) | ||
50 | return -EINVAL; | ||
51 | |||
52 | f_flags = (O_RDONLY | FMODE_NONOTIFY); | ||
53 | if (flags & FAN_CLOEXEC) | ||
54 | f_flags |= O_CLOEXEC; | ||
55 | if (flags & FAN_NONBLOCK) | ||
56 | f_flags |= O_NONBLOCK; | ||
57 | |||
58 | /* fsnotify_alloc_group takes a ref. Dropped in fanotify_release */ | ||
59 | group = fsnotify_alloc_group(&fanotify_fsnotify_ops); | ||
60 | if (IS_ERR(group)) | ||
61 | return PTR_ERR(group); | ||
62 | |||
63 | fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags); | ||
64 | if (fd < 0) | ||
65 | goto out_put_group; | ||
66 | |||
67 | return fd; | ||
68 | |||
69 | out_put_group: | ||
70 | fsnotify_put_group(group); | ||
71 | return fd; | ||
13 | } | 72 | } |