]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/fanotify_init.2
fanotify_init.2, fanotify.7: Document FAN_REPORT_TID
[thirdparty/man-pages.git] / man2 / fanotify_init.2
CommitLineData
3e6ebb33
HS
1.\" Copyright (C) 2013, Heinrich Schuchardt <xypron.glpk@gmx.de>
2.\"
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.
7.\"
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.
12.\"
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.
19.\" professionally.
20.\"
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
23.\" %%%LICENSE_END
4b8c67d9 24.TH FANOTIFY_INIT 2 2017-09-15 "Linux" "Linux Programmer's Manual"
3e6ebb33
HS
25.SH NAME
26fanotify_init \- create and initialize fanotify group
27.SH SYNOPSIS
28.B #include <fcntl.h>
29.br
30.B #include <sys/fanotify.h>
080522cb 31.PP
3e6ebb33
HS
32.BI "int fanotify_init(unsigned int " flags ", unsigned int " event_f_flags );
33.SH DESCRIPTION
34For an overview of the fanotify API, see
35.BR fanotify (7).
36.PP
37.BR fanotify_init ()
38initializes a new fanotify group and returns a file descriptor for the event
39queue associated with the group.
40.PP
41The file descriptor is used in calls to
42.BR fanotify_mark (2)
1b24e2ee
MK
43to specify the files, directories, and mounts for which fanotify events
44shall be created.
3e6ebb33
HS
45These events are received by reading from the file descriptor.
46Some events are only informative, indicating that a file has been accessed.
72b14a93
MK
47Other events can be used to determine whether
48another application is permitted to access a file or directory.
3e6ebb33
HS
49Permission to access filesystem objects is granted by writing to the file
50descriptor.
51.PP
52Multiple programs may be using the fanotify interface at the same time to
53monitor the same files.
54.PP
55In the current implementation, the number of fanotify groups per user is
56limited to 128.
57This limit cannot be overridden.
58.PP
59Calling
60.BR fanotify_init ()
61requires the
62.B CAP_SYS_ADMIN
63capability.
64This constraint might be relaxed in future versions of the API.
f1282fd0 65Therefore, certain additional capability checks have been implemented as
3e6ebb33
HS
66indicated below.
67.PP
68The
69.I flags
70argument contains a multi-bit field defining the notification class of the
1b24e2ee
MK
71listening application and further single bit fields specifying the behavior
72of the file descriptor.
3e6ebb33 73.PP
1b24e2ee
MK
74If multiple listeners for permission events exist,
75the notification class is used to establish the sequence
76in which the listeners receive the events.
3e6ebb33 77.PP
d58f4190
MK
78Only one of the following notification classes may be specified in
79.IR flags :
3e6ebb33
HS
80.TP
81.B FAN_CLASS_PRE_CONTENT
82This value allows the receipt of events notifying that a file has been
83accessed and events for permission decisions if a file may be accessed.
84It is intended for event listeners that need to access files before they
85contain their final data.
1b24e2ee
MK
86This notification class might be used by hierarchical storage managers,
87for example.
3e6ebb33
HS
88.TP
89.B FAN_CLASS_CONTENT
90This value allows the receipt of events notifying that a file has been
91accessed and events for permission decisions if a file may be accessed.
1b24e2ee
MK
92It is intended for event listeners that need to access files when they
93already contain their final content.
3e6ebb33
HS
94This notification class might be used by malware detection programs, for
95example.
96.TP
97.B FAN_CLASS_NOTIF
98This is the default value.
99It does not need to be specified.
100This value only allows the receipt of events notifying that a file has been
101accessed.
102Permission decisions before the file is accessed are not possible.
103.PP
104Listeners with different notification classes will receive events in the
cd505a8a 105order
3e6ebb33
HS
106.BR FAN_CLASS_PRE_CONTENT ,
107.BR FAN_CLASS_CONTENT ,
108.BR FAN_CLASS_NOTIF .
8d605e55
MK
109The order of notification for listeners in the same notification class
110is undefined.
3e6ebb33 111.PP
8d605e55 112The following bits can additionally be set in
3e6ebb33
HS
113.IR flags :
114.TP
115.B FAN_CLOEXEC
8d605e55 116Set the close-on-exec flag
3e6ebb33
HS
117.RB ( FD_CLOEXEC )
118on the new file descriptor.
119See the description of the
120.B O_CLOEXEC
121flag in
122.BR open (2).
123.TP
124.B FAN_NONBLOCK
8d605e55 125Enable the nonblocking flag
3e6ebb33
HS
126.RB ( O_NONBLOCK )
127for the file descriptor.
128Reading from the file descriptor will not block.
f199b308 129Instead, if no data is available,
3e6ebb33 130.BR read (2)
a23d8efa 131fails with the error
f199b308 132.BR EAGAIN .
3e6ebb33
HS
133.TP
134.B FAN_UNLIMITED_QUEUE
8d605e55
MK
135Remove the limit of 16384 events for the event queue.
136Use of this flag requires the
3e6ebb33
HS
137.B CAP_SYS_ADMIN
138capability.
139.TP
140.B FAN_UNLIMITED_MARKS
8d605e55
MK
141Remove the limit of 8192 marks.
142Use of this flag requires the
3e6ebb33
HS
143.B CAP_SYS_ADMIN
144capability.
ebfb6fee 145.TP
146.BR FAN_REPORT_TID " (since Linux 4.20)"
147.\" commit d0a6a87e40da49cfc7954c491d3065a25a641b29
148Report thread id (TID) instead of process id (PID).
3e6ebb33 149.PP
8d605e55 150The
3e6ebb33 151.I event_f_flags
8d605e55
MK
152argument
153defines the file status flags that will be set on the open file descriptions
154that are created for fanotify events.
155For details of these flags, see the description of the
3e6ebb33 156.I flags
8d605e55
MK
157values in
158.BR open (2).
1caffed4 159.I event_f_flags
be5c465e 160includes a multi-bit field for the access mode.
1caffed4 161This field can take the following values:
3e6ebb33
HS
162.TP
163.B O_RDONLY
164This value allows only read access.
165.TP
166.B O_WRONLY
167This value allows only write access.
168.TP
169.B O_RDWR
170This value allows read and write access.
1caffed4
HS
171.PP
172Additional bits can be set in
173.IR event_f_flags .
174The most useful values are:
3e6ebb33
HS
175.TP
176.B O_LARGEFILE
c4b7e5ac 177Enable support for files exceeding 2\ GB.
3e6ebb33
HS
178Failing to set this flag will result in an
179.B EOVERFLOW
1b24e2ee
MK
180error when trying to open a large file which is monitored by
181an fanotify group on a 32-bit system.
1caffed4 182.TP
d38a09fc
MK
183.BR O_CLOEXEC " (since Linux 3.18)"
184.\" commit 0b37e097a648aa71d4db1ad108001e95b69a2da4
1caffed4 185Enable the close-on-exec flag for the file descriptor.
be5c465e
MK
186See the description of the
187.B O_CLOEXEC
188flag in
189.BR open (2)
190for reasons why this may be useful.
1caffed4
HS
191.PP
192The following are also allowable:
193.BR O_APPEND ,
194.BR O_DSYNC ,
195.BR O_NOATIME ,
196.BR O_NONBLOCK ,
197and
198.BR O_SYNC .
be5c465e
MK
199Specifying any other flag in
200.I event_f_flags
201yields the error
1caffed4
HS
202.B EINVAL
203(but see BUGS).
3e6ebb33
HS
204.SH RETURN VALUE
205On success,
206.BR fanotify_init ()
207returns a new file descriptor.
ddfa9db7 208On error, \-1 is returned, and
3e6ebb33
HS
209.I errno
210is set to indicate the error.
211.SH ERRORS
212.TP
213.B EINVAL
214An invalid value was passed in
1caffed4
HS
215.I flags
216or
217.IR event_f_flags .
3e6ebb33 218.B FAN_ALL_INIT_FLAGS
1caffed4
HS
219defines all allowable bits for
220.IR flags .
3e6ebb33
HS
221.TP
222.B EMFILE
8d605e55 223The number of fanotify groups for this user exceeds 128.
3e6ebb33 224.TP
356a2957 225.B EMFILE
71d597e9
MK
226The per-process limit on the number of open file descriptors has been reached.
227.TP
3e6ebb33
HS
228.B ENOMEM
229The allocation of memory for the notification group failed.
230.TP
a8972eed
HS
231.B ENOSYS
232This kernel does not implement
233.BR fanotify_init ().
8d605e55
MK
234The fanotify API is available only if the kernel was configured with
235.BR CONFIG_FANOTIFY .
a8972eed 236.TP
3e6ebb33
HS
237.B EPERM
238The operation is not permitted because the caller lacks the
239.B CAP_SYS_ADMIN
240capability.
241.SH VERSIONS
242.BR fanotify_init ()
243was introduced in version 2.6.36 of the Linux kernel and enabled in version
2442.6.37.
d282bb24 245.SH CONFORMING TO
3e6ebb33 246This system call is Linux-specific.
6448be7e 247.SH BUGS
692b4bcc 248The following bug was present in Linux kernels before version 3.18:
0d69c093 249.IP * 3
692b4bcc 250.\" Fixed by commit 0b37e097a648aa71d4db1ad108001e95b69a2da4
51d266b7 251The
0d69c093 252.B O_CLOEXEC
51d266b7
MK
253is ignored when passed in
254.IR event_f_flags .
0d69c093 255.PP
f479e19c 256The following bug was present in Linux kernels before version 3.14:
6448be7e 257.IP * 3
f479e19c 258.\" Fixed by commit 48149e9d3a7e924010a0daab30a6197b7d7b6580
20abed53 259The
6448be7e 260.I event_f_flags
491bc783 261argument is not checked for invalid flags.
20abed53
MK
262Flags that are intended only for internal use,
263such as
6448be7e 264.BR FMODE_EXEC ,
20abed53
MK
265can be set, and will consequently be set for the file descriptors
266returned when reading from the fanotify file descriptor.
d282bb24 267.SH SEE ALSO
3e6ebb33
HS
268.BR fanotify_mark (2),
269.BR fanotify (7)