OSDN Git Service

c88ee46ee4496b2e79e350d95ea8be6fa30993ba
[linuxjm/LDP_man-pages.git] / original / man2 / fanotify_init.2
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
24 .TH FANOTIFY_INIT 2 2014-10-02 "Linux" "Linux Programmer's Manual"
25 .SH NAME
26 fanotify_init \- create and initialize fanotify group
27 .SH SYNOPSIS
28 .B #include <fcntl.h>
29 .br
30 .B #include <sys/fanotify.h>
31 .sp
32 .BI "int fanotify_init(unsigned int " flags ", unsigned int " event_f_flags );
33 .SH DESCRIPTION
34 For an overview of the fanotify API, see
35 .BR fanotify (7).
36 .PP
37 .BR fanotify_init ()
38 initializes a new fanotify group and returns a file descriptor for the event
39 queue associated with the group.
40 .PP
41 The file descriptor is used in calls to
42 .BR fanotify_mark (2)
43 to specify the files, directories, and mounts for which fanotify events
44 shall be created.
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
50 descriptor.
51 .PP
52 Multiple programs may be using the fanotify interface at the same time to
53 monitor the same files.
54 .PP
55 In the current implementation, the number of fanotify groups per user is
56 limited to 128.
57 This limit cannot be overridden.
58 .PP
59 Calling
60 .BR fanotify_init ()
61 requires the
62 .B CAP_SYS_ADMIN
63 capability.
64 This constraint might be relaxed in future versions of the API.
65 Therefore, certain additional capability checks have been implemented as
66 indicated below.
67 .PP
68 The
69 .I flags
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.
73 .PP
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.
77 .PP
78 Only one of the following notification classes may be specified in
79 .IR flags :
80 .TP
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,
87 for example.
88 .TP
89 .B FAN_CLASS_CONTENT
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
95 example.
96 .TP
97 .B FAN_CLASS_NOTIF
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
101 accessed.
102 Permission decisions before the file is accessed are not possible.
103 .PP
104 Listeners with different notification classes will receive events in the
105 order
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
110 is undefined.
111 .PP
112 The following bits can additionally be set in
113 .IR flags :
114 .TP
115 .B FAN_CLOEXEC
116 Set the close-on-exec flag
117 .RB ( FD_CLOEXEC )
118 on the new file descriptor.
119 See the description of the
120 .B O_CLOEXEC
121 flag in
122 .BR open (2).
123 .TP
124 .B FAN_NONBLOCK
125 Enable the nonblocking flag
126 .RB ( O_NONBLOCK )
127 for the file descriptor.
128 Reading from the file descriptor will not block.
129 Instead, if no data is available,
130 .BR read (2)
131 will fail with the error
132 .BR EAGAIN .
133 .TP
134 .B FAN_UNLIMITED_QUEUE
135 Remove the limit of 16384 events for the event queue.
136 Use of this flag requires the
137 .B CAP_SYS_ADMIN
138 capability.
139 .TP
140 .B FAN_UNLIMITED_MARKS
141 Remove the limit of 8192 marks.
142 Use of this flag requires the
143 .B CAP_SYS_ADMIN
144 capability.
145 .PP
146 The
147 .I event_f_flags
148 argument
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
152 .I flags
153 values in
154 .BR open (2).
155 .I event_f_flags
156 includes a multi-bit field for the access mode.
157 This field can take the following values:
158 .TP
159 .B O_RDONLY
160 This value allows only read access.
161 .TP
162 .B O_WRONLY
163 This value allows only write access.
164 .TP
165 .B O_RDWR
166 This value allows read and write access.
167 .PP
168 Additional bits can be set in
169 .IR event_f_flags .
170 The most useful values are:
171 .TP
172 .B O_LARGEFILE
173 Enable support for files exceeding 2 GB.
174 Failing to set this flag will result in an
175 .B EOVERFLOW
176 error when trying to open a large file which is monitored by
177 an fanotify group on a 32-bit system.
178 .TP
179 .B O_CLOEXEC
180 Enable the close-on-exec flag for the file descriptor.
181 See the description of the
182 .B O_CLOEXEC
183 flag in
184 .BR open (2)
185 for reasons why this may be useful.
186 .PP
187 The following are also allowable:
188 .BR O_APPEND ,
189 .BR O_DSYNC ,
190 .BR O_NOATIME ,
191 .BR O_NONBLOCK ,
192 and
193 .BR O_SYNC .
194 Specifying any other flag in
195 .I event_f_flags
196 yields the error
197 .B EINVAL
198 (but see BUGS).
199 .SH RETURN VALUE
200 On success,
201 .BR fanotify_init ()
202 returns a new file descriptor.
203 On error, \-1 is returned, and
204 .I errno
205 is set to indicate the error.
206 .SH ERRORS
207 .TP
208 .B EINVAL
209 An invalid value was passed in
210 .I flags
211 or
212 .IR event_f_flags .
213 .B FAN_ALL_INIT_FLAGS
214 defines all allowable bits for
215 .IR flags .
216 .TP
217 .B EMFILE
218 The number of fanotify groups for this user exceeds 128.
219 .TP
220 .B ENOMEM
221 The allocation of memory for the notification group failed.
222 .TP
223 .B ENOSYS
224 This kernel does not implement
225 .BR fanotify_init ().
226 The fanotify API is available only if the kernel was configured with
227 .BR CONFIG_FANOTIFY .
228 .TP
229 .B EPERM
230 The operation is not permitted because the caller lacks the
231 .B CAP_SYS_ADMIN
232 capability.
233 .SH VERSIONS
234 .BR fanotify_init ()
235 was introduced in version 2.6.36 of the Linux kernel and enabled in version
236 2.6.37.
237 .SH "CONFORMING TO"
238 This system call is Linux-specific.
239 .SH BUGS
240 As of Linux 3.17,
241 the following bug exists:
242 .IP * 3
243 .\" FIXME . Patch proposed: https://lkml.org/lkml/2014/9/24/967
244 The
245 .B O_CLOEXEC
246 is ignored when passed in
247 .IR event_f_flags .
248 .PP
249 The following bug was present in Linux kernels before version 3.14:
250 .IP * 3
251 .\" Fixed by commit 48149e9d3a7e924010a0daab30a6197b7d7b6580
252 The
253 .I event_f_flags
254 argument is not checked for invalid flags.
255 Flags that are intended only for internal use,
256 such as
257 .BR FMODE_EXEC ,
258 can be set, and will consequently be set for the file descriptors
259 returned when reading from the fanotify file descriptor.
260 .SH "SEE ALSO"
261 .BR fanotify_mark (2),
262 .BR fanotify (7)
263 .SH COLOPHON
264 This page is part of release 3.78 of the Linux
265 .I man-pages
266 project.
267 A description of the project,
268 information about reporting bugs,
269 and the latest version of this page,
270 can be found at
271 \%http://www.kernel.org/doc/man\-pages/.