xref: /linux/fs/notify/inotify/inotify.h (revision a32e697c)
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 	u32 mask;
9 	int wd;
10 	u32 sync_cookie;
11 	int name_len;
12 	char name[];
13 };
14 
15 struct inotify_inode_mark {
16 	struct fsnotify_mark fsn_mark;
17 	int wd;
18 };
19 
20 static inline struct inotify_event_info *INOTIFY_E(struct fsnotify_event *fse)
21 {
22 	return container_of(fse, struct inotify_event_info, fse);
23 }
24 
25 /*
26  * INOTIFY_USER_FLAGS represents all of the mask bits that we expose to
27  * userspace.  There is at least one bit (FS_EVENT_ON_CHILD) which is
28  * used only internally to the kernel.
29  */
30 #define INOTIFY_USER_MASK (IN_ALL_EVENTS | IN_ONESHOT | IN_EXCL_UNLINK)
31 
32 static inline __u32 inotify_mark_user_mask(struct fsnotify_mark *fsn_mark)
33 {
34 	return fsn_mark->mask & INOTIFY_USER_MASK;
35 }
36 
37 extern void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark,
38 					   struct fsnotify_group *group);
39 extern int inotify_handle_inode_event(struct fsnotify_mark *inode_mark,
40 				      u32 mask, struct inode *inode,
41 				      struct inode *dir,
42 				      const struct qstr *name, u32 cookie);
43 
44 extern const struct fsnotify_ops inotify_fsnotify_ops;
45 extern struct kmem_cache *inotify_inode_mark_cachep;
46 
47 #ifdef CONFIG_INOTIFY_USER
48 static inline void dec_inotify_instances(struct ucounts *ucounts)
49 {
50 	dec_ucount(ucounts, UCOUNT_INOTIFY_INSTANCES);
51 }
52 
53 static inline struct ucounts *inc_inotify_watches(struct ucounts *ucounts)
54 {
55 	return inc_ucount(ucounts->ns, ucounts->uid, UCOUNT_INOTIFY_WATCHES);
56 }
57 
58 static inline void dec_inotify_watches(struct ucounts *ucounts)
59 {
60 	dec_ucount(ucounts, UCOUNT_INOTIFY_WATCHES);
61 }
62 #endif
63