inotify.h 1.8 KB

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