xref: /linux/include/uapi/linux/fanotify.h (revision 6f52b16c5b29b89d92c0e7236f4655dc8491ad70)
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 togther.  */
31 #define FAN_CLASS_NOTIF		0x00000000
32 #define FAN_CLASS_CONTENT	0x00000004
33 #define FAN_CLASS_PRE_CONTENT	0x00000008
34 #define FAN_ALL_CLASS_BITS	(FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \
35 				 FAN_CLASS_PRE_CONTENT)
36 
37 #define FAN_UNLIMITED_QUEUE	0x00000010
38 #define FAN_UNLIMITED_MARKS	0x00000020
39 
40 #define FAN_ALL_INIT_FLAGS	(FAN_CLOEXEC | FAN_NONBLOCK | \
41 				 FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\
42 				 FAN_UNLIMITED_MARKS)
43 
44 /* flags used for fanotify_modify_mark() */
45 #define FAN_MARK_ADD		0x00000001
46 #define FAN_MARK_REMOVE		0x00000002
47 #define FAN_MARK_DONT_FOLLOW	0x00000004
48 #define FAN_MARK_ONLYDIR	0x00000008
49 #define FAN_MARK_MOUNT		0x00000010
50 #define FAN_MARK_IGNORED_MASK	0x00000020
51 #define FAN_MARK_IGNORED_SURV_MODIFY	0x00000040
52 #define FAN_MARK_FLUSH		0x00000080
53 
54 #define FAN_ALL_MARK_FLAGS	(FAN_MARK_ADD |\
55 				 FAN_MARK_REMOVE |\
56 				 FAN_MARK_DONT_FOLLOW |\
57 				 FAN_MARK_ONLYDIR |\
58 				 FAN_MARK_MOUNT |\
59 				 FAN_MARK_IGNORED_MASK |\
60 				 FAN_MARK_IGNORED_SURV_MODIFY |\
61 				 FAN_MARK_FLUSH)
62 
63 /*
64  * All of the events - we build the list by hand so that we can add flags in
65  * the future and not break backward compatibility.  Apps will get only the
66  * events that they originally wanted.  Be sure to add new events here!
67  */
68 #define FAN_ALL_EVENTS (FAN_ACCESS |\
69 			FAN_MODIFY |\
70 			FAN_CLOSE |\
71 			FAN_OPEN)
72 
73 /*
74  * All events which require a permission response from userspace
75  */
76 #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\
77 			     FAN_ACCESS_PERM)
78 
79 #define FAN_ALL_OUTGOING_EVENTS	(FAN_ALL_EVENTS |\
80 				 FAN_ALL_PERM_EVENTS |\
81 				 FAN_Q_OVERFLOW)
82 
83 #define FANOTIFY_METADATA_VERSION	3
84 
85 struct fanotify_event_metadata {
86 	__u32 event_len;
87 	__u8 vers;
88 	__u8 reserved;
89 	__u16 metadata_len;
90 	__aligned_u64 mask;
91 	__s32 fd;
92 	__s32 pid;
93 };
94 
95 struct fanotify_response {
96 	__s32 fd;
97 	__u32 response;
98 };
99 
100 /* Legit userspace responses to a _PERM event */
101 #define FAN_ALLOW	0x01
102 #define FAN_DENY	0x02
103 /* No fd set in event */
104 #define FAN_NOFD	-1
105 
106 /* Helper functions to deal with fanotify_event_metadata buffers */
107 #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata))
108 
109 #define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \
110 				   (struct fanotify_event_metadata*)(((char *)(meta)) + \
111 				   (meta)->event_len))
112 
113 #define FAN_EVENT_OK(meta, len)	((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \
114 				(long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \
115 				(long)(meta)->event_len <= (long)(len))
116 
117 #endif /* _UAPI_LINUX_FANOTIFY_H */
118