xref: /linux/include/uapi/linux/fanotify.h (revision 607ca46e97a1b6594b29647d98a32d545c24bdff)
1*607ca46eSDavid Howells #ifndef _UAPI_LINUX_FANOTIFY_H
2*607ca46eSDavid Howells #define _UAPI_LINUX_FANOTIFY_H
3*607ca46eSDavid Howells 
4*607ca46eSDavid Howells #include <linux/types.h>
5*607ca46eSDavid Howells 
6*607ca46eSDavid Howells /* the following events that user-space can register for */
7*607ca46eSDavid Howells #define FAN_ACCESS		0x00000001	/* File was accessed */
8*607ca46eSDavid Howells #define FAN_MODIFY		0x00000002	/* File was modified */
9*607ca46eSDavid Howells #define FAN_CLOSE_WRITE		0x00000008	/* Writtable file closed */
10*607ca46eSDavid Howells #define FAN_CLOSE_NOWRITE	0x00000010	/* Unwrittable file closed */
11*607ca46eSDavid Howells #define FAN_OPEN		0x00000020	/* File was opened */
12*607ca46eSDavid Howells 
13*607ca46eSDavid Howells #define FAN_Q_OVERFLOW		0x00004000	/* Event queued overflowed */
14*607ca46eSDavid Howells 
15*607ca46eSDavid Howells #define FAN_OPEN_PERM		0x00010000	/* File open in perm check */
16*607ca46eSDavid Howells #define FAN_ACCESS_PERM		0x00020000	/* File accessed in perm check */
17*607ca46eSDavid Howells 
18*607ca46eSDavid Howells #define FAN_ONDIR		0x40000000	/* event occurred against dir */
19*607ca46eSDavid Howells 
20*607ca46eSDavid Howells #define FAN_EVENT_ON_CHILD	0x08000000	/* interested in child events */
21*607ca46eSDavid Howells 
22*607ca46eSDavid Howells /* helper events */
23*607ca46eSDavid Howells #define FAN_CLOSE		(FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */
24*607ca46eSDavid Howells 
25*607ca46eSDavid Howells /* flags used for fanotify_init() */
26*607ca46eSDavid Howells #define FAN_CLOEXEC		0x00000001
27*607ca46eSDavid Howells #define FAN_NONBLOCK		0x00000002
28*607ca46eSDavid Howells 
29*607ca46eSDavid Howells /* These are NOT bitwise flags.  Both bits are used togther.  */
30*607ca46eSDavid Howells #define FAN_CLASS_NOTIF		0x00000000
31*607ca46eSDavid Howells #define FAN_CLASS_CONTENT	0x00000004
32*607ca46eSDavid Howells #define FAN_CLASS_PRE_CONTENT	0x00000008
33*607ca46eSDavid Howells #define FAN_ALL_CLASS_BITS	(FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \
34*607ca46eSDavid Howells 				 FAN_CLASS_PRE_CONTENT)
35*607ca46eSDavid Howells 
36*607ca46eSDavid Howells #define FAN_UNLIMITED_QUEUE	0x00000010
37*607ca46eSDavid Howells #define FAN_UNLIMITED_MARKS	0x00000020
38*607ca46eSDavid Howells 
39*607ca46eSDavid Howells #define FAN_ALL_INIT_FLAGS	(FAN_CLOEXEC | FAN_NONBLOCK | \
40*607ca46eSDavid Howells 				 FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\
41*607ca46eSDavid Howells 				 FAN_UNLIMITED_MARKS)
42*607ca46eSDavid Howells 
43*607ca46eSDavid Howells /* flags used for fanotify_modify_mark() */
44*607ca46eSDavid Howells #define FAN_MARK_ADD		0x00000001
45*607ca46eSDavid Howells #define FAN_MARK_REMOVE		0x00000002
46*607ca46eSDavid Howells #define FAN_MARK_DONT_FOLLOW	0x00000004
47*607ca46eSDavid Howells #define FAN_MARK_ONLYDIR	0x00000008
48*607ca46eSDavid Howells #define FAN_MARK_MOUNT		0x00000010
49*607ca46eSDavid Howells #define FAN_MARK_IGNORED_MASK	0x00000020
50*607ca46eSDavid Howells #define FAN_MARK_IGNORED_SURV_MODIFY	0x00000040
51*607ca46eSDavid Howells #define FAN_MARK_FLUSH		0x00000080
52*607ca46eSDavid Howells 
53*607ca46eSDavid Howells #define FAN_ALL_MARK_FLAGS	(FAN_MARK_ADD |\
54*607ca46eSDavid Howells 				 FAN_MARK_REMOVE |\
55*607ca46eSDavid Howells 				 FAN_MARK_DONT_FOLLOW |\
56*607ca46eSDavid Howells 				 FAN_MARK_ONLYDIR |\
57*607ca46eSDavid Howells 				 FAN_MARK_MOUNT |\
58*607ca46eSDavid Howells 				 FAN_MARK_IGNORED_MASK |\
59*607ca46eSDavid Howells 				 FAN_MARK_IGNORED_SURV_MODIFY |\
60*607ca46eSDavid Howells 				 FAN_MARK_FLUSH)
61*607ca46eSDavid Howells 
62*607ca46eSDavid Howells /*
63*607ca46eSDavid Howells  * All of the events - we build the list by hand so that we can add flags in
64*607ca46eSDavid Howells  * the future and not break backward compatibility.  Apps will get only the
65*607ca46eSDavid Howells  * events that they originally wanted.  Be sure to add new events here!
66*607ca46eSDavid Howells  */
67*607ca46eSDavid Howells #define FAN_ALL_EVENTS (FAN_ACCESS |\
68*607ca46eSDavid Howells 			FAN_MODIFY |\
69*607ca46eSDavid Howells 			FAN_CLOSE |\
70*607ca46eSDavid Howells 			FAN_OPEN)
71*607ca46eSDavid Howells 
72*607ca46eSDavid Howells /*
73*607ca46eSDavid Howells  * All events which require a permission response from userspace
74*607ca46eSDavid Howells  */
75*607ca46eSDavid Howells #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\
76*607ca46eSDavid Howells 			     FAN_ACCESS_PERM)
77*607ca46eSDavid Howells 
78*607ca46eSDavid Howells #define FAN_ALL_OUTGOING_EVENTS	(FAN_ALL_EVENTS |\
79*607ca46eSDavid Howells 				 FAN_ALL_PERM_EVENTS |\
80*607ca46eSDavid Howells 				 FAN_Q_OVERFLOW)
81*607ca46eSDavid Howells 
82*607ca46eSDavid Howells #define FANOTIFY_METADATA_VERSION	3
83*607ca46eSDavid Howells 
84*607ca46eSDavid Howells struct fanotify_event_metadata {
85*607ca46eSDavid Howells 	__u32 event_len;
86*607ca46eSDavid Howells 	__u8 vers;
87*607ca46eSDavid Howells 	__u8 reserved;
88*607ca46eSDavid Howells 	__u16 metadata_len;
89*607ca46eSDavid Howells 	__aligned_u64 mask;
90*607ca46eSDavid Howells 	__s32 fd;
91*607ca46eSDavid Howells 	__s32 pid;
92*607ca46eSDavid Howells };
93*607ca46eSDavid Howells 
94*607ca46eSDavid Howells struct fanotify_response {
95*607ca46eSDavid Howells 	__s32 fd;
96*607ca46eSDavid Howells 	__u32 response;
97*607ca46eSDavid Howells };
98*607ca46eSDavid Howells 
99*607ca46eSDavid Howells /* Legit userspace responses to a _PERM event */
100*607ca46eSDavid Howells #define FAN_ALLOW	0x01
101*607ca46eSDavid Howells #define FAN_DENY	0x02
102*607ca46eSDavid Howells /* No fd set in event */
103*607ca46eSDavid Howells #define FAN_NOFD	-1
104*607ca46eSDavid Howells 
105*607ca46eSDavid Howells /* Helper functions to deal with fanotify_event_metadata buffers */
106*607ca46eSDavid Howells #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata))
107*607ca46eSDavid Howells 
108*607ca46eSDavid Howells #define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \
109*607ca46eSDavid Howells 				   (struct fanotify_event_metadata*)(((char *)(meta)) + \
110*607ca46eSDavid Howells 				   (meta)->event_len))
111*607ca46eSDavid Howells 
112*607ca46eSDavid Howells #define FAN_EVENT_OK(meta, len)	((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \
113*607ca46eSDavid Howells 				(long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \
114*607ca46eSDavid Howells 				(long)(meta)->event_len <= (long)(len))
115*607ca46eSDavid Howells 
116*607ca46eSDavid Howells #endif /* _UAPI_LINUX_FANOTIFY_H */
117