• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _UAPI_LINUX_FANOTIFY_H
3 #define _UAPI_LINUX_FANOTIFY_H
4 
5 #include <linux/types.h>
6 
7 /* the following events that user-space can register for */
8 #define FAN_ACCESS		0x00000001	/* File was accessed */
9 #define FAN_MODIFY		0x00000002	/* File was modified */
10 #define FAN_CLOSE_WRITE		0x00000008	/* Writtable file closed */
11 #define FAN_CLOSE_NOWRITE	0x00000010	/* Unwrittable file closed */
12 #define FAN_OPEN		0x00000020	/* File was opened */
13 #define FAN_OPEN_EXEC		0x00001000	/* File was opened for exec */
14 
15 #define FAN_Q_OVERFLOW		0x00004000	/* Event queued overflowed */
16 
17 #define FAN_OPEN_PERM		0x00010000	/* File open in perm check */
18 #define FAN_ACCESS_PERM		0x00020000	/* File accessed in perm check */
19 #define FAN_OPEN_EXEC_PERM	0x00040000	/* File open/exec in perm check */
20 
21 #define FAN_ONDIR		0x40000000	/* event occurred against dir */
22 
23 #define FAN_EVENT_ON_CHILD	0x08000000	/* interested in child events */
24 
25 /* helper events */
26 #define FAN_CLOSE		(FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */
27 
28 /* flags used for fanotify_init() */
29 #define FAN_CLOEXEC		0x00000001
30 #define FAN_NONBLOCK		0x00000002
31 
32 /* These are NOT bitwise flags.  Both bits are used together.  */
33 #define FAN_CLASS_NOTIF		0x00000000
34 #define FAN_CLASS_CONTENT	0x00000004
35 #define FAN_CLASS_PRE_CONTENT	0x00000008
36 
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 
41 #define FAN_UNLIMITED_QUEUE	0x00000010
42 #define FAN_UNLIMITED_MARKS	0x00000020
43 #define FAN_ENABLE_AUDIT	0x00000040
44 
45 /* Flags to determine fanotify event format */
46 #define FAN_REPORT_TID		0x00000100	/* event->pid is thread id */
47 
48 /* Deprecated - do not use this in programs and do not add new flags here! */
49 #define FAN_ALL_INIT_FLAGS	(FAN_CLOEXEC | FAN_NONBLOCK | \
50 				 FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\
51 				 FAN_UNLIMITED_MARKS)
52 
53 /* flags used for fanotify_modify_mark() */
54 #define FAN_MARK_ADD		0x00000001
55 #define FAN_MARK_REMOVE		0x00000002
56 #define FAN_MARK_DONT_FOLLOW	0x00000004
57 #define FAN_MARK_ONLYDIR	0x00000008
58 /* FAN_MARK_MOUNT is		0x00000010 */
59 #define FAN_MARK_IGNORED_MASK	0x00000020
60 #define FAN_MARK_IGNORED_SURV_MODIFY	0x00000040
61 #define FAN_MARK_FLUSH		0x00000080
62 /* FAN_MARK_FILESYSTEM is	0x00000100 */
63 
64 /* These are NOT bitwise flags.  Both bits can be used togther.  */
65 #define FAN_MARK_INODE		0x00000000
66 #define FAN_MARK_MOUNT		0x00000010
67 #define FAN_MARK_FILESYSTEM	0x00000100
68 
69 /* Deprecated - do not use this in programs and do not add new flags here! */
70 #define FAN_ALL_MARK_FLAGS	(FAN_MARK_ADD |\
71 				 FAN_MARK_REMOVE |\
72 				 FAN_MARK_DONT_FOLLOW |\
73 				 FAN_MARK_ONLYDIR |\
74 				 FAN_MARK_MOUNT |\
75 				 FAN_MARK_IGNORED_MASK |\
76 				 FAN_MARK_IGNORED_SURV_MODIFY |\
77 				 FAN_MARK_FLUSH)
78 
79 /* Deprecated - do not use this in programs and do not add new flags here! */
80 #define FAN_ALL_EVENTS (FAN_ACCESS |\
81 			FAN_MODIFY |\
82 			FAN_CLOSE |\
83 			FAN_OPEN)
84 
85 /*
86  * All events which require a permission response from userspace
87  */
88 /* Deprecated - do not use this in programs and do not add new flags here! */
89 #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\
90 			     FAN_ACCESS_PERM)
91 
92 /* Deprecated - do not use this in programs and do not add new flags here! */
93 #define FAN_ALL_OUTGOING_EVENTS	(FAN_ALL_EVENTS |\
94 				 FAN_ALL_PERM_EVENTS |\
95 				 FAN_Q_OVERFLOW)
96 
97 #define FANOTIFY_METADATA_VERSION	3
98 
99 struct fanotify_event_metadata {
100 	__u32 event_len;
101 	__u8 vers;
102 	__u8 reserved;
103 	__u16 metadata_len;
104 	__aligned_u64 mask;
105 	__s32 fd;
106 	__s32 pid;
107 };
108 
109 struct fanotify_response {
110 	__s32 fd;
111 	__u32 response;
112 };
113 
114 /* Legit userspace responses to a _PERM event */
115 #define FAN_ALLOW	0x01
116 #define FAN_DENY	0x02
117 #define FAN_AUDIT	0x10	/* Bit mask to create audit record for result */
118 
119 /* No fd set in event */
120 #define FAN_NOFD	-1
121 
122 /* Helper functions to deal with fanotify_event_metadata buffers */
123 #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata))
124 
125 #define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \
126 				   (struct fanotify_event_metadata*)(((char *)(meta)) + \
127 				   (meta)->event_len))
128 
129 #define FAN_EVENT_OK(meta, len)	((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \
130 				(long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \
131 				(long)(meta)->event_len <= (long)(len))
132 
133 #endif /* _UAPI_LINUX_FANOTIFY_H */
134