-
Notifications
You must be signed in to change notification settings - Fork 0
/
fanotify_init.html
450 lines (336 loc) · 13 KB
/
fanotify_init.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:26:54 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>FANOTIFY_INIT</title>
</head>
<body>
<h1 align="center">FANOTIFY_INIT</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#VERSIONS">VERSIONS</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#BUGS">BUGS</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">fanotify_init -
create and initialize fanotify group</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<fcntl.h> <br>
#include <sys/fanotify.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>int
fanotify_init(unsigned int</b> <i>flags</i><b>, unsigned
int</b> <i>event_f_flags</i><b>);</b></p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">For an overview
of the fanotify API, see <b>fanotify</b>(7).</p>
<p style="margin-left:11%; margin-top: 1em"><b>fanotify_init</b>()
initializes a new fanotify group and returns a file
descriptor for the event queue associated with the
group.</p>
<p style="margin-left:11%; margin-top: 1em">The file
descriptor is used in calls to <b>fanotify_mark</b>(2) to
specify the files, directories, mounts or filesystems for
which fanotify events shall be created. These events are
received by reading from the file descriptor. Some events
are only informative, indicating that a file has been
accessed. Other events can be used to determine whether
another application is permitted to access a file or
directory. Permission to access filesystem objects is
granted by writing to the file descriptor.</p>
<p style="margin-left:11%; margin-top: 1em">Multiple
programs may be using the fanotify interface at the same
time to monitor the same files.</p>
<p style="margin-left:11%; margin-top: 1em">In the current
implementation, the number of fanotify groups per user is
limited to 128. This limit cannot be overridden.</p>
<p style="margin-left:11%; margin-top: 1em">Calling
<b>fanotify_init</b>() requires the <b>CAP_SYS_ADMIN</b>
capability. This constraint might be relaxed in future
versions of the API. Therefore, certain additional
capability checks have been implemented as indicated
below.</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>flags</i> argument contains a multi-bit field defining
the notification class of the listening application and
further single bit fields specifying the behavior of the
file descriptor.</p>
<p style="margin-left:11%; margin-top: 1em">If multiple
listeners for permission events exist, the notification
class is used to establish the sequence in which the
listeners receive the events.</p>
<p style="margin-left:11%; margin-top: 1em">Only one of the
following notification classes may be specified in
<i>flags</i>: <b><br>
FAN_CLASS_PRE_CONTENT</b></p>
<p style="margin-left:22%;">This value allows the receipt
of events notifying that a file has been accessed and events
for permission decisions if a file may be accessed. It is
intended for event listeners that need to access files
before they contain their final data. This notification
class might be used by hierarchical storage managers, for
example.</p>
<p style="margin-left:11%;"><b>FAN_CLASS_CONTENT</b></p>
<p style="margin-left:22%;">This value allows the receipt
of events notifying that a file has been accessed and events
for permission decisions if a file may be accessed. It is
intended for event listeners that need to access files when
they already contain their final content. This notification
class might be used by malware detection programs, for
example.</p>
<p style="margin-left:11%;"><b>FAN_REPORT_FID</b> (since
Linux 5.1)</p>
<p style="margin-left:22%;">This value allows the receipt
of events which contain additional information about the
underlying filesystem object correlated to an event. An
additional structure encapsulates the information about the
object and is included alongside the generic event metadata
structure. The file descriptor that is used to represent the
object correlated to an event is instead substituted with a
file handle. It is intended for applications that may find
the use of a file handle to identify an object more suitable
than a file descriptor. Additionally, it may be used for
applications that are interested in directory entry events,
such as <b>FAN_CREATE</b>, <b>FAN_ATTRIB</b>,
<b>FAN_MOVE</b>, and <b>FAN_DELETE</b> for example. Note
that the use of directory modification events are not
supported when monitoring a mount point. The use of
<b>FAN_CLASS_CONTENT</b> or <b>FAN_CLASS_PRE_CONTENT</b> is
not permitted with this flag and will result in the error
<b>EINVAL</b>. See <b>fanotify</b>(7) for additional
information.</p>
<p style="margin-left:11%;"><b>FAN_CLASS_NOTIF</b></p>
<p style="margin-left:22%;">This is the default value. It
does not need to be specified. This value only allows the
receipt of events notifying that a file has been accessed.
Permission decisions before the file is accessed are not
possible.</p>
<p style="margin-left:11%; margin-top: 1em">Listeners with
different notification classes will receive events in the
order <b>FAN_CLASS_PRE_CONTENT</b>,
<b>FAN_CLASS_CONTENT</b>, <b>FAN_CLASS_NOTIF</b>. The order
of notification for listeners in the same notification class
is undefined.</p>
<p style="margin-left:11%; margin-top: 1em">The following
bits can additionally be set in <i>flags</i>: <b><br>
FAN_CLOEXEC</b></p>
<p style="margin-left:22%;">Set the close-on-exec flag
(<b>FD_CLOEXEC</b>) on the new file descriptor. See the
description of the <b>O_CLOEXEC</b> flag in
<b>open</b>(2).</p>
<p style="margin-left:11%;"><b>FAN_NONBLOCK</b></p>
<p style="margin-left:22%;">Enable the nonblocking flag
(<b>O_NONBLOCK</b>) for the file descriptor. Reading from
the file descriptor will not block. Instead, if no data is
available, <b>read</b>(2) fails with the error
<b>EAGAIN</b>.</p>
<p style="margin-left:11%;"><b>FAN_UNLIMITED_QUEUE</b></p>
<p style="margin-left:22%;">Remove the limit of 16384
events for the event queue. Use of this flag requires the
<b>CAP_SYS_ADMIN</b> capability.</p>
<p style="margin-left:11%;"><b>FAN_UNLIMITED_MARKS</b></p>
<p style="margin-left:22%;">Remove the limit of 8192 marks.
Use of this flag requires the <b>CAP_SYS_ADMIN</b>
capability.</p>
<p style="margin-left:11%;"><b>FAN_REPORT_TID</b> (since
Linux 4.20)</p>
<p style="margin-left:22%;">Report thread ID (TID) instead
of process ID (PID) in the <i>pid</i> field of the <i>struct
fanotify_event_metadata</i> supplied to <b>read</b>(2) (see
<b>fanotify</b>(7)).</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>event_f_flags</i> argument defines the file status flags
that will be set on the open file descriptions that are
created for fanotify events. For details of these flags, see
the description of the <i>flags</i> values in
<b>open</b>(2). <i>event_f_flags</i> includes a multi-bit
field for the access mode. This field can take the following
values: <b><br>
O_RDONLY</b></p>
<p style="margin-left:22%;">This value allows only read
access.</p>
<p style="margin-left:11%;"><b>O_WRONLY</b></p>
<p style="margin-left:22%;">This value allows only write
access.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>O_RDWR</b></p></td>
<td width="2%"></td>
<td width="61%">
<p>This value allows read and write access.</p></td>
<td width="17%">
</td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">Additional bits
can be set in <i>event_f_flags</i>. The most useful values
are: <b><br>
O_LARGEFILE</b></p>
<p style="margin-left:22%;">Enable support for files
exceeding 2 GB. Failing to set this flag will result in
an <b>EOVERFLOW</b> error when trying to open a large file
which is monitored by an fanotify group on a 32-bit
system.</p>
<p style="margin-left:11%;"><b>O_CLOEXEC</b> (since Linux
3.18)</p>
<p style="margin-left:22%;">Enable the close-on-exec flag
for the file descriptor. See the description of the
<b>O_CLOEXEC</b> flag in <b>open</b>(2) for reasons why this
may be useful.</p>
<p style="margin-left:11%; margin-top: 1em">The following
are also allowable: <b>O_APPEND</b>, <b>O_DSYNC</b>,
<b>O_NOATIME</b>, <b>O_NONBLOCK</b>, and <b>O_SYNC</b>.
Specifying any other flag in <i>event_f_flags</i> yields the
error <b>EINVAL</b> (but see BUGS).</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">On success,
<b>fanotify_init</b>() returns a new file descriptor. On
error, -1 is returned, and <i>errno</i> is set to indicate
the error.</p>
<h2>ERRORS
<a name="ERRORS"></a>
</h2>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em">An invalid value was passed in
<i>flags</i> or <i>event_f_flags</i>.
<b>FAN_ALL_INIT_FLAGS</b> (deprecated since Linux kernel
version 4.20) defines all allowable bits for
<i>flags</i>.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EMFILE</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The number of fanotify groups for this user exceeds
128.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EMFILE</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The per-process limit on the number of open file
descriptors has been reached.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOMEM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The allocation of memory for the notification group
failed.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOSYS</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>This kernel does not implement <b>fanotify_init</b>().
The fanotify API is available only if the kernel was
configured with <b>CONFIG_FANOTIFY</b>.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EPERM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The operation is not permitted because the caller lacks
the <b>CAP_SYS_ADMIN</b> capability.</p></td></tr>
</table>
<h2>VERSIONS
<a name="VERSIONS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>fanotify_init</b>()
was introduced in version 2.6.36 of the Linux kernel and
enabled in version 2.6.37.</p>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This system
call is Linux-specific.</p>
<h2>BUGS
<a name="BUGS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">The following
bug was present in Linux kernels before version 3.18:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p style="margin-top: 1em">*</p></td>
<td width="3%"></td>
<td width="83%">
<p style="margin-top: 1em">The <b>O_CLOEXEC</b> is ignored
when passed in <i>event_f_flags</i>.</p></td>
<td width="2%">
</td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">The following
bug was present in Linux kernels before version 3.14:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p style="margin-top: 1em">*</p></td>
<td width="3%"></td>
<td width="85%">
<p style="margin-top: 1em">The <i>event_f_flags</i>
argument is not checked for invalid flags. Flags that are
intended only for internal use, such as <b>FMODE_EXEC</b>,
can be set, and will consequently be set for the file
descriptors returned when reading from the fanotify file
descriptor.</p> </td></tr>
</table>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>fanotify_mark</b>(2),
<b>fanotify</b>(7)</p>
<h2>COLOPHON
<a name="COLOPHON"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This page is
part of release 5.02 of the Linux <i>man-pages</i> project.
A description of the project, information about reporting
bugs, and the latest version of this page, can be found at
https://www.kernel.org/doc/man-pages/.</p>
<hr>
</body>
</html>