1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
263c882a0SEric Paris #include <linux/fsnotify_backend.h>
363c882a0SEric Paris #include <linux/inotify.h>
463c882a0SEric Paris #include <linux/slab.h> /* struct kmem_cache */
563c882a0SEric Paris
67053aee2SJan Kara struct inotify_event_info {
77053aee2SJan Kara struct fsnotify_event fse;
8a0a92d26SAmir Goldstein u32 mask;
963c882a0SEric Paris int wd;
107053aee2SJan Kara u32 sync_cookie;
117053aee2SJan Kara int name_len;
127053aee2SJan Kara char name[];
1363c882a0SEric Paris };
1463c882a0SEric Paris
15000285deSEric Paris struct inotify_inode_mark {
16000285deSEric Paris struct fsnotify_mark fsn_mark;
1763c882a0SEric Paris int wd;
1863c882a0SEric Paris };
1963c882a0SEric Paris
INOTIFY_E(struct fsnotify_event * fse)207053aee2SJan Kara static inline struct inotify_event_info *INOTIFY_E(struct fsnotify_event *fse)
217053aee2SJan Kara {
227053aee2SJan Kara return container_of(fse, struct inotify_event_info, fse);
237053aee2SJan Kara }
247053aee2SJan Kara
25a32e697cSAmir Goldstein /*
26a32e697cSAmir Goldstein * INOTIFY_USER_FLAGS represents all of the mask bits that we expose to
27a32e697cSAmir Goldstein * userspace. There is at least one bit (FS_EVENT_ON_CHILD) which is
28a32e697cSAmir Goldstein * used only internally to the kernel.
29a32e697cSAmir Goldstein */
30*38035c04SAmir Goldstein #define INOTIFY_USER_MASK (IN_ALL_EVENTS)
31a32e697cSAmir Goldstein
inotify_mark_user_mask(struct fsnotify_mark * fsn_mark)32a32e697cSAmir Goldstein static inline __u32 inotify_mark_user_mask(struct fsnotify_mark *fsn_mark)
33a32e697cSAmir Goldstein {
34*38035c04SAmir Goldstein __u32 mask = fsn_mark->mask & INOTIFY_USER_MASK;
35*38035c04SAmir Goldstein
36*38035c04SAmir Goldstein if (fsn_mark->flags & FSNOTIFY_MARK_FLAG_EXCL_UNLINK)
37*38035c04SAmir Goldstein mask |= IN_EXCL_UNLINK;
38*38035c04SAmir Goldstein if (fsn_mark->flags & FSNOTIFY_MARK_FLAG_IN_ONESHOT)
39*38035c04SAmir Goldstein mask |= IN_ONESHOT;
40*38035c04SAmir Goldstein
41*38035c04SAmir Goldstein return mask;
42a32e697cSAmir Goldstein }
43a32e697cSAmir Goldstein
44000285deSEric Paris extern void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark,
45528da3e9SEric Paris struct fsnotify_group *group);
461a2620a9SAmir Goldstein extern int inotify_handle_inode_event(struct fsnotify_mark *inode_mark,
471a2620a9SAmir Goldstein u32 mask, struct inode *inode,
48b54cecf5SAmir Goldstein struct inode *dir,
491a2620a9SAmir Goldstein const struct qstr *name, u32 cookie);
5063c882a0SEric Paris
5163c882a0SEric Paris extern const struct fsnotify_ops inotify_fsnotify_ops;
52054c636eSJan Kara extern struct kmem_cache *inotify_inode_mark_cachep;
531cce1eeaSNikolay Borisov
541cce1eeaSNikolay Borisov #ifdef CONFIG_INOTIFY_USER
dec_inotify_instances(struct ucounts * ucounts)551cce1eeaSNikolay Borisov static inline void dec_inotify_instances(struct ucounts *ucounts)
561cce1eeaSNikolay Borisov {
571cce1eeaSNikolay Borisov dec_ucount(ucounts, UCOUNT_INOTIFY_INSTANCES);
581cce1eeaSNikolay Borisov }
591cce1eeaSNikolay Borisov
inc_inotify_watches(struct ucounts * ucounts)601cce1eeaSNikolay Borisov static inline struct ucounts *inc_inotify_watches(struct ucounts *ucounts)
611cce1eeaSNikolay Borisov {
621cce1eeaSNikolay Borisov return inc_ucount(ucounts->ns, ucounts->uid, UCOUNT_INOTIFY_WATCHES);
631cce1eeaSNikolay Borisov }
641cce1eeaSNikolay Borisov
dec_inotify_watches(struct ucounts * ucounts)651cce1eeaSNikolay Borisov static inline void dec_inotify_watches(struct ucounts *ucounts)
661cce1eeaSNikolay Borisov {
671cce1eeaSNikolay Borisov dec_ucount(ucounts, UCOUNT_INOTIFY_WATCHES);
681cce1eeaSNikolay Borisov }
691cce1eeaSNikolay Borisov #endif
70