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