]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/fanotify_mark.2
Many pages: Fix style issues reported by `make lint-groff`
[thirdparty/man-pages.git] / man2 / fanotify_mark.2
CommitLineData
c200b422
HS
1.\" Copyright (C) 2013, Heinrich Schuchardt <xypron.glpk@gmx.de>
2.\"
5fbde956 3.\" SPDX-License-Identifier: Linux-man-pages-copyleft
6e00b7a8 4.TH FANOTIFY_MARK 2 2021-08-27 "Linux" "Linux Programmer's Manual"
c200b422
HS
5.SH NAME
6fanotify_mark \- add, remove, or modify an fanotify mark on a filesystem
7object
61e69b14
AC
8.SH LIBRARY
9Standard C library
8fc3b2cf 10.RI ( libc ", " \-lc )
c200b422
HS
11.SH SYNOPSIS
12.nf
13.B #include <sys/fanotify.h>
68e4db0a 14.PP
c200b422 15.BI "int fanotify_mark(int " fanotify_fd ", unsigned int " flags ,
5ff1ff14
MK
16.BI " uint64_t " mask ", int " dirfd \
17", const char *" pathname );
c200b422
HS
18.fi
19.SH DESCRIPTION
20For an overview of the fanotify API, see
21.BR fanotify (7).
22.PP
bf7bc8b8 23.BR fanotify_mark ()
b6551738 24adds, removes, or modifies an fanotify mark on a filesystem object.
1b24e2ee
MK
25The caller must have read permission on the filesystem object that
26is to be marked.
c200b422
HS
27.PP
28The
29.I fanotify_fd
963a1568 30argument is a file descriptor returned by
c200b422
HS
31.BR fanotify_init (2).
32.PP
33.I flags
34is a bit mask describing the modification to perform.
35It must include exactly one of the following values:
36.TP
37.B FAN_MARK_ADD
38The events in
39.I mask
40will be added to the mark mask (or to the ignore mask).
41.I mask
42must be nonempty or the error
43.B EINVAL
44will occur.
45.TP
46.B FAN_MARK_REMOVE
47The events in argument
48.I mask
49will be removed from the mark mask (or from the ignore mask).
50.I mask
51must be nonempty or the error
52.B EINVAL
53will occur.
54.TP
55.B FAN_MARK_FLUSH
953d1e07 56Remove either all marks for filesystems, all marks for mounts, or all
b2f8214d 57marks for directories and files from the fanotify group.
c200b422 58If
8c659c48 59.I flags
c200b422
HS
60contains
61.BR FAN_MARK_MOUNT ,
62all marks for mounts are removed from the group.
b2f8214d
AG
63If
64.I flags
65contains
66.BR FAN_MARK_FILESYSTEM ,
67all marks for filesystems are removed from the group.
c200b422 68Otherwise, all marks for directories and files are removed.
669d6302 69No flag other than, and at most one of, the flags
c200b422 70.B FAN_MARK_MOUNT
b2f8214d
AG
71or
72.B FAN_MARK_FILESYSTEM
c200b422
HS
73can be used in conjunction with
74.BR FAN_MARK_FLUSH .
75.I mask
76is ignored.
77.PP
1b24e2ee
MK
78If none of the values above is specified, or more than one is specified,
79the call fails with the error
c200b422
HS
80.BR EINVAL .
81.PP
82In addition,
d4a12c12
MK
83zero or more of the following values may be ORed into
84.IR flags :
c200b422
HS
85.TP
86.B FAN_MARK_DONT_FOLLOW
87If
88.I pathname
89is a symbolic link, mark the link itself, rather than the file to which it
90refers.
91(By default,
92.BR fanotify_mark ()
93dereferences
94.I pathname
95if it is a symbolic link.)
96.TP
97.B FAN_MARK_ONLYDIR
98If the filesystem object to be marked is not a directory, the error
99.B ENOTDIR
100shall be raised.
101.TP
102.B FAN_MARK_MOUNT
525a8b54 103Mark the mount specified by
c82b4ae4
MK
104.IR pathname .
105If
106.I pathname
525a8b54 107is not itself a mount point, the mount containing
c200b422 108.I pathname
c200b422 109will be marked.
525a8b54 110All directories, subdirectories, and the contained files of the mount
c200b422 111will be monitored.
b216da61 112The events which require that filesystem objects are identified by file handles,
d71c9b4a
AG
113such as
114.BR FAN_CREATE ,
115.BR FAN_ATTRIB ,
116.BR FAN_MOVE ,
117and
118.BR FAN_DELETE_SELF ,
119cannot be provided as a
1ae6b2c7 120.I mask
d71c9b4a
AG
121when
122.I flags
123contains
124.BR FAN_MARK_MOUNT .
0a4db6dc
MB
125Attempting to do so will result in the error
126.B EINVAL
127being returned.
69e6b644
MB
128Use of this flag requires the
129.B CAP_SYS_ADMIN
130capability.
c200b422 131.TP
b2f8214d
AG
132.BR FAN_MARK_FILESYSTEM " (since Linux 4.20)"
133.\" commit d54f4fba889b205e9cd8239182ca5d27d0ac3bc2
134Mark the filesystem specified by
135.IR pathname .
136The filesystem containing
137.I pathname
138will be marked.
139All the contained files and directories of the filesystem from any mount
140point will be monitored.
69e6b644
MB
141Use of this flag requires the
142.B CAP_SYS_ADMIN
143capability.
b2f8214d 144.TP
c200b422
HS
145.B FAN_MARK_IGNORED_MASK
146The events in
147.I mask
148shall be added to or removed from the ignore mask.
149.TP
150.B FAN_MARK_IGNORED_SURV_MODIFY
151The ignore mask shall survive modify events.
1b24e2ee
MK
152If this flag is not set,
153the ignore mask is cleared when a modify event occurs
c200b422
HS
154for the ignored file or directory.
155.PP
156.I mask
d4a12c12 157defines which events shall be listened for (or which shall be ignored).
c200b422
HS
158It is a bit mask composed of the following values:
159.TP
160.B FAN_ACCESS
161Create an event when a file or directory (but see BUGS) is accessed (read).
162.TP
163.B FAN_MODIFY
164Create an event when a file is modified (write).
165.TP
166.B FAN_CLOSE_WRITE
167Create an event when a writable file is closed.
168.TP
169.B FAN_CLOSE_NOWRITE
170Create an event when a read-only file or directory is closed.
171.TP
172.B FAN_OPEN
173Create an event when a file or directory is opened.
174.TP
bbd7edea 175.BR FAN_OPEN_EXEC " (since Linux 5.0)"
10fa1da2 176.\" commit 9b076f1c0f4869b838a1b7aa0edb5664d47ec8aa
fc37d2f1 177Create an event when a file is opened with the intent to be executed.
fd1eb8a7 178See NOTES for additional details.
fc37d2f1 179.TP
10fa1da2
JW
180.BR FAN_ATTRIB " (since Linux 5.1)"
181.\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
0a4db6dc 182Create an event when the metadata for a file or directory has changed.
b216da61 183An fanotify group that identifies filesystem objects by file handles
d71c9b4a 184is required.
0a4db6dc 185.TP
10fa1da2
JW
186.BR FAN_CREATE " (since Linux 5.1)"
187.\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
0a4db6dc
MB
188Create an event when a file or directory has been created in a marked
189parent directory.
b216da61 190An fanotify group that identifies filesystem objects by file handles
d71c9b4a 191is required.
0a4db6dc 192.TP
10fa1da2
JW
193.BR FAN_DELETE " (since Linux 5.1)"
194.\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
0a4db6dc
MB
195Create an event when a file or directory has been deleted in a marked
196parent directory.
b216da61 197An fanotify group that identifies filesystem objects by file handles
d71c9b4a 198is required.
0a4db6dc 199.TP
10fa1da2
JW
200.BR FAN_DELETE_SELF " (since Linux 5.1)"
201.\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
0a4db6dc 202Create an event when a marked file or directory itself is deleted.
b216da61 203An fanotify group that identifies filesystem objects by file handles
d71c9b4a 204is required.
0a4db6dc 205.TP
10fa1da2
JW
206.BR FAN_MOVED_FROM " (since Linux 5.1)"
207.\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
0a4db6dc
MB
208Create an event when a file or directory has been moved from a marked
209parent directory.
b216da61 210An fanotify group that identifies filesystem objects by file handles
d71c9b4a 211is required.
0a4db6dc 212.TP
10fa1da2
JW
213.BR FAN_MOVED_TO " (since Linux 5.1)"
214.\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
0a4db6dc
MB
215Create an event when a file or directory has been moved to a marked parent
216directory.
b216da61 217An fanotify group that identifies filesystem objects by file handles
d71c9b4a 218is required.
0a4db6dc 219.TP
b5e1b804
JW
220.BR FAN_MOVE_SELF " (since Linux 5.1)"
221.\" commit 235328d1fa4251c6dcb32351219bb553a58838d2
222Create an event when a marked file or directory itself has been moved.
b216da61 223An fanotify group that identifies filesystem objects by file handles
d71c9b4a 224is required.
b5e1b804 225.TP
c200b422
HS
226.B FAN_OPEN_PERM
227Create an event when a permission to open a file or directory is requested.
228An fanotify file descriptor created with
229.B FAN_CLASS_PRE_CONTENT
230or
231.B FAN_CLASS_CONTENT
232is required.
233.TP
fd1eb8a7 234.BR FAN_OPEN_EXEC_PERM " (since Linux 5.0)"
10fa1da2 235.\" commit 66917a3130f218dcef9eeab4fd11a71cd00cd7c9
fc37d2f1
MB
236Create an event when a permission to open a file for execution is
237requested.
238An fanotify file descriptor created with
239.B FAN_CLASS_PRE_CONTENT
240or
241.B FAN_CLASS_CONTENT
242is required.
fd1eb8a7 243See NOTES for additional details.
fc37d2f1 244.TP
c200b422
HS
245.B FAN_ACCESS_PERM
246Create an event when a permission to read a file or directory is requested.
247An fanotify file descriptor created with
248.B FAN_CLASS_PRE_CONTENT
249or
250.B FAN_CLASS_CONTENT
251is required.
252.TP
253.B FAN_ONDIR
817c8240 254Create events for directories\(emfor example, when
834e5597
MK
255.BR opendir (3),
256.BR readdir (3)
c200b422 257(but see BUGS), and
834e5597 258.BR closedir (3)
c200b422 259are called.
e9898cc8 260Without this flag, events are created only for files.
0a4db6dc
MB
261In the context of directory entry events, such as
262.BR FAN_CREATE ,
263.BR FAN_DELETE ,
817c8240 264.BR FAN_MOVED_FROM ,
0a4db6dc 265and
e9898cc8
AG
266.BR FAN_MOVED_TO ,
267specifying the flag
1ae6b2c7 268.B FAN_ONDIR
0a4db6dc 269is required in order to create events when subdirectory entries are
817c8240
MK
270modified (i.e.,
271.BR mkdir (2)/
272.BR rmdir (2)).
c200b422
HS
273.TP
274.B FAN_EVENT_ON_CHILD
275Events for the immediate children of marked directories shall be created.
b2f8214d 276The flag has no effect when marking mounts and filesystems.
c200b422
HS
277Note that events are not generated for children of the subdirectories
278of marked directories.
1f20a880
AG
279More specifically, the directory entry modification events
280.BR FAN_CREATE ,
281.BR FAN_DELETE ,
3af84490 282.BR FAN_MOVED_FROM ,
1f20a880 283and
1ae6b2c7 284.B FAN_MOVED_TO
1f20a880
AG
285are not generated for any entry modifications performed inside subdirectories
286of marked directories.
287Note that the events
1ae6b2c7 288.B FAN_DELETE_SELF
1f20a880 289and
1ae6b2c7 290.B FAN_MOVE_SELF
1f20a880 291are not generated for children of marked directories.
c200b422 292To monitor complete directory trees it is necessary to mark the relevant
1f20a880 293mount or filesystem.
c200b422 294.PP
0a4db6dc 295The following composed values are defined:
c200b422
HS
296.TP
297.B FAN_CLOSE
298A file is closed
299.RB ( FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE ).
0a4db6dc
MB
300.TP
301.B FAN_MOVE
302A file or directory has been moved
303.RB ( FAN_MOVED_FROM | FAN_MOVED_TO ).
c200b422
HS
304.PP
305The filesystem object to be marked is determined by the file descriptor
306.I dirfd
307and the pathname specified in
308.IR pathname :
309.IP * 3
310If
311.I pathname
312is NULL,
313.I dirfd
314defines the filesystem object to be marked.
315.IP *
316If
317.I pathname
318is NULL, and
319.I dirfd
320takes the special value
321.BR AT_FDCWD ,
322the current working directory is to be marked.
323.IP *
324If
325.I pathname
326is absolute, it defines the filesystem object to be marked, and
327.I dirfd
328is ignored.
329.IP *
330If
331.I pathname
332is relative, and
333.I dirfd
334does not have the value
335.BR AT_FDCWD ,
336then the filesystem object to be marked is determined by interpreting
337.I pathname
338relative the directory referred to by
339.IR dirfd .
340.IP *
341If
342.I pathname
343is relative, and
344.I dirfd
345has the value
9fdb563e 346.BR AT_FDCWD ,
c200b422
HS
347then the filesystem object to be marked is determined by interpreting
348.I pathname
3c39ce85 349relative to the current working directory.
717c3a7d
MK
350(See
351.BR openat (2)
352for an explanation of why the
353.I dirfd
354argument is useful.)
c200b422
HS
355.SH RETURN VALUE
356On success,
357.BR fanotify_mark ()
358returns 0.
b3470de1 359On error, \-1 is returned, and
c200b422
HS
360.I errno
361is set to indicate the error.
362.SH ERRORS
363.TP
364.B EBADF
365An invalid file descriptor was passed in
366.IR fanotify_fd .
367.TP
38a35006
MK
368.B EBADF
369.I pathname
370is relative but
371.I dirfd
372is neither
373.B AT_FDCWD
374nor a valid file descriptor.
375.TP
c200b422
HS
376.B EINVAL
377An invalid value was passed in
1ae6b2c7 378.I flags
c200b422
HS
379or
380.IR mask ,
381or
382.I fanotify_fd
383was not an fanotify file descriptor.
384.TP
385.B EINVAL
386The fanotify file descriptor was opened with
387.B FAN_CLASS_NOTIF
b216da61 388or the fanotify group identifies filesystem objects by file handles
c200b422
HS
389and mask contains a flag for permission events
390.RB ( FAN_OPEN_PERM
391or
392.BR FAN_ACCESS_PERM ).
393.TP
49a2a105
MK
394.B ENODEV
395The filesystem object indicated by
396.I pathname
397is not associated with a filesystem that supports
398.I fsid
399(e.g.,
d6a514ba
AG
400.BR fuse (4)).
401.BR tmpfs (5)
402did not support
403.I fsid
404prior to Linux 5.13.
405.\" commit 59cda49ecf6c9a32fae4942420701b6e087204f6
b216da61
AG
406This error can be returned only with an fanotify group that identifies
407filesystem objects by file handles.
49a2a105 408.TP
c200b422
HS
409.B ENOENT
410The filesystem object indicated by
1ae6b2c7 411.I dirfd
c200b422 412and
1ae6b2c7 413.I pathname
c200b422 414does not exist.
1b24e2ee
MK
415This error also occurs when trying to remove a mark from an object
416which is not marked.
c200b422
HS
417.TP
418.B ENOMEM
419The necessary memory could not be allocated.
420.TP
421.B ENOSPC
39bab785 422The number of marks for this user exceeds the limit and the
c200b422 423.B FAN_UNLIMITED_MARKS
d4a12c12 424flag was not specified when the fanotify file descriptor was created with
c200b422 425.BR fanotify_init (2).
39bab785
AG
426See
427.BR fanotify (7)
428for details about this limit.
c200b422 429.TP
89ba4cc2
MK
430.B ENOSYS
431This kernel does not implement
ffb30e75 432.BR fanotify_mark ().
d4a12c12
MK
433The fanotify API is available only if the kernel was configured with
434.BR CONFIG_FANOTIFY .
89ba4cc2 435.TP
c200b422
HS
436.B ENOTDIR
437.I flags
438contains
439.BR FAN_MARK_ONLYDIR ,
440and
441.I dirfd
442and
443.I pathname
444do not specify a directory.
0a4db6dc 445.TP
49a2a105
MK
446.B EOPNOTSUPP
447The object indicated by
0a4db6dc 448.I pathname
49a2a105
MK
449is associated with a filesystem that does not support the encoding of file
450handles.
b216da61
AG
451This error can be returned only with an fanotify group that identifies
452filesystem objects by file handles.
0a4db6dc 453.TP
69e6b644
MB
454.B EPERM
455The operation is not permitted because the caller lacks a required capability.
456.TP
49a2a105 457.B EXDEV
eae836e0 458The filesystem object indicated by
0a4db6dc 459.I pathname
49a2a105
MK
460resides within a filesystem subvolume (e.g.,
461.BR btrfs (5))
462which uses a different
0a4db6dc 463.I fsid
49a2a105 464than its root superblock.
b216da61
AG
465This error can be returned only with an fanotify group that identifies
466filesystem objects by file handles.
c200b422
HS
467.SH VERSIONS
468.BR fanotify_mark ()
469was introduced in version 2.6.36 of the Linux kernel and enabled in version
4702.6.37.
471.SH CONFORMING TO
472This system call is Linux-specific.
fc37d2f1 473.SH NOTES
fd1eb8a7 474.SS FAN_OPEN_EXEC and FAN_OPEN_EXEC_PERM
fc37d2f1
MB
475When using either
476.B FAN_OPEN_EXEC
477or
478.B FAN_OPEN_EXEC_PERM
479within the
480.IR mask ,
fd1eb8a7 481events of these types will be returned only when the direct execution of a
fc37d2f1 482program occurs.
fd1eb8a7
MK
483More specifically, this means that events of these types will be generated
484for files that are opened using
485.BR execve (2),
486.BR execveat (2),
fc37d2f1 487or
fd1eb8a7 488.BR uselib (2).
fc37d2f1 489Events of these types will not be raised in the situation where an
9b89b9dd 490interpreter is passed (or reads) a file for interpretation.
fc37d2f1
MB
491.PP
492Additionally, if a mark has also been placed on the Linux dynamic
fd1eb8a7
MK
493linker, a user should also expect to receive an event for it when
494an ELF object has been successfully opened using
495.BR execve (2)
fc37d2f1 496or
fd1eb8a7 497.BR execveat (2).
fc37d2f1
MB
498.PP
499For example, if the following ELF binary were to be invoked and a
1ae6b2c7 500.B FAN_OPEN_EXEC
fc37d2f1
MB
501mark has been placed on /:
502.PP
fd1eb8a7 503.in +4n
fc37d2f1 504.EX
fd1eb8a7 505$ /bin/echo foo
fc37d2f1 506.EE
fd1eb8a7 507.in
fc37d2f1 508.PP
fd1eb8a7 509The listening application in this case would receive
1ae6b2c7 510.B FAN_OPEN_EXEC
fd1eb8a7 511events for both the ELF binary and interpreter, respectively:
fc37d2f1 512.PP
fd1eb8a7 513.in +4n
fc37d2f1 514.EX
fd1eb8a7 515/bin/echo
d064d41a 516/lib64/ld\-linux\-x86\-64.so.2
fc37d2f1 517.EE
fd1eb8a7 518.in
c200b422 519.SH BUGS
e5209a5a 520The following bugs were present in Linux kernels before version 3.16:
c200b422 521.IP * 3
e5209a5a 522.\" Fixed by commit 0a8dd2db579f7a0ac7033d6b857c3d5dbaa77563
c200b422
HS
523If
524.I flags
525contains
526.BR FAN_MARK_FLUSH ,
d556548b 527.IR dirfd ,
c200b422
HS
528and
529.I pathname
4ac7d313 530must specify a valid filesystem object, even though this object is not used.
c200b422 531.IP *
e5209a5a 532.\" Fixed by commit d4c7cf6cffb1bc711a833b5e304ba5bcfe76398b
c200b422 533.BR readdir (2)
97ef170a 534does not generate a
c200b422
HS
535.B FAN_ACCESS
536event.
537.IP *
e5209a5a 538.\" Fixed by commit cc299a98eb13a9853675a9cbb90b30b4011e1406
c200b422 539If
bf7bc8b8 540.BR fanotify_mark ()
c200b422 541is called with
f2f50fed 542.BR FAN_MARK_FLUSH ,
c200b422
HS
543.I flags
544is not checked for invalid values.
545.SH SEE ALSO
546.BR fanotify_init (2),
547.BR fanotify (7)