logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

fanotify.h (8296B)


  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _LINUX_FANOTIFY_H
  3. #define _LINUX_FANOTIFY_H
  4. #include <linux/types.h>
  5. /* the following events that user-space can register for */
  6. #define FAN_ACCESS 0x00000001 /* File was accessed */
  7. #define FAN_MODIFY 0x00000002 /* File was modified */
  8. #define FAN_ATTRIB 0x00000004 /* Metadata changed */
  9. #define FAN_CLOSE_WRITE 0x00000008 /* Writable file closed */
  10. #define FAN_CLOSE_NOWRITE 0x00000010 /* Unwritable file closed */
  11. #define FAN_OPEN 0x00000020 /* File was opened */
  12. #define FAN_MOVED_FROM 0x00000040 /* File was moved from X */
  13. #define FAN_MOVED_TO 0x00000080 /* File was moved to Y */
  14. #define FAN_CREATE 0x00000100 /* Subfile was created */
  15. #define FAN_DELETE 0x00000200 /* Subfile was deleted */
  16. #define FAN_DELETE_SELF 0x00000400 /* Self was deleted */
  17. #define FAN_MOVE_SELF 0x00000800 /* Self was moved */
  18. #define FAN_OPEN_EXEC 0x00001000 /* File was opened for exec */
  19. #define FAN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */
  20. #define FAN_FS_ERROR 0x00008000 /* Filesystem error */
  21. #define FAN_OPEN_PERM 0x00010000 /* File open in perm check */
  22. #define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */
  23. #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */
  24. #define FAN_EVENT_ON_CHILD 0x08000000 /* Interested in child events */
  25. #define FAN_RENAME 0x10000000 /* File was renamed */
  26. #define FAN_ONDIR 0x40000000 /* Event occurred against dir */
  27. /* helper events */
  28. #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */
  29. #define FAN_MOVE (FAN_MOVED_FROM | FAN_MOVED_TO) /* moves */
  30. /* flags used for fanotify_init() */
  31. #define FAN_CLOEXEC 0x00000001
  32. #define FAN_NONBLOCK 0x00000002
  33. /* These are NOT bitwise flags. Both bits are used together. */
  34. #define FAN_CLASS_NOTIF 0x00000000
  35. #define FAN_CLASS_CONTENT 0x00000004
  36. #define FAN_CLASS_PRE_CONTENT 0x00000008
  37. /* Deprecated - do not use this in programs and do not add new flags here! */
  38. #define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \
  39. FAN_CLASS_PRE_CONTENT)
  40. #define FAN_UNLIMITED_QUEUE 0x00000010
  41. #define FAN_UNLIMITED_MARKS 0x00000020
  42. #define FAN_ENABLE_AUDIT 0x00000040
  43. /* Flags to determine fanotify event format */
  44. #define FAN_REPORT_PIDFD 0x00000080 /* Report pidfd for event->pid */
  45. #define FAN_REPORT_TID 0x00000100 /* event->pid is thread id */
  46. #define FAN_REPORT_FID 0x00000200 /* Report unique file id */
  47. #define FAN_REPORT_DIR_FID 0x00000400 /* Report unique directory id */
  48. #define FAN_REPORT_NAME 0x00000800 /* Report events with name */
  49. #define FAN_REPORT_TARGET_FID 0x00001000 /* Report dirent target id */
  50. /* Convenience macro - FAN_REPORT_NAME requires FAN_REPORT_DIR_FID */
  51. #define FAN_REPORT_DFID_NAME (FAN_REPORT_DIR_FID | FAN_REPORT_NAME)
  52. /* Convenience macro - FAN_REPORT_TARGET_FID requires all other FID flags */
  53. #define FAN_REPORT_DFID_NAME_TARGET (FAN_REPORT_DFID_NAME | \
  54. FAN_REPORT_FID | FAN_REPORT_TARGET_FID)
  55. /* Deprecated - do not use this in programs and do not add new flags here! */
  56. #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \
  57. FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\
  58. FAN_UNLIMITED_MARKS)
  59. /* flags used for fanotify_modify_mark() */
  60. #define FAN_MARK_ADD 0x00000001
  61. #define FAN_MARK_REMOVE 0x00000002
  62. #define FAN_MARK_DONT_FOLLOW 0x00000004
  63. #define FAN_MARK_ONLYDIR 0x00000008
  64. /* FAN_MARK_MOUNT is 0x00000010 */
  65. #define FAN_MARK_IGNORED_MASK 0x00000020
  66. #define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040
  67. #define FAN_MARK_FLUSH 0x00000080
  68. /* FAN_MARK_FILESYSTEM is 0x00000100 */
  69. #define FAN_MARK_EVICTABLE 0x00000200
  70. /* This bit is mutually exclusive with FAN_MARK_IGNORED_MASK bit */
  71. #define FAN_MARK_IGNORE 0x00000400
  72. /* These are NOT bitwise flags. Both bits can be used togther. */
  73. #define FAN_MARK_INODE 0x00000000
  74. #define FAN_MARK_MOUNT 0x00000010
  75. #define FAN_MARK_FILESYSTEM 0x00000100
  76. /*
  77. * Convenience macro - FAN_MARK_IGNORE requires FAN_MARK_IGNORED_SURV_MODIFY
  78. * for non-inode mark types.
  79. */
  80. #define FAN_MARK_IGNORE_SURV (FAN_MARK_IGNORE | FAN_MARK_IGNORED_SURV_MODIFY)
  81. /* Deprecated - do not use this in programs and do not add new flags here! */
  82. #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\
  83. FAN_MARK_REMOVE |\
  84. FAN_MARK_DONT_FOLLOW |\
  85. FAN_MARK_ONLYDIR |\
  86. FAN_MARK_MOUNT |\
  87. FAN_MARK_IGNORED_MASK |\
  88. FAN_MARK_IGNORED_SURV_MODIFY |\
  89. FAN_MARK_FLUSH)
  90. /* Deprecated - do not use this in programs and do not add new flags here! */
  91. #define FAN_ALL_EVENTS (FAN_ACCESS |\
  92. FAN_MODIFY |\
  93. FAN_CLOSE |\
  94. FAN_OPEN)
  95. /*
  96. * All events which require a permission response from userspace
  97. */
  98. /* Deprecated - do not use this in programs and do not add new flags here! */
  99. #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\
  100. FAN_ACCESS_PERM)
  101. /* Deprecated - do not use this in programs and do not add new flags here! */
  102. #define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\
  103. FAN_ALL_PERM_EVENTS |\
  104. FAN_Q_OVERFLOW)
  105. #define FANOTIFY_METADATA_VERSION 3
  106. struct fanotify_event_metadata {
  107. __u32 event_len;
  108. __u8 vers;
  109. __u8 reserved;
  110. __u16 metadata_len;
  111. __aligned_u64 mask;
  112. __s32 fd;
  113. __s32 pid;
  114. };
  115. #define FAN_EVENT_INFO_TYPE_FID 1
  116. #define FAN_EVENT_INFO_TYPE_DFID_NAME 2
  117. #define FAN_EVENT_INFO_TYPE_DFID 3
  118. #define FAN_EVENT_INFO_TYPE_PIDFD 4
  119. #define FAN_EVENT_INFO_TYPE_ERROR 5
  120. /* Special info types for FAN_RENAME */
  121. #define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME 10
  122. /* Reserved for FAN_EVENT_INFO_TYPE_OLD_DFID 11 */
  123. #define FAN_EVENT_INFO_TYPE_NEW_DFID_NAME 12
  124. /* Reserved for FAN_EVENT_INFO_TYPE_NEW_DFID 13 */
  125. /* Variable length info record following event metadata */
  126. struct fanotify_event_info_header {
  127. __u8 info_type;
  128. __u8 pad;
  129. __u16 len;
  130. };
  131. /*
  132. * Unique file identifier info record.
  133. * This structure is used for records of types FAN_EVENT_INFO_TYPE_FID,
  134. * FAN_EVENT_INFO_TYPE_DFID and FAN_EVENT_INFO_TYPE_DFID_NAME.
  135. * For FAN_EVENT_INFO_TYPE_DFID_NAME there is additionally a null terminated
  136. * name immediately after the file handle.
  137. */
  138. struct fanotify_event_info_fid {
  139. struct fanotify_event_info_header hdr;
  140. __kernel_fsid_t fsid;
  141. /*
  142. * Following is an opaque struct file_handle that can be passed as
  143. * an argument to open_by_handle_at(2).
  144. */
  145. unsigned char handle[];
  146. };
  147. /*
  148. * This structure is used for info records of type FAN_EVENT_INFO_TYPE_PIDFD.
  149. * It holds a pidfd for the pid that was responsible for generating an event.
  150. */
  151. struct fanotify_event_info_pidfd {
  152. struct fanotify_event_info_header hdr;
  153. __s32 pidfd;
  154. };
  155. struct fanotify_event_info_error {
  156. struct fanotify_event_info_header hdr;
  157. __s32 error;
  158. __u32 error_count;
  159. };
  160. /*
  161. * User space may need to record additional information about its decision.
  162. * The extra information type records what kind of information is included.
  163. * The default is none. We also define an extra information buffer whose
  164. * size is determined by the extra information type.
  165. *
  166. * If the information type is Audit Rule, then the information following
  167. * is the rule number that triggered the user space decision that
  168. * requires auditing.
  169. */
  170. #define FAN_RESPONSE_INFO_NONE 0
  171. #define FAN_RESPONSE_INFO_AUDIT_RULE 1
  172. struct fanotify_response {
  173. __s32 fd;
  174. __u32 response;
  175. };
  176. struct fanotify_response_info_header {
  177. __u8 type;
  178. __u8 pad;
  179. __u16 len;
  180. };
  181. struct fanotify_response_info_audit_rule {
  182. struct fanotify_response_info_header hdr;
  183. __u32 rule_number;
  184. __u32 subj_trust;
  185. __u32 obj_trust;
  186. };
  187. /* Legit userspace responses to a _PERM event */
  188. #define FAN_ALLOW 0x01
  189. #define FAN_DENY 0x02
  190. #define FAN_AUDIT 0x10 /* Bitmask to create audit record for result */
  191. #define FAN_INFO 0x20 /* Bitmask to indicate additional information */
  192. /* No fd set in event */
  193. #define FAN_NOFD -1
  194. #define FAN_NOPIDFD FAN_NOFD
  195. #define FAN_EPIDFD -2
  196. /* Helper functions to deal with fanotify_event_metadata buffers */
  197. #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata))
  198. #define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \
  199. (struct fanotify_event_metadata*)(((char *)(meta)) + \
  200. (meta)->event_len))
  201. #define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \
  202. (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \
  203. (long)(meta)->event_len <= (long)(len))
  204. #endif /* _LINUX_FANOTIFY_H */