diff options
-rw-r--r-- | fs/notify/Kconfig | 1 | ||||
-rw-r--r-- | fs/notify/Makefile | 1 | ||||
-rw-r--r-- | fs/notify/fanotify/Kconfig | 11 | ||||
-rw-r--r-- | fs/notify/fanotify/Makefile | 1 | ||||
-rw-r--r-- | fs/notify/fanotify/fanotify.c | 78 | ||||
-rw-r--r-- | fs/notify/fanotify/fanotify.h | 12 | ||||
-rw-r--r-- | include/linux/Kbuild | 1 | ||||
-rw-r--r-- | include/linux/fanotify.h | 40 |
8 files changed, 145 insertions, 0 deletions
diff --git a/fs/notify/Kconfig b/fs/notify/Kconfig index dffbb0911d02..22c629eedd82 100644 --- a/fs/notify/Kconfig +++ b/fs/notify/Kconfig | |||
@@ -3,3 +3,4 @@ config FSNOTIFY | |||
3 | 3 | ||
4 | source "fs/notify/dnotify/Kconfig" | 4 | source "fs/notify/dnotify/Kconfig" |
5 | source "fs/notify/inotify/Kconfig" | 5 | source "fs/notify/inotify/Kconfig" |
6 | source "fs/notify/fanotify/Kconfig" | ||
diff --git a/fs/notify/Makefile b/fs/notify/Makefile index 0922cc826c46..396a38779371 100644 --- a/fs/notify/Makefile +++ b/fs/notify/Makefile | |||
@@ -2,3 +2,4 @@ obj-$(CONFIG_FSNOTIFY) += fsnotify.o notification.o group.o inode_mark.o | |||
2 | 2 | ||
3 | obj-y += dnotify/ | 3 | obj-y += dnotify/ |
4 | obj-y += inotify/ | 4 | obj-y += inotify/ |
5 | obj-y += fanotify/ | ||
diff --git a/fs/notify/fanotify/Kconfig b/fs/notify/fanotify/Kconfig new file mode 100644 index 000000000000..f9d7ae081f85 --- /dev/null +++ b/fs/notify/fanotify/Kconfig | |||
@@ -0,0 +1,11 @@ | |||
1 | config FANOTIFY | ||
2 | bool "Filesystem wide access notification" | ||
3 | select FSNOTIFY | ||
4 | default y | ||
5 | ---help--- | ||
6 | Say Y here to enable fanotify suport. fanotify is a file access | ||
7 | notification system which differs from inotify in that it sends | ||
8 | and open file descriptor to the userspace listener along with | ||
9 | the event. | ||
10 | |||
11 | If unsure, say Y. | ||
diff --git a/fs/notify/fanotify/Makefile b/fs/notify/fanotify/Makefile new file mode 100644 index 000000000000..e7d39c05b0fe --- /dev/null +++ b/fs/notify/fanotify/Makefile | |||
@@ -0,0 +1 @@ | |||
obj-$(CONFIG_FANOTIFY) += fanotify.o | |||
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c new file mode 100644 index 000000000000..3ffb9dbcab08 --- /dev/null +++ b/fs/notify/fanotify/fanotify.c | |||
@@ -0,0 +1,78 @@ | |||
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> | ||
6 | |||
7 | #include "fanotify.h" | ||
8 | |||
9 | static int fanotify_handle_event(struct fsnotify_group *group, struct fsnotify_event *event) | ||
10 | { | ||
11 | int ret; | ||
12 | |||
13 | |||
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); | ||
21 | |||
22 | pr_debug("%s: group=%p event=%p\n", __func__, group, event); | ||
23 | |||
24 | ret = fsnotify_add_notify_event(group, event, NULL, NULL); | ||
25 | |||
26 | return ret; | ||
27 | } | ||
28 | |||
29 | static bool fanotify_should_send_event(struct fsnotify_group *group, struct inode *inode, | ||
30 | struct vfsmount *mnt, __u32 mask, void *data, | ||
31 | int data_type) | ||
32 | { | ||
33 | struct fsnotify_mark *fsn_mark; | ||
34 | bool send; | ||
35 | |||
36 | pr_debug("%s: group=%p inode=%p mask=%x data=%p data_type=%d\n", | ||
37 | __func__, group, inode, mask, data, data_type); | ||
38 | |||
39 | /* sorry, fanotify only gives a damn about files and dirs */ | ||
40 | if (!S_ISREG(inode->i_mode) && | ||
41 | !S_ISDIR(inode->i_mode)) | ||
42 | return false; | ||
43 | |||
44 | /* if we don't have enough info to send an event to userspace say no */ | ||
45 | if (data_type != FSNOTIFY_EVENT_PATH) | ||
46 | return false; | ||
47 | |||
48 | fsn_mark = fsnotify_find_mark(group, inode); | ||
49 | if (!fsn_mark) | ||
50 | return false; | ||
51 | |||
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)) { | ||
56 | send = false; | ||
57 | } else { | ||
58 | /* | ||
59 | * We care about children, but do we care about this particular | ||
60 | * type of event? | ||
61 | */ | ||
62 | mask = (mask & ~FS_EVENT_ON_CHILD); | ||
63 | send = (fsn_mark->mask & mask); | ||
64 | } | ||
65 | |||
66 | /* find took a reference */ | ||
67 | fsnotify_put_mark(fsn_mark); | ||
68 | |||
69 | return send; | ||
70 | } | ||
71 | |||
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, | ||
77 | .freeing_mark = NULL, | ||
78 | }; | ||
diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h new file mode 100644 index 000000000000..50765eb30fe4 --- /dev/null +++ b/fs/notify/fanotify/fanotify.h | |||
@@ -0,0 +1,12 @@ | |||
1 | #include <linux/fanotify.h> | ||
2 | #include <linux/fsnotify_backend.h> | ||
3 | #include <linux/net.h> | ||
4 | #include <linux/kernel.h> | ||
5 | #include <linux/types.h> | ||
6 | |||
7 | static inline bool fanotify_mask_valid(__u32 mask) | ||
8 | { | ||
9 | if (mask & ~((__u32)FAN_ALL_INCOMING_EVENTS)) | ||
10 | return false; | ||
11 | return true; | ||
12 | } | ||
diff --git a/include/linux/Kbuild b/include/linux/Kbuild index 2fc8e14cc24a..d5cca9a05f14 100644 --- a/include/linux/Kbuild +++ b/include/linux/Kbuild | |||
@@ -210,6 +210,7 @@ unifdef-y += ethtool.h | |||
210 | unifdef-y += eventpoll.h | 210 | unifdef-y += eventpoll.h |
211 | unifdef-y += signalfd.h | 211 | unifdef-y += signalfd.h |
212 | unifdef-y += ext2_fs.h | 212 | unifdef-y += ext2_fs.h |
213 | unifdef-y += fanotify.h | ||
213 | unifdef-y += fb.h | 214 | unifdef-y += fb.h |
214 | unifdef-y += fcntl.h | 215 | unifdef-y += fcntl.h |
215 | unifdef-y += filter.h | 216 | unifdef-y += filter.h |
diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h new file mode 100644 index 000000000000..b560f86d1401 --- /dev/null +++ b/include/linux/fanotify.h | |||
@@ -0,0 +1,40 @@ | |||
1 | #ifndef _LINUX_FANOTIFY_H | ||
2 | #define _LINUX_FANOTIFY_H | ||
3 | |||
4 | #include <linux/types.h> | ||
5 | |||
6 | /* the following events that user-space can register for */ | ||
7 | #define FAN_ACCESS 0x00000001 /* File was accessed */ | ||
8 | #define FAN_MODIFY 0x00000002 /* File was modified */ | ||
9 | #define FAN_CLOSE_WRITE 0x00000008 /* Unwrittable file closed */ | ||
10 | #define FAN_CLOSE_NOWRITE 0x00000010 /* Writtable file closed */ | ||
11 | #define FAN_OPEN 0x00000020 /* File was opened */ | ||
12 | |||
13 | #define FAN_EVENT_ON_CHILD 0x08000000 /* interested in child events */ | ||
14 | |||
15 | /* FIXME currently Q's have no limit.... */ | ||
16 | #define FAN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ | ||
17 | |||
18 | /* helper events */ | ||
19 | #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */ | ||
20 | |||
21 | /* | ||
22 | * All of the events - we build the list by hand so that we can add flags in | ||
23 | * the future and not break backward compatibility. Apps will get only the | ||
24 | * events that they originally wanted. Be sure to add new events here! | ||
25 | */ | ||
26 | #define FAN_ALL_EVENTS (FAN_ACCESS |\ | ||
27 | FAN_MODIFY |\ | ||
28 | FAN_CLOSE |\ | ||
29 | FAN_OPEN) | ||
30 | |||
31 | /* | ||
32 | * All legal FAN bits userspace can request (although possibly not all | ||
33 | * at the same time. | ||
34 | */ | ||
35 | #define FAN_ALL_INCOMING_EVENTS (FAN_ALL_EVENTS |\ | ||
36 | FAN_EVENT_ON_CHILD) | ||
37 | #ifdef __KERNEL__ | ||
38 | |||
39 | #endif /* __KERNEL__ */ | ||
40 | #endif /* _LINUX_FANOTIFY_H */ | ||