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