1 .\" Copyright (C) 2013, Heinrich Schuchardt <xypron.glpk@gmx.de>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of
9 .\" this manual under the conditions for verbatim copying, provided that
10 .\" the entire resulting derived work is distributed under the terms of
11 .\" a permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume.
15 .\" no responsibility for errors or omissions, or for damages resulting.
16 .\" from the use of the information contained herein. The author(s) may.
17 .\" not have taken the same level of care in the production of this.
18 .\" manual, which is licensed free of charge, as they might when working.
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .TH FANOTIFY_MARK 2 2019-08-02 "Linux" "Linux Programmer's Manual"
26 fanotify_mark \- add, remove, or modify an fanotify mark on a filesystem
30 .B #include <sys/fanotify.h>
32 .BI "int fanotify_mark(int " fanotify_fd ", unsigned int " flags ,
33 .BI " uint64_t " mask ", int " dirfd \
34 ", const char *" pathname );
37 For an overview of the fanotify API, see
41 adds, removes, or modifies an fanotify mark on a filesystem object.
42 The caller must have read permission on the filesystem object that
47 argument is a file descriptor returned by
48 .BR fanotify_init (2).
51 is a bit mask describing the modification to perform.
52 It must include exactly one of the following values:
57 will be added to the mark mask (or to the ignore mask).
59 must be nonempty or the error
64 The events in argument
66 will be removed from the mark mask (or from the ignore mask).
68 must be nonempty or the error
73 Remove either all marks for filesystems, all marks for mounts, or all
74 marks for directories and files from the fanotify group.
79 all marks for mounts are removed from the group.
83 .BR FAN_MARK_FILESYSTEM ,
84 all marks for filesystems are removed from the group.
85 Otherwise, all marks for directories and files are removed.
86 No flag other than and at most one of the flags
89 .B FAN_MARK_FILESYSTEM
90 can be used in conjunction with
95 If none of the values above is specified, or more than one is specified,
96 the call fails with the error
100 zero or more of the following values may be ORed into
103 .B FAN_MARK_DONT_FOLLOW
106 is a symbolic link, mark the link itself, rather than the file to which it
112 if it is a symbolic link.)
115 If the filesystem object to be marked is not a directory, the error
120 Mark the mount point specified by
124 is not itself a mount point, the mount point containing
127 All directories, subdirectories, and the contained files of the mount point
129 This value cannot be used if the
131 file descriptor has been initialized with the flag
133 or if any of the new directory modification events are provided as a
135 Attempting to do so will result in the error
139 .BR FAN_MARK_FILESYSTEM " (since Linux 4.20)"
140 .\" commit d54f4fba889b205e9cd8239182ca5d27d0ac3bc2
141 Mark the filesystem specified by
143 The filesystem containing
146 All the contained files and directories of the filesystem from any mount
147 point will be monitored.
149 .B FAN_MARK_IGNORED_MASK
152 shall be added to or removed from the ignore mask.
154 .B FAN_MARK_IGNORED_SURV_MODIFY
155 The ignore mask shall survive modify events.
156 If this flag is not set,
157 the ignore mask is cleared when a modify event occurs
158 for the ignored file or directory.
161 defines which events shall be listened for (or which shall be ignored).
162 It is a bit mask composed of the following values:
165 Create an event when a file or directory (but see BUGS) is accessed (read).
168 Create an event when a file is modified (write).
171 Create an event when a writable file is closed.
174 Create an event when a read-only file or directory is closed.
177 Create an event when a file or directory is opened.
179 .BR FAN_OPEN_EXEC " (since Linux 5.0)"
180 .\" commit 9b076f1c0f4869b838a1b7aa0edb5664d47ec8aa
181 Create an event when a file is opened with the intent to be executed.
182 See NOTES for additional details.
184 .BR FAN_ATTRIB " (since Linux 5.1)"
185 .\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
186 Create an event when the metadata for a file or directory has changed.
188 .BR FAN_CREATE " (since Linux 5.1)"
189 .\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
190 Create an event when a file or directory has been created in a marked
193 .BR FAN_DELETE " (since Linux 5.1)"
194 .\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
195 Create an event when a file or directory has been deleted in a marked
198 .BR FAN_DELETE_SELF " (since Linux 5.1)"
199 .\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
200 Create an event when a marked file or directory itself is deleted.
202 .BR FAN_MOVED_FROM " (since Linux 5.1)"
203 .\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
204 Create an event when a file or directory has been moved from a marked
207 .BR FAN_MOVED_TO " (since Linux 5.1)"
208 .\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
209 Create an event when a file or directory has been moved to a marked parent
212 .BR FAN_MOVE_SELF " (since Linux 5.1)"
213 .\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
214 Create an event when a marked file or directory itself has been moved.
217 Create an event when an overflow of the event queue occurs.
218 The size of the event queue is limited to 16384 entries if
219 .B FAN_UNLIMITED_QUEUE
221 .BR fanotify_init (2).
224 Create an event when a permission to open a file or directory is requested.
225 An fanotify file descriptor created with
226 .B FAN_CLASS_PRE_CONTENT
231 .BR FAN_OPEN_EXEC_PERM " (since Linux 5.0)"
232 .\" commit 66917a3130f218dcef9eeab4fd11a71cd00cd7c9
233 Create an event when a permission to open a file for execution is
235 An fanotify file descriptor created with
236 .B FAN_CLASS_PRE_CONTENT
240 See NOTES for additional details.
243 Create an event when a permission to read a file or directory is requested.
244 An fanotify file descriptor created with
245 .B FAN_CLASS_PRE_CONTENT
251 Create events for directories\(emfor example, when
257 Without this flag, only events for files are created.
260 flag is reported in an event mask only if the
262 file descriptor has been initialized with the flag
264 In the context of directory entry events, such as
270 for example, specifying the flag
272 is required in order to create events when subdirectory entries are
276 Subdirectory entry modification events will never be merged with
277 nonsubdirectory entry modification events.
278 This flag is never reported individually within an event and is always
279 supplied in conjunction with another event type.
281 .B FAN_EVENT_ON_CHILD
282 Events for the immediate children of marked directories shall be created.
283 The flag has no effect when marking mounts and filesystems.
284 Note that events are not generated for children of the subdirectories
285 of marked directories.
286 To monitor complete directory trees it is necessary to mark the relevant
289 The following composed values are defined:
293 .RB ( FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE ).
296 A file or directory has been moved
297 .RB ( FAN_MOVED_FROM | FAN_MOVED_TO ).
299 The filesystem object to be marked is determined by the file descriptor
301 and the pathname specified in
308 defines the filesystem object to be marked.
314 takes the special value
316 the current working directory is to be marked.
320 is absolute, it defines the filesystem object to be marked, and
328 does not have the value
330 then the filesystem object to be marked is determined by interpreting
332 relative the directory referred to by
341 then the filesystem object to be marked is determined by interpreting
343 relative the current working directory.
348 On error, \-1 is returned, and
350 is set to indicate the error.
354 An invalid file descriptor was passed in
358 An invalid value was passed in
364 was not an fanotify file descriptor.
367 The fanotify file descriptor was opened with
371 and mask contains a flag for permission events
374 .BR FAN_ACCESS_PERM ).
377 The filesystem object indicated by
379 is not associated with a filesystem that supports
383 This error can be returned only when an fanotify file descriptor returned
385 .BR fanotify_init (2)
386 has been created with
390 The filesystem object indicated by
395 This error also occurs when trying to remove a mark from an object
399 The necessary memory could not be allocated.
402 The number of marks exceeds the limit of 8192 and the
403 .B FAN_UNLIMITED_MARKS
404 flag was not specified when the fanotify file descriptor was created with
405 .BR fanotify_init (2).
408 This kernel does not implement
409 .BR fanotify_mark ().
410 The fanotify API is available only if the kernel was configured with
411 .BR CONFIG_FANOTIFY .
416 .BR FAN_MARK_ONLYDIR ,
421 do not specify a directory.
424 The object indicated by
426 is associated with a filesystem that does not support the encoding of file
428 This error can be returned only when an fanotify file descriptor returned
430 .BR fanotify_init (2)
431 has been created with
435 The filesystem object indicated by
437 resides within a filesystem subvolume (e.g.,
439 which uses a different
441 than its root superblock.
442 This error can be returned only when an fanotify file descriptor returned
444 .BR fanotify_init (2)
445 has been created with
449 was introduced in version 2.6.36 of the Linux kernel and enabled in version
452 This system call is Linux-specific.
454 .SS FAN_OPEN_EXEC and FAN_OPEN_EXEC_PERM
458 .B FAN_OPEN_EXEC_PERM
461 events of these types will be returned only when the direct execution of a
463 More specifically, this means that events of these types will be generated
464 for files that are opened using
469 Events of these types will not be raised in the situation where an
470 interpreter is passed (or reads) a file for interpretation.
472 Additionally, if a mark has also been placed on the Linux dynamic
473 linker, a user should also expect to receive an event for it when
474 an ELF object has been successfully opened using
479 For example, if the following ELF binary were to be invoked and a
481 mark has been placed on /:
489 The listening application in this case would receive
491 events for both the ELF binary and interpreter, respectively:
496 /lib64/ld-linux-x86-64.so.2
500 The following bugs were present in Linux kernels before version 3.16:
502 .\" Fixed by commit 0a8dd2db579f7a0ac7033d6b857c3d5dbaa77563
510 must specify a valid filesystem object, even though this object is not used.
512 .\" Fixed by commit d4c7cf6cffb1bc711a833b5e304ba5bcfe76398b
518 .\" Fixed by commit cc299a98eb13a9853675a9cbb90b30b4011e1406
524 is not checked for invalid values.
526 .BR fanotify_init (2),