• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (c) 2012-2022 Linux Test Project.  All Rights Reserved.
4  * Author: Jan Kara, November 2013
5  */
6 
7 #ifndef	LAPI_FANOTIFY_H__
8 #define	LAPI_FANOTIFY_H__
9 
10 #include "config.h"
11 #include <sys/fanotify.h>
12 #include <linux/types.h>
13 
14 #ifndef FAN_REPORT_TID
15 #define FAN_REPORT_TID		0x00000100
16 #endif
17 #ifndef FAN_REPORT_FID
18 #define FAN_REPORT_FID		0x00000200
19 #endif
20 #ifndef FAN_REPORT_DIR_FID
21 #define FAN_REPORT_DIR_FID	0x00000400
22 #endif
23 #ifndef FAN_REPORT_NAME
24 #define FAN_REPORT_NAME		0x00000800
25 #define FAN_REPORT_DFID_NAME     (FAN_REPORT_DIR_FID | FAN_REPORT_NAME)
26 #endif
27 #ifndef FAN_REPORT_PIDFD
28 #define FAN_REPORT_PIDFD	0x00000080
29 #endif
30 #ifndef FAN_REPORT_TARGET_FID
31 #define FAN_REPORT_TARGET_FID	0x00001000
32 #define FAN_REPORT_DFID_NAME_TARGET (FAN_REPORT_DFID_NAME | \
33 				     FAN_REPORT_FID | FAN_REPORT_TARGET_FID)
34 #endif
35 
36 /* Non-uapi convenience macros */
37 #ifndef FAN_REPORT_DFID_NAME_FID
38 #define FAN_REPORT_DFID_NAME_FID (FAN_REPORT_DFID_NAME | FAN_REPORT_FID)
39 #endif
40 #ifndef FAN_REPORT_DFID_FID
41 #define FAN_REPORT_DFID_FID      (FAN_REPORT_DIR_FID | FAN_REPORT_FID)
42 #endif
43 
44 #ifndef FAN_MARK_INODE
45 #define FAN_MARK_INODE		0
46 #endif
47 #ifndef FAN_MARK_FILESYSTEM
48 #define FAN_MARK_FILESYSTEM	0x00000100
49 #endif
50 #ifndef FAN_MARK_EVICTABLE
51 #define FAN_MARK_EVICTABLE	0x00000200
52 #endif
53 #ifndef FAN_MARK_IGNORE
54 #define FAN_MARK_IGNORE		0x00000400
55 #endif
56 #ifndef FAN_MARK_IGNORE_SURV
57 #define FAN_MARK_IGNORE_SURV	(FAN_MARK_IGNORE | FAN_MARK_IGNORED_SURV_MODIFY)
58 #endif
59 /* Non-uapi convenience macros */
60 #ifndef FAN_MARK_IGNORED_SURV
61 #define FAN_MARK_IGNORED_SURV	(FAN_MARK_IGNORED_MASK | \
62 				FAN_MARK_IGNORED_SURV_MODIFY)
63 #endif
64 #ifndef FAN_MARK_PARENT
65 #define FAN_MARK_PARENT		FAN_MARK_ONLYDIR
66 #endif
67 #ifndef FAN_MARK_SUBDIR
68 #define FAN_MARK_SUBDIR		FAN_MARK_ONLYDIR
69 #endif
70 #ifndef FAN_MARK_TYPES
71 #define FAN_MARK_TYPES (FAN_MARK_INODE | FAN_MARK_MOUNT | FAN_MARK_FILESYSTEM)
72 #endif
73 
74 /* New dirent event masks */
75 #ifndef FAN_ATTRIB
76 #define FAN_ATTRIB		0x00000004
77 #endif
78 #ifndef FAN_MOVED_FROM
79 #define FAN_MOVED_FROM		0x00000040
80 #endif
81 #ifndef FAN_MOVED_TO
82 #define FAN_MOVED_TO		0x00000080
83 #endif
84 #ifndef FAN_CREATE
85 #define FAN_CREATE		0x00000100
86 #endif
87 #ifndef FAN_DELETE
88 #define FAN_DELETE		0x00000200
89 #endif
90 #ifndef FAN_DELETE_SELF
91 #define FAN_DELETE_SELF		0x00000400
92 #endif
93 #ifndef FAN_MOVE_SELF
94 #define FAN_MOVE_SELF		0x00000800
95 #endif
96 #ifndef FAN_MOVE
97 #define FAN_MOVE		(FAN_MOVED_FROM | FAN_MOVED_TO)
98 #endif
99 #ifndef FAN_OPEN_EXEC
100 #define FAN_OPEN_EXEC		0x00001000
101 #endif
102 #ifndef FAN_OPEN_EXEC_PERM
103 #define FAN_OPEN_EXEC_PERM	0x00040000
104 #endif
105 #ifndef FAN_FS_ERROR
106 #define FAN_FS_ERROR		0x00008000
107 #endif
108 #ifndef FAN_RENAME
109 #define FAN_RENAME		0x10000000
110 #endif
111 
112 /* Additional error status codes that can be returned to userspace */
113 #ifndef FAN_NOPIDFD
114 #define FAN_NOPIDFD		-1
115 #endif
116 #ifndef FAN_EPIDFD
117 #define FAN_EPIDFD		-2
118 #endif
119 
120 /* Flags required for unprivileged user group */
121 #define FANOTIFY_REQUIRED_USER_INIT_FLAGS    (FAN_REPORT_FID)
122 
123 /*
124  * FAN_ALL_PERM_EVENTS has been deprecated, so any new permission events
125  * are not to be added to it. To cover the instance where a new permission
126  * event is defined, we create a new macro that is to include all
127  * permission events. Any new permission events should be added to this
128  * macro.
129  */
130 #define LTP_ALL_PERM_EVENTS	(FAN_OPEN_PERM | FAN_OPEN_EXEC_PERM | \
131 				 FAN_ACCESS_PERM)
132 
133 struct fanotify_group_type {
134 	unsigned int flag;
135 	const char *name;
136 };
137 
138 struct fanotify_mark_type {
139 	unsigned int flag;
140 	const char *name;
141 };
142 
143 #ifndef __kernel_fsid_t
144 typedef struct {
145 	int	val[2];
146 } lapi_fsid_t;
147 #define __kernel_fsid_t lapi_fsid_t
148 #endif /* __kernel_fsid_t */
149 
150 #ifndef FAN_EVENT_INFO_TYPE_FID
151 #define FAN_EVENT_INFO_TYPE_FID		1
152 #endif
153 #ifndef FAN_EVENT_INFO_TYPE_DFID_NAME
154 #define FAN_EVENT_INFO_TYPE_DFID_NAME	2
155 #endif
156 #ifndef FAN_EVENT_INFO_TYPE_DFID
157 #define FAN_EVENT_INFO_TYPE_DFID	3
158 #endif
159 #ifndef FAN_EVENT_INFO_TYPE_PIDFD
160 #define FAN_EVENT_INFO_TYPE_PIDFD	4
161 #endif
162 #ifndef FAN_EVENT_INFO_TYPE_ERROR
163 #define FAN_EVENT_INFO_TYPE_ERROR	5
164 #endif
165 
166 #ifndef FAN_EVENT_INFO_TYPE_OLD_DFID_NAME
167 #define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME	10
168 #endif
169 #ifndef FAN_EVENT_INFO_TYPE_NEW_DFID_NAME
170 #define FAN_EVENT_INFO_TYPE_NEW_DFID_NAME	12
171 #endif
172 
173 #ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER
174 struct fanotify_event_info_header {
175 	uint8_t info_type;
176 	uint8_t pad;
177 	uint16_t len;
178 };
179 #endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER */
180 
181 #ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_FID
182 struct fanotify_event_info_fid {
183 	struct fanotify_event_info_header hdr;
184 	__kernel_fsid_t fsid;
185 	unsigned char handle[0];
186 };
187 #endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_FID */
188 
189 #ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_PIDFD
190 struct fanotify_event_info_pidfd {
191 	struct fanotify_event_info_header hdr;
192 	int32_t pidfd;
193 };
194 #endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_PIDFD */
195 
196 #ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_ERROR
197 struct fanotify_event_info_error {
198 	struct fanotify_event_info_header hdr;
199 	__s32 error;
200 	__u32 error_count;
201 };
202 #endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_ERROR */
203 
204 /* NOTE: only for struct fanotify_event_info_fid */
205 #ifdef HAVE_STRUCT_FANOTIFY_EVENT_INFO_FID_FSID___VAL
206 # define FSID_VAL_MEMBER(fsid, i) (fsid.__val[i])
207 #else
208 # define FSID_VAL_MEMBER(fsid, i) (fsid.val[i])
209 #endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_FID_FSID___VAL */
210 
211 #endif /* LAPI_FANOTIFY_H__ */
212