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_INIT 2 2017-09-15 "Linux" "Linux Programmer's Manual"
26 fanotify_init \- create and initialize fanotify group
30 .B #include <sys/fanotify.h>
32 .BI "int fanotify_init(unsigned int " flags ", unsigned int " event_f_flags );
34 For an overview of the fanotify API, see
38 initializes a new fanotify group and returns a file descriptor for the event
39 queue associated with the group.
41 The file descriptor is used in calls to
43 to specify the files, directories, and mounts for which fanotify events
45 These events are received by reading from the file descriptor.
46 Some events are only informative, indicating that a file has been accessed.
47 Other events can be used to determine whether
48 another application is permitted to access a file or directory.
49 Permission to access filesystem objects is granted by writing to the file
52 Multiple programs may be using the fanotify interface at the same time to
53 monitor the same files.
55 In the current implementation, the number of fanotify groups per user is
57 This limit cannot be overridden.
64 This constraint might be relaxed in future versions of the API.
65 Therefore, certain additional capability checks have been implemented as
70 argument contains a multi-bit field defining the notification class of the
71 listening application and further single bit fields specifying the behavior
72 of the file descriptor.
74 If multiple listeners for permission events exist,
75 the notification class is used to establish the sequence
76 in which the listeners receive the events.
78 Only one of the following notification classes may be specified in
81 .B FAN_CLASS_PRE_CONTENT
82 This value allows the receipt of events notifying that a file has been
83 accessed and events for permission decisions if a file may be accessed.
84 It is intended for event listeners that need to access files before they
85 contain their final data.
86 This notification class might be used by hierarchical storage managers,
90 This value allows the receipt of events notifying that a file has been
91 accessed and events for permission decisions if a file may be accessed.
92 It is intended for event listeners that need to access files when they
93 already contain their final content.
94 This notification class might be used by malware detection programs, for
98 This is the default value.
99 It does not need to be specified.
100 This value only allows the receipt of events notifying that a file has been
102 Permission decisions before the file is accessed are not possible.
104 Listeners with different notification classes will receive events in the
106 .BR FAN_CLASS_PRE_CONTENT ,
107 .BR FAN_CLASS_CONTENT ,
108 .BR FAN_CLASS_NOTIF .
109 The order of notification for listeners in the same notification class
112 The following bits can additionally be set in
116 Set the close-on-exec flag
118 on the new file descriptor.
119 See the description of the
125 Enable the nonblocking flag
127 for the file descriptor.
128 Reading from the file descriptor will not block.
129 Instead, if no data is available,
134 .B FAN_UNLIMITED_QUEUE
135 Remove the limit of 16384 events for the event queue.
136 Use of this flag requires the
140 .B FAN_UNLIMITED_MARKS
141 Remove the limit of 8192 marks.
142 Use of this flag requires the
149 defines the file status flags that will be set on the open file descriptions
150 that are created for fanotify events.
151 For details of these flags, see the description of the
156 includes a multi-bit field for the access mode.
157 This field can take the following values:
160 This value allows only read access.
163 This value allows only write access.
166 This value allows read and write access.
168 Additional bits can be set in
170 The most useful values are:
173 Enable support for files exceeding 2\ GB.
174 Failing to set this flag will result in an
176 error when trying to open a large file which is monitored by
177 an fanotify group on a 32-bit system.
179 .BR O_CLOEXEC " (since Linux 3.18)"
180 .\" commit 0b37e097a648aa71d4db1ad108001e95b69a2da4
181 Enable the close-on-exec flag for the file descriptor.
182 See the description of the
186 for reasons why this may be useful.
188 The following are also allowable:
195 Specifying any other flag in
203 returns a new file descriptor.
204 On error, \-1 is returned, and
206 is set to indicate the error.
210 An invalid value was passed in
214 .B FAN_ALL_INIT_FLAGS
215 defines all allowable bits for
219 The number of fanotify groups for this user exceeds 128.
222 The per-process limit on the number of open file descriptors has been reached.
225 The allocation of memory for the notification group failed.
228 This kernel does not implement
229 .BR fanotify_init ().
230 The fanotify API is available only if the kernel was configured with
231 .BR CONFIG_FANOTIFY .
234 The operation is not permitted because the caller lacks the
239 was introduced in version 2.6.36 of the Linux kernel and enabled in version
242 This system call is Linux-specific.
244 The following bug was present in Linux kernels before version 3.18:
246 .\" Fixed by commit 0b37e097a648aa71d4db1ad108001e95b69a2da4
249 is ignored when passed in
252 The following bug was present in Linux kernels before version 3.14:
254 .\" Fixed by commit 48149e9d3a7e924010a0daab30a6197b7d7b6580
257 argument is not checked for invalid flags.
258 Flags that are intended only for internal use,
261 can be set, and will consequently be set for the file descriptors
262 returned when reading from the fanotify file descriptor.
264 .BR fanotify_mark (2),