GNU Linux-libre 4.14.332-gnu1
[releases.git] / fs / notify / inotify / inotify.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <linux/fsnotify_backend.h>
3 #include <linux/inotify.h>
4 #include <linux/slab.h> /* struct kmem_cache */
5
6 struct inotify_event_info {
7         struct fsnotify_event fse;
8         int wd;
9         u32 sync_cookie;
10         int name_len;
11         char name[];
12 };
13
14 struct inotify_inode_mark {
15         struct fsnotify_mark fsn_mark;
16         int wd;
17 };
18
19 static inline struct inotify_event_info *INOTIFY_E(struct fsnotify_event *fse)
20 {
21         return container_of(fse, struct inotify_event_info, fse);
22 }
23
24 /*
25  * INOTIFY_USER_FLAGS represents all of the mask bits that we expose to
26  * userspace.  There is at least one bit (FS_EVENT_ON_CHILD) which is
27  * used only internally to the kernel.
28  */
29 #define INOTIFY_USER_MASK (IN_ALL_EVENTS | IN_ONESHOT | IN_EXCL_UNLINK)
30
31 static inline __u32 inotify_mark_user_mask(struct fsnotify_mark *fsn_mark)
32 {
33         return fsn_mark->mask & INOTIFY_USER_MASK;
34 }
35
36 extern void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark,
37                                            struct fsnotify_group *group);
38 extern int inotify_handle_event(struct fsnotify_group *group,
39                                 struct inode *inode,
40                                 struct fsnotify_mark *inode_mark,
41                                 struct fsnotify_mark *vfsmount_mark,
42                                 u32 mask, const void *data, int data_type,
43                                 const unsigned char *file_name, u32 cookie,
44                                 struct fsnotify_iter_info *iter_info);
45
46 extern const struct fsnotify_ops inotify_fsnotify_ops;
47 extern struct kmem_cache *inotify_inode_mark_cachep;
48
49 #ifdef CONFIG_INOTIFY_USER
50 static inline void dec_inotify_instances(struct ucounts *ucounts)
51 {
52         dec_ucount(ucounts, UCOUNT_INOTIFY_INSTANCES);
53 }
54
55 static inline struct ucounts *inc_inotify_watches(struct ucounts *ucounts)
56 {
57         return inc_ucount(ucounts->ns, ucounts->uid, UCOUNT_INOTIFY_WATCHES);
58 }
59
60 static inline void dec_inotify_watches(struct ucounts *ucounts)
61 {
62         dec_ucount(ucounts, UCOUNT_INOTIFY_WATCHES);
63 }
64 #endif