fanotify.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef _LINUX_FANOTIFY_H
  2. #define _LINUX_FANOTIFY_H
  3. #include <linux/types.h>
  4. /* the following events that user-space can register for */
  5. #define FAN_ACCESS 0x00000001 /* File was accessed */
  6. #define FAN_MODIFY 0x00000002 /* File was modified */
  7. #define FAN_CLOSE_WRITE 0x00000008 /* Unwrittable file closed */
  8. #define FAN_CLOSE_NOWRITE 0x00000010 /* Writtable file closed */
  9. #define FAN_OPEN 0x00000020 /* File was opened */
  10. #define FAN_EVENT_ON_CHILD 0x08000000 /* interested in child events */
  11. /* FIXME currently Q's have no limit.... */
  12. #define FAN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */
  13. #define FAN_OPEN_PERM 0x00010000 /* File open in perm check */
  14. #define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */
  15. /* helper events */
  16. #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */
  17. /* flags used for fanotify_init() */
  18. #define FAN_CLOEXEC 0x00000001
  19. #define FAN_NONBLOCK 0x00000002
  20. #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK)
  21. /* flags used for fanotify_modify_mark() */
  22. #define FAN_MARK_ADD 0x00000001
  23. #define FAN_MARK_REMOVE 0x00000002
  24. #define FAN_MARK_DONT_FOLLOW 0x00000004
  25. #define FAN_MARK_ONLYDIR 0x00000008
  26. #define FAN_MARK_MOUNT 0x00000010
  27. #define FAN_MARK_IGNORED_MASK 0x00000020
  28. #define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040
  29. #define FAN_MARK_FLUSH 0x00000080
  30. #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\
  31. FAN_MARK_REMOVE |\
  32. FAN_MARK_DONT_FOLLOW |\
  33. FAN_MARK_ONLYDIR |\
  34. FAN_MARK_MOUNT |\
  35. FAN_MARK_IGNORED_MASK |\
  36. FAN_MARK_IGNORED_SURV_MODIFY)
  37. /*
  38. * All of the events - we build the list by hand so that we can add flags in
  39. * the future and not break backward compatibility. Apps will get only the
  40. * events that they originally wanted. Be sure to add new events here!
  41. */
  42. #define FAN_ALL_EVENTS (FAN_ACCESS |\
  43. FAN_MODIFY |\
  44. FAN_CLOSE |\
  45. FAN_OPEN)
  46. /*
  47. * All events which require a permission response from userspace
  48. */
  49. #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\
  50. FAN_ACCESS_PERM)
  51. #define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\
  52. FAN_ALL_PERM_EVENTS |\
  53. FAN_Q_OVERFLOW)
  54. #define FANOTIFY_METADATA_VERSION 2
  55. struct fanotify_event_metadata {
  56. __u32 event_len;
  57. __u32 vers;
  58. __u64 mask;
  59. __s32 fd;
  60. __s32 pid;
  61. } __attribute__ ((packed));
  62. struct fanotify_response {
  63. __s32 fd;
  64. __u32 response;
  65. } __attribute__ ((packed));
  66. /* Legit userspace responses to a _PERM event */
  67. #define FAN_ALLOW 0x01
  68. #define FAN_DENY 0x02
  69. /* Helper functions to deal with fanotify_event_metadata buffers */
  70. #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata))
  71. #define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \
  72. (struct fanotify_event_metadata*)(((char *)(meta)) + \
  73. (meta)->event_len))
  74. #define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \
  75. (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \
  76. (long)(meta)->event_len <= (long)(len))
  77. #endif /* _LINUX_FANOTIFY_H */