Debian Codegraph @

templates/man7/fanotify.7.pot

raw
1 # SOME DESCRIPTIVE TITLE
2 # Copyright (C) YEAR Free Software Foundation, Inc.
3 # This file is distributed under the same license as the PACKAGE package.
4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5 #
6 #, fuzzy
7 msgid ""
8 msgstr ""
9 "Project-Id-Version: PACKAGE VERSION\n"
10 "POT-Creation-Date: 2026-06-05 06:24+0200\n"
11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 "Language-Team: LANGUAGE <[email protected]>\n"
14 "Language: \n"
15 "MIME-Version: 1.0\n"
16 "Content-Type: text/plain; charset=UTF-8\n"
17 "Content-Transfer-Encoding: 8bit\n"
18
19 #. type: TH
20 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
21 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
22 #, no-wrap
23 msgid "fanotify"
24 msgstr ""
25
26 #. type: TH
27 #: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed
28 #, no-wrap
29 msgid "2026-02-14"
30 msgstr ""
31
32 #. type: TH
33 #: archlinux debian-unstable
34 #, no-wrap
35 msgid "Linux man-pages 6.18"
36 msgstr ""
37
38 #. type: SH
39 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
40 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
41 #, no-wrap
42 msgid "NAME"
43 msgstr ""
44
45 #. type: Plain text
46 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
47 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
48 msgid "fanotify - monitoring filesystem events"
49 msgstr ""
50
51 #. type: SH
52 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
53 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
54 #, no-wrap
55 msgid "DESCRIPTION"
56 msgstr ""
57
58 #. type: Plain text
59 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
60 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
61 msgid ""
62 "The fanotify API provides notification and interception of filesystem "
63 "events. Use cases include virus scanning and hierarchical storage "
64 "management. In the original fanotify API, only a limited set of events was "
65 "supported. In particular, there was no support for create, delete, and move "
66 "events. The support for those events was added in Linux 5.1. (See "
67 "B<inotify>(7) for details of an API that did notify those events pre Linux "
68 "5.1.)"
69 msgstr ""
70
71 #. type: Plain text
72 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
73 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
74 msgid ""
75 "Additional capabilities compared to the B<inotify>(7) API include the "
76 "ability to monitor all of the objects in a mounted filesystem, the ability "
77 "to make access permission decisions, and the possibility to read or modify "
78 "files before access by other applications."
79 msgstr ""
80
81 #. type: Plain text
82 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
83 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
84 msgid ""
85 "The following system calls are used with this API: B<fanotify_init>(2), "
86 "B<fanotify_mark>(2), B<read>(2), B<write>(2), and B<close>(2)."
87 msgstr ""
88
89 #. type: SS
90 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
91 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
92 #, no-wrap
93 msgid "fanotify_init(), fanotify_mark(), and notification groups"
94 msgstr ""
95
96 #. type: Plain text
97 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
98 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
99 msgid ""
100 "The B<fanotify_init>(2) system call creates and initializes an fanotify "
101 "notification group and returns a file descriptor referring to it."
102 msgstr ""
103
104 #. type: Plain text
105 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
106 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
107 msgid ""
108 "An fanotify notification group is a kernel-internal object that holds a list "
109 "of files, directories, filesystems, and mounts for which events shall be "
110 "created."
111 msgstr ""
112
113 #. type: Plain text
114 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
115 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
116 msgid ""
117 "For each entry in an fanotify notification group, two bit masks exist: the "
118 "I<mark> mask and the I<ignore> mask. The mark mask defines file activities "
119 "for which an event shall be created. The ignore mask defines activities for "
120 "which no event shall be generated. Having these two types of masks permits "
121 "a filesystem, mount, or directory to be marked for receiving events, while "
122 "at the same time ignoring events for specific objects under a mount or "
123 "directory."
124 msgstr ""
125
126 #. type: Plain text
127 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
128 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
129 msgid ""
130 "The B<fanotify_mark>(2) system call adds a file, directory, filesystem, or "
131 "mount to a notification group and specifies which events shall be reported "
132 "(or ignored), or removes or modifies such an entry."
133 msgstr ""
134
135 #. type: Plain text
136 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
137 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
138 msgid ""
139 "A possible usage of the ignore mask is for a file cache. Events of interest "
140 "for a file cache are modification of a file and closing of the same. Hence, "
141 "the cached directory or mount is to be marked to receive these events. "
142 "After receiving the first event informing that a file has been modified, the "
143 "corresponding cache entry will be invalidated. No further modification "
144 "events for this file are of interest until the file is closed. Hence, the "
145 "modify event can be added to the ignore mask. Upon receiving the close "
146 "event, the modify event can be removed from the ignore mask and the file "
147 "cache entry can be updated."
148 msgstr ""
149
150 #. type: Plain text
151 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
152 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
153 msgid ""
154 "The entries in the fanotify notification groups refer to files and "
155 "directories via their inode number and to mounts via their mount ID. If "
156 "files or directories are renamed or moved within the same mount, the "
157 "respective entries survive. If files or directories are deleted or moved to "
158 "another mount or if filesystems or mounts are unmounted, the corresponding "
159 "entries are deleted."
160 msgstr ""
161
162 #. type: SS
163 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
164 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
165 #, no-wrap
166 msgid "The event queue"
167 msgstr ""
168
169 #. type: Plain text
170 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
171 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
172 msgid ""
173 "As events occur on the filesystem objects monitored by a notification group, "
174 "the fanotify system generates events that are collected in a queue. These "
175 "events can then be read (using B<read>(2) or similar) from the fanotify "
176 "file descriptor returned by B<fanotify_init>(2)."
177 msgstr ""
178
179 #. type: Plain text
180 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
181 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
182 msgid ""
183 "Two types of events are generated: I<notification> events and I<permission> "
184 "events. Notification events are merely informative and require no action to "
185 "be taken by the receiving application with one exception: if a valid file "
186 "descriptor is provided within a generic event, the file descriptor must be "
187 "closed. Permission events are requests to the receiving application to "
188 "decide whether permission for a file access shall be granted. For these "
189 "events, the recipient must write a response which decides whether access is "
190 "granted or not."
191 msgstr ""
192
193 #. type: Plain text
194 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
195 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
196 msgid ""
197 "An event is removed from the event queue of the fanotify group when it has "
198 "been read. Permission events that have been read are kept in an internal "
199 "list of the fanotify group until either a permission decision has been taken "
200 "by writing to the fanotify file descriptor or the fanotify file descriptor "
201 "is closed."
202 msgstr ""
203
204 #. type: SS
205 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
206 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
207 #, no-wrap
208 msgid "Reading fanotify events"
209 msgstr ""
210
211 #. type: Plain text
212 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
213 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
214 msgid ""
215 "Calling B<read>(2) for the file descriptor returned by B<fanotify_init>(2) "
216 "blocks (if the flag B<FAN_NONBLOCK> is not specified in the call to "
217 "B<fanotify_init>(2)) until either a file event occurs or the call is "
218 "interrupted by a signal (see B<signal>(7))."
219 msgstr ""
220
221 #. type: Plain text
222 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
223 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
224 msgid ""
225 "After a successful B<read>(2), the read buffer contains one or more of the "
226 "following structures:"
227 msgstr ""
228
229 #. type: Plain text
230 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
231 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
232 #, no-wrap
233 msgid ""
234 "struct fanotify_event_metadata {\n"
235 " __u32 event_len;\n"
236 " __u8 vers;\n"
237 " __u8 reserved;\n"
238 " __u16 metadata_len;\n"
239 " __aligned_u64 mask;\n"
240 " __s32 fd;\n"
241 " __s32 pid;\n"
242 "};\n"
243 msgstr ""
244
245 #. type: Plain text
246 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
247 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
248 msgid ""
249 "Information records are supplemental pieces of information that may be "
250 "provided alongside the generic I<fanotify_event_metadata> structure. The "
251 "I<flags> passed to B<fanotify_init>(2) have influence over the type of "
252 "information records that may be returned for an event. For example, if a "
253 "notification group is initialized with B<FAN_REPORT_FID> or "
254 "B<FAN_REPORT_DIR_FID>, then event listeners should also expect to receive a "
255 "I<fanotify_event_info_fid> structure alongside the "
256 "I<fanotify_event_metadata> structure, whereby file handles are used to "
257 "identify filesystem objects rather than file descriptors. Information "
258 "records may also be stacked, meaning that using the various B<FAN_REPORT_*> "
259 "flags in conjunction with one another is supported. In such cases, multiple "
260 "information records can be returned for an event alongside the generic "
261 "I<fanotify_event_metadata> structure. For example, if a notification group "
262 "is initialized with B<FAN_REPORT_TARGET_FID> and B<FAN_REPORT_PIDFD>, then "
263 "an event listener should expect to receive up to two "
264 "I<fanotify_event_info_fid> information records and one "
265 "I<fanotify_event_info_pidfd> information record alongside the generic "
266 "I<fanotify_event_metadata> structure. Importantly, fanotify provides no "
267 "guarantee around the ordering of information records when a notification "
268 "group is initialized with a stacked based configuration. Each information "
269 "record has a nested structure of type I<fanotify_event_info_header>. It is "
270 "imperative for event listeners to inspect the I<info_type> field of this "
271 "structure in order to determine the type of information record that had been "
272 "received for a given event."
273 msgstr ""
274
275 #. type: Plain text
276 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
277 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
278 msgid ""
279 "In cases where an fanotify group identifies filesystem objects by file "
280 "handles, event listeners should also expect to receive one or more of the "
281 "below information record objects alongside the generic "
282 "I<fanotify_event_metadata> structure within the read buffer:"
283 msgstr ""
284
285 #. type: Plain text
286 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
287 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
288 #, no-wrap
289 msgid ""
290 "struct fanotify_event_info_fid {\n"
291 " struct fanotify_event_info_header hdr;\n"
292 " __kernel_fsid_t fsid;\n"
293 " unsigned char handle[];\n"
294 "};\n"
295 msgstr ""
296
297 #. type: Plain text
298 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
299 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
300 msgid ""
301 "In cases where an fanotify group is initialized with B<FAN_REPORT_PIDFD>, "
302 "event listeners should expect to receive the below information record object "
303 "alongside the generic I<fanotify_event_metadata> structure within the read "
304 "buffer:"
305 msgstr ""
306
307 #. type: Plain text
308 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
309 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
310 #, no-wrap
311 msgid ""
312 "struct fanotify_event_info_pidfd {\n"
313 " struct fanotify_event_info_header hdr;\n"
314 " __s32 pidfd;\n"
315 "};\n"
316 msgstr ""
317
318 #. type: Plain text
319 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
320 #: opensuse-tumbleweed
321 msgid ""
322 "In cases where an fanotify group is initialized with B<FAN_REPORT_MNT>, "
323 "event listeners should expect to receive the below information record object "
324 "alongside the generic I<fanotify_event_metadata> structure within the read "
325 "buffer. This structure is defined as follows:"
326 msgstr ""
327
328 #. type: Plain text
329 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
330 #: opensuse-tumbleweed
331 #, no-wrap
332 msgid ""
333 "struct fanotify_event_info_mnt {\n"
334 " struct fanotify_event_info_header hdr;\n"
335 " __u64 mnt_id;\n"
336 "};\n"
337 msgstr ""
338
339 #. type: Plain text
340 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
341 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
342 msgid ""
343 "In case of a B<FAN_FS_ERROR> event, an additional information record "
344 "describing the error that occurred is returned alongside the generic "
345 "I<fanotify_event_metadata> structure within the read buffer. This structure "
346 "is defined as follows:"
347 msgstr ""
348
349 #. type: Plain text
350 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
351 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
352 #, no-wrap
353 msgid ""
354 "struct fanotify_event_info_error {\n"
355 " struct fanotify_event_info_header hdr;\n"
356 " __s32 error;\n"
357 " __u32 error_count;\n"
358 "};\n"
359 msgstr ""
360
361 #. type: Plain text
362 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
363 #: opensuse-tumbleweed
364 msgid ""
365 "In case of B<FAN_PRE_ACCESS> events, an additional information record "
366 "describing the access range is returned alongside the generic "
367 "I<fanotify_event_metadata> structure within the read buffer. This structure "
368 "is defined as follows:"
369 msgstr ""
370
371 #. type: Plain text
372 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
373 #: opensuse-tumbleweed
374 #, no-wrap
375 msgid ""
376 "struct fanotify_event_info_range {\n"
377 " struct fanotify_event_info_header hdr;\n"
378 " __u32 pad;\n"
379 " __u64 offset;\n"
380 " __u64 count;\n"
381 "};\n"
382 msgstr ""
383
384 #. type: Plain text
385 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
386 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
387 msgid ""
388 "All information records contain a nested structure of type "
389 "I<fanotify_event_info_header>. This structure holds meta-information about "
390 "the information record that may have been returned alongside the generic "
391 "I<fanotify_event_metadata> structure. This structure is defined as follows:"
392 msgstr ""
393
394 #. type: Plain text
395 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
396 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
397 #, no-wrap
398 msgid ""
399 "struct fanotify_event_info_header {\n"
400 "\t__u8 info_type;\n"
401 "\t__u8 pad;\n"
402 "\t__u16 len;\n"
403 "};\n"
404 msgstr ""
405
406 #. type: Plain text
407 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
408 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
409 msgid ""
410 "For performance reasons, it is recommended to use a large buffer size (for "
411 "example, 4096 bytes), so that multiple events can be retrieved by a single "
412 "B<read>(2)."
413 msgstr ""
414
415 #. type: Plain text
416 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
417 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
418 msgid ""
419 "The return value of B<read>(2) is the number of bytes placed in the buffer, "
420 "or -1 in case of an error (but see BUGS)."
421 msgstr ""
422
423 #. type: Plain text
424 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
425 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
426 msgid "The fields of the I<fanotify_event_metadata> structure are as follows:"
427 msgstr ""
428
429 #. type: TP
430 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
431 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
432 #, no-wrap
433 msgid "I<event_len>"
434 msgstr ""
435
436 #. type: Plain text
437 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
438 #: opensuse-leap-16-1 opensuse-tumbleweed
439 msgid ""
440 "This is the size of the data for the current event and the offset to the "
441 "next event in the buffer. Unless the group identifies filesystem objects by "
442 "file handles, the value of I<event_len> is always "
443 "B<FAN_EVENT_METADATA_LEN>. For a group that identifies filesystem objects "
444 "by file handles, I<event_len> also includes the variable size file "
445 "identifier records."
446 msgstr ""
447
448 #. type: TP
449 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
450 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
451 #, no-wrap
452 msgid "I<vers>"
453 msgstr ""
454
455 #. type: Plain text
456 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
457 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
458 msgid ""
459 "This field holds a version number for the structure. It must be compared to "
460 "B<FANOTIFY_METADATA_VERSION> to verify that the structures returned at run "
461 "time match the structures defined at compile time. In case of a mismatch, "
462 "the application should abandon trying to use the fanotify file descriptor."
463 msgstr ""
464
465 #. type: TP
466 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
467 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
468 #, no-wrap
469 msgid "I<reserved>"
470 msgstr ""
471
472 #. type: Plain text
473 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
474 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
475 msgid "This field is not used."
476 msgstr ""
477
478 #. type: TP
479 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
480 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
481 #, no-wrap
482 msgid "I<metadata_len>"
483 msgstr ""
484
485 #. type: Plain text
486 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
487 #: opensuse-leap-16-1 opensuse-tumbleweed
488 msgid ""
489 "This is the size of the structure. The field was introduced to facilitate "
490 "the implementation of optional headers per event type. No such optional "
491 "headers exist in the current implementation."
492 msgstr ""
493
494 #. type: TP
495 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
496 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
497 #, no-wrap
498 msgid "I<mask>"
499 msgstr ""
500
501 #. type: Plain text
502 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
503 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
504 msgid "This is a bit mask describing the event (see below)."
505 msgstr ""
506
507 #. type: TP
508 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
509 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
510 #, no-wrap
511 msgid "I<fd>"
512 msgstr ""
513
514 #. type: Plain text
515 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
516 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
517 msgid ""
518 "This is an open file descriptor for the object being accessed, or "
519 "B<FAN_NOFD> if a queue overflow occurred. With an fanotify group that "
520 "identifies filesystem objects by file handles, applications should expect "
521 "this value to be set to B<FAN_NOFD> for each event that is received. The "
522 "file descriptor can be used to access the contents of the monitored file or "
523 "directory. The reading application is responsible for closing this file "
524 "descriptor."
525 msgstr ""
526
527 #. type: Plain text
528 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
529 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
530 msgid ""
531 "When calling B<fanotify_init>(2), the caller may specify (via the "
532 "I<event_f_flags> argument) various file status flags that are to be set on "
533 "the open file description that corresponds to this file descriptor. In "
534 "addition, the (kernel-internal) B<FMODE_NONOTIFY> file status flag is set "
535 "on the open file description. This flag suppresses fanotify event "
536 "generation. Hence, when the receiver of the fanotify event accesses the "
537 "notified file or directory using this file descriptor, no additional events "
538 "will be created."
539 msgstr ""
540
541 #. type: Plain text
542 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
543 #: opensuse-tumbleweed
544 msgid ""
545 "When an fanotify group is initialized using B<FAN_REPORT_FD_ERROR>, this "
546 "field will contain a negative error value in case a file descriptor could "
547 "not be opened and in case of a queue overflow, the value will be B<-EBADF>."
548 msgstr ""
549
550 #. type: TP
551 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
552 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
553 #, no-wrap
554 msgid "I<pid>"
555 msgstr ""
556
557 #. type: Plain text
558 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
559 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
560 msgid ""
561 "If flag B<FAN_REPORT_TID> was set in B<fanotify_init>(2), this is the TID of "
562 "the thread that caused the event. Otherwise, this the PID of the process "
563 "that caused the event."
564 msgstr ""
565
566 #. type: Plain text
567 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
568 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
569 msgid ""
570 "A program listening to fanotify events can compare this PID to the PID "
571 "returned by B<getpid>(2), to determine whether the event is caused by the "
572 "listener itself, or is due to a file access by another process."
573 msgstr ""
574
575 #. type: Plain text
576 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
577 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
578 msgid ""
579 "The bit mask in I<mask> indicates which events have occurred for a single "
580 "filesystem object. Multiple bits may be set in this mask, if more than one "
581 "event occurred for the monitored filesystem object. In particular, "
582 "consecutive events for the same filesystem object and originating from the "
583 "same process may be merged into a single event, with the exception that two "
584 "permission events are never merged into one queue entry."
585 msgstr ""
586
587 #. type: Plain text
588 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
589 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
590 msgid "The bits that may appear in I<mask> are as follows:"
591 msgstr ""
592
593 #. type: TP
594 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
595 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
596 #, no-wrap
597 msgid "B<FAN_ACCESS>"
598 msgstr ""
599
600 #. type: Plain text
601 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
602 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
603 msgid "A file or a directory (but see BUGS) was accessed (read)."
604 msgstr ""
605
606 #. type: TP
607 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
608 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
609 #, no-wrap
610 msgid "B<FAN_OPEN>"
611 msgstr ""
612
613 #. type: Plain text
614 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
615 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
616 msgid "A file or a directory was opened."
617 msgstr ""
618
619 #. type: TP
620 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
621 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
622 #, no-wrap
623 msgid "B<FAN_OPEN_EXEC>"
624 msgstr ""
625
626 #. type: Plain text
627 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
628 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
629 msgid ""
630 "A file was opened with the intent to be executed. See NOTES in "
631 "B<fanotify_mark>(2) for additional details."
632 msgstr ""
633
634 #. type: TP
635 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
636 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
637 #, no-wrap
638 msgid "B<FAN_ATTRIB>"
639 msgstr ""
640
641 #. type: Plain text
642 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
643 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
644 msgid "A file or directory metadata was changed."
645 msgstr ""
646
647 #. type: TP
648 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
649 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
650 #, no-wrap
651 msgid "B<FAN_CREATE>"
652 msgstr ""
653
654 #. type: Plain text
655 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
656 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
657 msgid "A child file or directory was created in a watched parent."
658 msgstr ""
659
660 #. type: TP
661 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
662 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
663 #, no-wrap
664 msgid "B<FAN_DELETE>"
665 msgstr ""
666
667 #. type: Plain text
668 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
669 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
670 msgid "A child file or directory was deleted in a watched parent."
671 msgstr ""
672
673 #. type: TP
674 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
675 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
676 #, no-wrap
677 msgid "B<FAN_DELETE_SELF>"
678 msgstr ""
679
680 #. type: Plain text
681 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
682 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
683 msgid "A watched file or directory was deleted."
684 msgstr ""
685
686 #. type: TP
687 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
688 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
689 #, no-wrap
690 msgid "B<FAN_RENAME>"
691 msgstr ""
692
693 #. type: Plain text
694 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
695 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
696 msgid ""
697 "A file or directory has been moved to or from a watched parent directory."
698 msgstr ""
699
700 #. type: TP
701 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
702 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
703 #, no-wrap
704 msgid "B<FAN_MOVED_FROM>"
705 msgstr ""
706
707 #. type: Plain text
708 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
709 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
710 msgid "A file or directory has been moved from a watched parent directory."
711 msgstr ""
712
713 #. type: TP
714 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
715 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
716 #, no-wrap
717 msgid "B<FAN_MOVED_TO>"
718 msgstr ""
719
720 #. type: Plain text
721 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
722 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
723 msgid "A file or directory has been moved to a watched parent directory."
724 msgstr ""
725
726 #. type: TP
727 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
728 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
729 #, no-wrap
730 msgid "B<FAN_MOVE_SELF>"
731 msgstr ""
732
733 #. type: Plain text
734 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
735 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
736 msgid "A watched file or directory was moved."
737 msgstr ""
738
739 #. type: TP
740 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
741 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
742 #, no-wrap
743 msgid "B<FAN_MODIFY>"
744 msgstr ""
745
746 #. type: Plain text
747 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
748 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
749 msgid "A file was modified."
750 msgstr ""
751
752 #. type: TP
753 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
754 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
755 #, no-wrap
756 msgid "B<FAN_CLOSE_WRITE>"
757 msgstr ""
758
759 #. type: Plain text
760 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
761 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
762 msgid ""
763 "A file that was opened for writing (B<O_WRONLY> or B<O_RDWR>) was closed."
764 msgstr ""
765
766 #. type: TP
767 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
768 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
769 #, no-wrap
770 msgid "B<FAN_CLOSE_NOWRITE>"
771 msgstr ""
772
773 #. type: Plain text
774 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
775 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
776 msgid ""
777 "A file or directory that was opened read-only (B<O_RDONLY>) was closed."
778 msgstr ""
779
780 #. type: TP
781 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
782 #: opensuse-tumbleweed
783 #, no-wrap
784 msgid "B<FAN_MNT_ATTACH>"
785 msgstr ""
786
787 #. type: Plain text
788 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
789 #: opensuse-tumbleweed
790 msgid "A mount was attached to mount namespace."
791 msgstr ""
792
793 #. type: TP
794 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
795 #: opensuse-tumbleweed
796 #, no-wrap
797 msgid "B<FAN_MNT_DETACH>"
798 msgstr ""
799
800 #. type: Plain text
801 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
802 #: opensuse-tumbleweed
803 msgid "A mount was detached from mount namespace."
804 msgstr ""
805
806 #. type: TP
807 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
808 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
809 #, no-wrap
810 msgid "B<FAN_FS_ERROR>"
811 msgstr ""
812
813 #. type: Plain text
814 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
815 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
816 msgid "A filesystem error was detected."
817 msgstr ""
818
819 #. type: TP
820 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
821 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
822 #, no-wrap
823 msgid "B<FAN_Q_OVERFLOW>"
824 msgstr ""
825
826 #. type: Plain text
827 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
828 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
829 msgid ""
830 "The event queue exceeded the limit on number of events. This limit can be "
831 "overridden by specifying the B<FAN_UNLIMITED_QUEUE> flag when calling "
832 "B<fanotify_init>(2)."
833 msgstr ""
834
835 #. type: TP
836 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
837 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
838 #, no-wrap
839 msgid "B<FAN_ACCESS_PERM>"
840 msgstr ""
841
842 #. type: Plain text
843 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
844 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
845 msgid ""
846 "An application wants to read a file or directory, for example using "
847 "B<read>(2) or B<readdir>(2). The reader must write a response (as "
848 "described below) that determines whether the permission to access the "
849 "filesystem object shall be granted."
850 msgstr ""
851
852 #. type: TP
853 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
854 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
855 #, no-wrap
856 msgid "B<FAN_OPEN_PERM>"
857 msgstr ""
858
859 #. type: Plain text
860 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
861 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
862 msgid ""
863 "An application wants to open a file or directory. The reader must write a "
864 "response that determines whether the permission to open the filesystem "
865 "object shall be granted."
866 msgstr ""
867
868 #. type: TP
869 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
870 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
871 #, no-wrap
872 msgid "B<FAN_OPEN_EXEC_PERM>"
873 msgstr ""
874
875 #. type: Plain text
876 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
877 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
878 msgid ""
879 "An application wants to open a file for execution. The reader must write a "
880 "response that determines whether the permission to open the filesystem "
881 "object for execution shall be granted. See NOTES in B<fanotify_mark>(2) "
882 "for additional details."
883 msgstr ""
884
885 #. type: Plain text
886 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
887 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
888 msgid "To check for any close event, the following bit mask may be used:"
889 msgstr ""
890
891 #. type: TP
892 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
893 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
894 #, no-wrap
895 msgid "B<FAN_CLOSE>"
896 msgstr ""
897
898 #. type: Plain text
899 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
900 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
901 msgid "A file was closed. This is a synonym for:"
902 msgstr ""
903
904 #. type: Plain text
905 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
906 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
907 #, no-wrap
908 msgid "FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE\n"
909 msgstr ""
910
911 #. type: Plain text
912 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
913 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
914 msgid "To check for any move event, the following bit mask may be used:"
915 msgstr ""
916
917 #. type: TP
918 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
919 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
920 #, no-wrap
921 msgid "B<FAN_MOVE>"
922 msgstr ""
923
924 #. type: Plain text
925 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
926 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
927 msgid "A file or directory was moved. This is a synonym for:"
928 msgstr ""
929
930 #. type: Plain text
931 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
932 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
933 #, no-wrap
934 msgid "FAN_MOVED_FROM | FAN_MOVED_TO\n"
935 msgstr ""
936
937 #. type: Plain text
938 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
939 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
940 msgid ""
941 "The following bits may appear in I<mask> only in conjunction with other "
942 "event type bits:"
943 msgstr ""
944
945 #. type: TP
946 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
947 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
948 #, no-wrap
949 msgid "B<FAN_ONDIR>"
950 msgstr ""
951
952 #. type: Plain text
953 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
954 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
955 msgid ""
956 "The events described in the I<mask> have occurred on a directory object. "
957 "Reporting events on directories requires setting this flag in the mark "
958 "mask. See B<fanotify_mark>(2) for additional details. The B<FAN_ONDIR> "
959 "flag is reported in an event mask only if the fanotify group identifies "
960 "filesystem objects by file handles."
961 msgstr ""
962
963 #. type: Plain text
964 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
965 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
966 msgid ""
967 "Information records that are supplied alongside the generic "
968 "I<fanotify_event_metadata> structure will always contain a nested structure "
969 "of type I<fanotify_event_info_header>. The fields of the "
970 "I<fanotify_event_info_header> are as follows:"
971 msgstr ""
972
973 #. type: TP
974 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
975 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
976 #, no-wrap
977 msgid "I<info_type>"
978 msgstr ""
979
980 #. type: Plain text
981 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
982 #: opensuse-tumbleweed
983 msgid ""
984 "A unique integer value representing the type of information record object "
985 "received for an event. The value of this field can be set to one of the "
986 "following."
987 msgstr ""
988
989 #. type: TP
990 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
991 #: opensuse-tumbleweed
992 #, no-wrap
993 msgid "B<FAN_EVENT_INFO_TYPE_FID>"
994 msgstr ""
995
996 #. type: TQ
997 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
998 #: opensuse-tumbleweed
999 #, no-wrap
1000 msgid "B<FAN_EVENT_INFO_TYPE_DFID>"
1001 msgstr ""
1002
1003 #. type: TQ
1004 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1005 #: opensuse-tumbleweed
1006 #, no-wrap
1007 msgid "B<FAN_EVENT_INFO_TYPE_DFID_NAME>"
1008 msgstr ""
1009
1010 #. type: TQ
1011 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1012 #: opensuse-tumbleweed
1013 #, no-wrap
1014 msgid "B<FAN_EVENT_INFO_TYPE_PIDFD>"
1015 msgstr ""
1016
1017 #. type: TQ
1018 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1019 #: opensuse-tumbleweed
1020 #, no-wrap
1021 msgid "B<FAN_EVENT_INFO_TYPE_ERROR>"
1022 msgstr ""
1023
1024 #. type: TQ
1025 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1026 #: opensuse-tumbleweed
1027 #, no-wrap
1028 msgid "B<FAN_EVENT_INFO_TYPE_RANGE>"
1029 msgstr ""
1030
1031 #. type: TQ
1032 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1033 #: opensuse-tumbleweed
1034 #, no-wrap
1035 msgid "B<FAN_EVENT_INFO_TYPE_MNT>"
1036 msgstr ""
1037
1038 #. type: Plain text
1039 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1040 #: opensuse-tumbleweed
1041 msgid ""
1042 "The value set for this field is dependent on the flags that have been "
1043 "supplied to B<fanotify_init>(2). Refer to the field details of each "
1044 "information record object type below to understand the different cases in "
1045 "which the I<info_type> values can be set."
1046 msgstr ""
1047
1048 #. type: TP
1049 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1050 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1051 #, no-wrap
1052 msgid "I<pad>"
1053 msgstr ""
1054
1055 #. type: Plain text
1056 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1057 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1058 msgid ""
1059 "This field is currently not used by any information record object type and "
1060 "therefore is set to zero."
1061 msgstr ""
1062
1063 #. type: TP
1064 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1065 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1066 #, no-wrap
1067 msgid "I<len>"
1068 msgstr ""
1069
1070 #. type: Plain text
1071 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1072 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1073 msgid ""
1074 "The value of I<len> is set to the size of the information record object, "
1075 "including the I<fanotify_event_info_header>. The total size of all "
1076 "additional information records is not expected to be larger than "
1077 "(I<event_len> - I<metadata_len>)."
1078 msgstr ""
1079
1080 #. type: Plain text
1081 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1082 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1083 msgid "The fields of the I<fanotify_event_info_fid> structure are as follows:"
1084 msgstr ""
1085
1086 #. type: TP
1087 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1088 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1089 #, no-wrap
1090 msgid "I<hdr>"
1091 msgstr ""
1092
1093 #. type: Plain text
1094 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1095 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1096 msgid ""
1097 "This is a structure of type I<fanotify_event_info_header>. For example, "
1098 "when an fanotify file descriptor is created using B<FAN_REPORT_FID>, a "
1099 "single information record is expected to be attached to the event with "
1100 "I<info_type> field value of B<FAN_EVENT_INFO_TYPE_FID>. When an fanotify "
1101 "file descriptor is created using the combination of B<FAN_REPORT_FID> and "
1102 "B<FAN_REPORT_DIR_FID>, there may be two information records attached to the "
1103 "event: one with I<info_type> field value of B<FAN_EVENT_INFO_TYPE_DFID>, "
1104 "identifying a parent directory object, and one with I<info_type> field value "
1105 "of B<FAN_EVENT_INFO_TYPE_FID>, identifying a child object. Note that for "
1106 "the directory entry modification events B<FAN_CREATE>, B<FAN_DELETE>, "
1107 "B<FAN_MOVE>, and B<FAN_RENAME>, an information record identifying the "
1108 "created/deleted/moved child object is reported only if an fanotify group was "
1109 "initialized with the flag B<FAN_REPORT_TARGET_FID>."
1110 msgstr ""
1111
1112 #. type: TP
1113 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1114 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1115 #, no-wrap
1116 msgid "I<fsid>"
1117 msgstr ""
1118
1119 #. type: Plain text
1120 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
1121 #: opensuse-leap-16-1 opensuse-tumbleweed
1122 msgid ""
1123 "This is a unique identifier of the filesystem containing the object "
1124 "associated with the event. It is a structure of type I<__kernel_fsid_t> and "
1125 "contains the same value as I<f_fsid> when calling B<statfs>(2). Note that "
1126 "some filesystems (e.g., B<fuse>(4)) report zero I<fsid>. In these cases, "
1127 "it is not possible to use I<fsid> to associate the event with a specific "
1128 "filesystem instance, so monitoring different filesystem instances that "
1129 "report zero I<fsid> with the same fanotify group is not supported."
1130 msgstr ""
1131
1132 #. type: TP
1133 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1134 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1135 #, no-wrap
1136 msgid "I<handle>"
1137 msgstr ""
1138
1139 #. type: Plain text
1140 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
1141 #: opensuse-leap-16-1 opensuse-tumbleweed
1142 msgid ""
1143 "This field contains a variable-size structure of type I<struct "
1144 "file_handle>. It is an opaque handle that corresponds to a specified object "
1145 "on a filesystem as returned by B<name_to_handle_at>(2). It can be used to "
1146 "uniquely identify a file on a filesystem and can be passed as an argument to "
1147 "B<open_by_handle_at>(2). If the value of I<info_type> field is "
1148 "B<FAN_EVENT_INFO_TYPE_DFID_NAME>, the file handle is followed by a null "
1149 "terminated string that identifies the created/deleted/moved directory entry "
1150 "name. For other events such as B<FAN_OPEN>, B<FAN_ATTRIB>, "
1151 "B<FAN_DELETE_SELF>, and B<FAN_MOVE_SELF>, if the value of I<info_type> field "
1152 "is B<FAN_EVENT_INFO_TYPE_FID>, the I<handle> identifies the object "
1153 "correlated to the event. If the value of I<info_type> field is "
1154 "B<FAN_EVENT_INFO_TYPE_DFID>, the I<handle> identifies the directory object "
1155 "correlated to the event or the parent directory of a non-directory object "
1156 "correlated to the event. If the value of I<info_type> field is "
1157 "B<FAN_EVENT_INFO_TYPE_DFID_NAME>, the I<handle> identifies the same "
1158 "directory object that would be reported with B<FAN_EVENT_INFO_TYPE_DFID> and "
1159 "the file handle is followed by a null terminated string that identifies the "
1160 "name of a directory entry in that directory, or '.' to identify the "
1161 "directory object itself."
1162 msgstr ""
1163
1164 #. type: Plain text
1165 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1166 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1167 msgid ""
1168 "The fields of the I<fanotify_event_info_pidfd> structure are as follows:"
1169 msgstr ""
1170
1171 #. type: Plain text
1172 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1173 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1174 msgid ""
1175 "This is a structure of type I<fanotify_event_info_header>. When an fanotify "
1176 "group is initialized using B<FAN_REPORT_PIDFD>, the I<info_type> field value "
1177 "of the I<fanotify_event_info_header> is set to B<FAN_EVENT_INFO_TYPE_PIDFD>."
1178 msgstr ""
1179
1180 #. type: TP
1181 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1182 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1183 #, no-wrap
1184 msgid "I<pidfd>"
1185 msgstr ""
1186
1187 #. type: Plain text
1188 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1189 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1190 msgid ""
1191 "This is a process file descriptor that refers to the process responsible for "
1192 "generating the event. The returned process file descriptor is no different "
1193 "from one which could be obtained manually if B<pidfd_open>(2) were to be "
1194 "called on I<fanotify_event_metadata.pid>. In the instance that an error is "
1195 "encountered during pidfd creation, one of two possible error types "
1196 "represented by a negative integer value may be returned in this I<pidfd> "
1197 "field. In cases where the process responsible for generating the event has "
1198 "terminated prior to the event listener being able to read events from the "
1199 "notification queue, B<FAN_NOPIDFD> is returned. The pidfd creation for an "
1200 "event is only performed at the time the events are read from the "
1201 "notification queue. All other possible pidfd creation failures are "
1202 "represented by B<FAN_EPIDFD>. Once the event listener has dealt with an "
1203 "event and the pidfd is no longer required, the pidfd should be closed via "
1204 "B<close>(2)."
1205 msgstr ""
1206
1207 #. type: Plain text
1208 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1209 #: opensuse-tumbleweed
1210 msgid ""
1211 "When an fanotify group is initialized using B<FAN_REPORT_FD_ERROR>, this "
1212 "field will contain a negative error value in case a pidfd creation failure "
1213 "and in case of a terminated process, the value will be B<-ESRCH>."
1214 msgstr ""
1215
1216 #. type: Plain text
1217 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1218 #: opensuse-tumbleweed
1219 msgid "The fields of the I<fanotify_event_info_mnt> structure are as follows:"
1220 msgstr ""
1221
1222 #. type: TP
1223 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1224 #: opensuse-tumbleweed
1225 #, no-wrap
1226 msgid "I<.hdr>"
1227 msgstr ""
1228
1229 #. type: Plain text
1230 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1231 #: opensuse-tumbleweed
1232 msgid ""
1233 "This is a structure of type I<fanotify_event_info_header>. The "
1234 "I<.info_type> field is set to B<FAN_EVENT_INFO_TYPE_MNT>."
1235 msgstr ""
1236
1237 #. type: TP
1238 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1239 #: opensuse-tumbleweed
1240 #, no-wrap
1241 msgid "I<.mnt_id>"
1242 msgstr ""
1243
1244 #. type: Plain text
1245 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1246 #: opensuse-tumbleweed
1247 msgid ""
1248 "Identifies the mount associated with the event. It is a 64-bit unique mount "
1249 "id as the one returned by B<statx>(2) with the B<STATX_MNT_ID_UNIQUE> flag."
1250 msgstr ""
1251
1252 #. type: Plain text
1253 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1254 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1255 msgid ""
1256 "The fields of the I<fanotify_event_info_error> structure are as follows:"
1257 msgstr ""
1258
1259 #. type: Plain text
1260 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1261 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1262 msgid ""
1263 "This is a structure of type I<fanotify_event_info_header>. The I<info_type> "
1264 "field is set to B<FAN_EVENT_INFO_TYPE_ERROR>."
1265 msgstr ""
1266
1267 #. type: TP
1268 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1269 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1270 #, no-wrap
1271 msgid "I<error>"
1272 msgstr ""
1273
1274 #. type: Plain text
1275 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1276 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1277 msgid "Identifies the type of error that occurred."
1278 msgstr ""
1279
1280 #. type: TP
1281 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1282 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1283 #, no-wrap
1284 msgid "I<error_count>"
1285 msgstr ""
1286
1287 #. type: Plain text
1288 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1289 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1290 msgid ""
1291 "This is a counter of the number of errors suppressed since the last error "
1292 "was read."
1293 msgstr ""
1294
1295 #. type: Plain text
1296 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1297 #: opensuse-tumbleweed
1298 msgid ""
1299 "The fields of the I<fanotify_event_info_range> structure are as follows:"
1300 msgstr ""
1301
1302 #. type: Plain text
1303 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1304 #: opensuse-tumbleweed
1305 msgid ""
1306 "This is a structure of type I<fanotify_event_info_header>. The I<info_type> "
1307 "field is set to B<FAN_EVENT_INFO_TYPE_RANGE>."
1308 msgstr ""
1309
1310 #. type: TP
1311 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1312 #: opensuse-tumbleweed
1313 #, no-wrap
1314 msgid "I<count>"
1315 msgstr ""
1316
1317 #. type: Plain text
1318 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1319 #: opensuse-tumbleweed
1320 msgid "The number of bytes being read or written to the file."
1321 msgstr ""
1322
1323 #. type: TP
1324 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1325 #: opensuse-tumbleweed
1326 #, no-wrap
1327 msgid "I<offset>"
1328 msgstr ""
1329
1330 #. type: Plain text
1331 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1332 #: opensuse-tumbleweed
1333 msgid "The offset from which bytes are read or written to the file."
1334 msgstr ""
1335
1336 #. type: Plain text
1337 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1338 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1339 msgid ""
1340 "The following macros are provided to iterate over a buffer containing "
1341 "fanotify event metadata returned by a B<read>(2) from an fanotify file "
1342 "descriptor:"
1343 msgstr ""
1344
1345 #. type: TP
1346 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
1347 #: opensuse-leap-16-1 opensuse-tumbleweed
1348 #, no-wrap
1349 msgid "B<FAN_EVENT_OK(meta, size)>"
1350 msgstr ""
1351
1352 #. type: Plain text
1353 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
1354 #: opensuse-leap-16-1 opensuse-tumbleweed
1355 msgid ""
1356 "This macro checks the remaining size I<size> of the buffer I<meta> against "
1357 "the size of the metadata structure and the I<event_len> field of the first "
1358 "metadata structure in the buffer."
1359 msgstr ""
1360
1361 #. type: TP
1362 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
1363 #: opensuse-leap-16-1 opensuse-tumbleweed
1364 #, no-wrap
1365 msgid "B<FAN_EVENT_NEXT(meta, size)>"
1366 msgstr ""
1367
1368 #. type: Plain text
1369 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
1370 #: opensuse-leap-16-1 opensuse-tumbleweed
1371 msgid ""
1372 "This macro uses the size indicated in the I<event_len> field of the metadata "
1373 "structure pointed to by I<meta> to calculate the address of the next "
1374 "metadata structure that follows I<meta>. I<size> is the number of bytes of "
1375 "metadata that currently remain in the buffer. The macro returns a pointer "
1376 "to the next metadata structure that follows I<meta>, and reduces I<size> by "
1377 "the number of bytes in the metadata structure that has been skipped over "
1378 "(i.e., it subtracts I<meta-E<gt>event_len> from I<size>)."
1379 msgstr ""
1380
1381 #. type: Plain text
1382 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1383 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1384 msgid "In addition, there is:"
1385 msgstr ""
1386
1387 #. type: TP
1388 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1389 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1390 #, no-wrap
1391 msgid "B<FAN_EVENT_METADATA_LEN>"
1392 msgstr ""
1393
1394 #. type: Plain text
1395 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1396 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1397 msgid ""
1398 "This macro returns the size (in bytes) of the structure "
1399 "I<fanotify_event_metadata>. This is the minimum size (and currently the "
1400 "only size) of any event metadata."
1401 msgstr ""
1402
1403 #. type: SS
1404 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1405 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1406 #, no-wrap
1407 msgid "Monitoring an fanotify file descriptor for events"
1408 msgstr ""
1409
1410 #. type: Plain text
1411 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1412 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1413 msgid ""
1414 "When an fanotify event occurs, the fanotify file descriptor indicates as "
1415 "readable when passed to B<epoll>(7), B<poll>(2), or B<select>(2)."
1416 msgstr ""
1417
1418 #. type: SS
1419 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1420 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1421 #, no-wrap
1422 msgid "Dealing with permission events"
1423 msgstr ""
1424
1425 #. type: Plain text
1426 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1427 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1428 msgid ""
1429 "For permission events, the application must B<write>(2) a structure of the "
1430 "following form to the fanotify file descriptor:"
1431 msgstr ""
1432
1433 #. type: Plain text
1434 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1435 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1436 #, no-wrap
1437 msgid ""
1438 "struct fanotify_response {\n"
1439 " __s32 fd;\n"
1440 " __u32 response;\n"
1441 "};\n"
1442 msgstr ""
1443
1444 #. type: Plain text
1445 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1446 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1447 msgid "The fields of this structure are as follows:"
1448 msgstr ""
1449
1450 #. type: Plain text
1451 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1452 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1453 msgid ""
1454 "This is the file descriptor from the structure I<fanotify_event_metadata>."
1455 msgstr ""
1456
1457 #. type: TP
1458 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1459 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1460 #, no-wrap
1461 msgid "I<response>"
1462 msgstr ""
1463
1464 #. type: Plain text
1465 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1466 #: opensuse-tumbleweed
1467 msgid ""
1468 "This field indicates whether or not the permission is to be granted. Its "
1469 "value must contain either the flag B<FAN_ALLOW> to allow the file operation "
1470 "or B<FAN_DENY> to deny the file operation."
1471 msgstr ""
1472
1473 #. commit b4b2ff4f61ded819bfa22e50fdec7693f51cbbee
1474 #. type: Plain text
1475 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1476 #: opensuse-tumbleweed
1477 msgid ""
1478 "If access is denied, the requesting application call will receive an "
1479 "B<EPERM> error. Since Linux 6.13, if a notification group is initialized "
1480 "with class B<FAN_CLASS_PRE_CONTENT>, the file operation can be denied with "
1481 "errors other than B<EPERM>. For example, for the requesting application to "
1482 "get the B<EIO> error, the event listener can write the response "
1483 "B<FAN_DENY_ERRNO>(B<EIO>). At the time of writing, only the following error "
1484 "values could be returned to the application with "
1485 "B<FAN_DENY_ERRNO>(\\f[I]e\\fR) macro: B<EPERM>, B<EIO>, B<EBUSY>, "
1486 "B<ETXTBSY>, B<EAGAIN>, B<ENOSPC>, B<EDQUOT>."
1487 msgstr ""
1488
1489 #. type: Plain text
1490 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1491 #: opensuse-tumbleweed
1492 msgid ""
1493 "Additionally, if the notification group has been created with the "
1494 "B<FAN_ENABLE_AUDIT> flag, then the B<FAN_AUDIT> flag can be set in the "
1495 "I<response> field. In that case, the audit subsystem will log information "
1496 "about the access decision to the audit logs."
1497 msgstr ""
1498
1499 #. commit 70529a199574c15a40f46b14256633b02ba10ca2
1500 #. type: Plain text
1501 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1502 #: opensuse-tumbleweed
1503 msgid ""
1504 "Since Linux 6.3, the B<FAN_INFO> flag can be set in the I<.response> field. "
1505 "It indicates that an extra variable-length response record follows the "
1506 "I<fanotify_response> structure. Extra response records start with a common "
1507 "header:"
1508 msgstr ""
1509
1510 #. type: Plain text
1511 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1512 #: opensuse-tumbleweed
1513 #, no-wrap
1514 msgid ""
1515 "struct fanotify_response_info_header {\n"
1516 " __u8 type;\n"
1517 " __u8 pad;\n"
1518 " __u16 len;\n"
1519 "};\n"
1520 msgstr ""
1521
1522 #. type: Plain text
1523 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1524 #: opensuse-tumbleweed
1525 msgid ""
1526 "The value of I<.type> determines the format of the extra response record."
1527 msgstr ""
1528
1529 #. type: TP
1530 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1531 #: opensuse-tumbleweed
1532 #, no-wrap
1533 msgid "B<FAN_RESPONSE_INFO_AUDIT_RULE>"
1534 msgstr ""
1535
1536 #. type: Plain text
1537 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1538 #: opensuse-tumbleweed
1539 msgid ""
1540 "The following response record is expected with extra details for the audit "
1541 "log:"
1542 msgstr ""
1543
1544 #. type: Plain text
1545 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1546 #: opensuse-tumbleweed
1547 #, no-wrap
1548 msgid ""
1549 "struct fanotify_response_info_audit_rule {\n"
1550 " struct fanotify_response_info_header hdr;\n"
1551 " __u32 rule_number;\n"
1552 " __u32 subj_trust;\n"
1553 " __u32 obj_trust;\n"
1554 "};\n"
1555 msgstr ""
1556
1557 #. type: SS
1558 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1559 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1560 #, no-wrap
1561 msgid "Monitoring filesystems for errors"
1562 msgstr ""
1563
1564 #. type: Plain text
1565 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1566 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1567 msgid ""
1568 "A single B<FAN_FS_ERROR> event is stored per filesystem at once. Extra "
1569 "error messages are suppressed and accounted for in the I<error_count> field "
1570 "of the existing B<FAN_FS_ERROR> event record, but details about the errors "
1571 "are lost."
1572 msgstr ""
1573
1574 #. type: Plain text
1575 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1576 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1577 msgid ""
1578 "Errors reported by B<FAN_FS_ERROR> are generic I<errno> values, but not all "
1579 "kinds of error types are reported by all filesystems."
1580 msgstr ""
1581
1582 #. type: Plain text
1583 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1584 #: opensuse-tumbleweed
1585 msgid ""
1586 "Errors not directly related to a file (i.e., super block corruption) are "
1587 "reported with an invalid I<handle>. For these errors, the I<handle> will "
1588 "have the field I<handle_type> set to B<FILEID_INVALID>, and the handle "
1589 "buffer size set to B<0>."
1590 msgstr ""
1591
1592 #. type: SS
1593 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1594 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1595 #, no-wrap
1596 msgid "Closing the fanotify file descriptor"
1597 msgstr ""
1598
1599 #. type: Plain text
1600 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1601 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1602 msgid ""
1603 "When all file descriptors referring to the fanotify notification group are "
1604 "closed, the fanotify group is released and its resources are freed for reuse "
1605 "by the kernel. Upon B<close>(2), outstanding permission events will be set "
1606 "to allowed."
1607 msgstr ""
1608
1609 #. type: SS
1610 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1611 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1612 #, no-wrap
1613 msgid "/proc interfaces"
1614 msgstr ""
1615
1616 #. type: Plain text
1617 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1618 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1619 msgid ""
1620 "The file I</proc/>pidI</fdinfo/>fd contains information about fanotify marks "
1621 "for file descriptor I<fd> of process I<pid>. See B<proc>(5) for details."
1622 msgstr ""
1623
1624 #. commit 5b8fea65d197f408bb00b251c70d842826d6b70b
1625 #. type: Plain text
1626 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
1627 #: opensuse-leap-16-1 opensuse-tumbleweed
1628 msgid ""
1629 "Since Linux 5.13 (and 5.10.220), the following interfaces can be used to "
1630 "control the amount of kernel resources consumed by fanotify:"
1631 msgstr ""
1632
1633 #. type: TP
1634 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1635 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1636 #, no-wrap
1637 msgid "I</proc/sys/fs/fanotify/max_queued_events>"
1638 msgstr ""
1639
1640 #. commit 5b8fea65d197f408bb00b251c70d842826d6b70b
1641 #. type: Plain text
1642 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1643 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1644 msgid ""
1645 "The value in this file is used when an application calls "
1646 "B<fanotify_init>(2) to set an upper limit on the number of events that can "
1647 "be queued to the corresponding fanotify group. Events in excess of this "
1648 "limit are dropped, but an B<FAN_Q_OVERFLOW> event is always generated. "
1649 "Prior to Linux kernel 5.13, the hardcoded limit was 16384 events."
1650 msgstr ""
1651
1652 #. type: TP
1653 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1654 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1655 #, no-wrap
1656 msgid "I</proc/sys/fs/fanotify/max_user_group>"
1657 msgstr ""
1658
1659 #. commit 5b8fea65d197f408bb00b251c70d842826d6b70b
1660 #. type: Plain text
1661 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1662 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1663 msgid ""
1664 "This specifies an upper limit on the number of fanotify groups that can be "
1665 "created per real user ID. Prior to Linux kernel 5.13, the hardcoded limit "
1666 "was 128 groups per user."
1667 msgstr ""
1668
1669 #. type: TP
1670 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1671 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1672 #, no-wrap
1673 msgid "I</proc/sys/fs/fanotify/max_user_marks>"
1674 msgstr ""
1675
1676 #. commit 5b8fea65d197f408bb00b251c70d842826d6b70b
1677 #. type: Plain text
1678 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1679 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1680 msgid ""
1681 "This specifies an upper limit on the number of fanotify marks that can be "
1682 "created per real user ID. Prior to Linux kernel 5.13, the hardcoded limit "
1683 "was 8192 marks per group (not per user)."
1684 msgstr ""
1685
1686 #. type: SH
1687 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1688 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1689 #, no-wrap
1690 msgid "ERRORS"
1691 msgstr ""
1692
1693 #. type: Plain text
1694 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1695 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1696 msgid ""
1697 "In addition to the usual errors for B<read>(2), the following errors can "
1698 "occur when reading from the fanotify file descriptor:"
1699 msgstr ""
1700
1701 #. type: TP
1702 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1703 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1704 #, no-wrap
1705 msgid "B<EINVAL>"
1706 msgstr ""
1707
1708 #. type: Plain text
1709 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1710 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1711 msgid "The buffer is too small to hold the event."
1712 msgstr ""
1713
1714 #. type: TP
1715 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1716 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1717 #, no-wrap
1718 msgid "B<EMFILE>"
1719 msgstr ""
1720
1721 #. type: Plain text
1722 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1723 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1724 msgid ""
1725 "The per-process limit on the number of open files has been reached. See the "
1726 "description of B<RLIMIT_NOFILE> in B<getrlimit>(2)."
1727 msgstr ""
1728
1729 #. type: TP
1730 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1731 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1732 #, no-wrap
1733 msgid "B<ENFILE>"
1734 msgstr ""
1735
1736 #. type: Plain text
1737 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1738 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1739 msgid ""
1740 "The system-wide limit on the total number of open files has been reached. "
1741 "See I</proc/sys/fs/file-max> in B<proc>(5)."
1742 msgstr ""
1743
1744 #. type: TP
1745 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1746 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1747 #, no-wrap
1748 msgid "B<ETXTBSY>"
1749 msgstr ""
1750
1751 #. type: Plain text
1752 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1753 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1754 msgid ""
1755 "This error is returned by B<read>(2) if B<O_RDWR> or B<O_WRONLY> was "
1756 "specified in the I<event_f_flags> argument when calling B<fanotify_init>(2) "
1757 "and an event occurred for a monitored file that is currently being executed."
1758 msgstr ""
1759
1760 #. type: Plain text
1761 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1762 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1763 msgid ""
1764 "In addition to the usual errors for B<write>(2), the following errors can "
1765 "occur when writing to the fanotify file descriptor:"
1766 msgstr ""
1767
1768 #. type: Plain text
1769 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1770 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1771 msgid ""
1772 "Fanotify access permissions are not enabled in the kernel configuration or "
1773 "the value of I<response> in the response structure is not valid."
1774 msgstr ""
1775
1776 #. type: TP
1777 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1778 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1779 #, no-wrap
1780 msgid "B<ENOENT>"
1781 msgstr ""
1782
1783 #. type: Plain text
1784 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1785 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1786 msgid ""
1787 "The file descriptor I<fd> in the response structure is not valid. This may "
1788 "occur when a response for the permission event has already been written."
1789 msgstr ""
1790
1791 #. type: SH
1792 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1793 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1794 #, no-wrap
1795 msgid "STANDARDS"
1796 msgstr ""
1797
1798 #. type: Plain text
1799 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1800 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1801 msgid "Linux."
1802 msgstr ""
1803
1804 #. type: SH
1805 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1806 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1807 #, no-wrap
1808 msgid "HISTORY"
1809 msgstr ""
1810
1811 #. type: Plain text
1812 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1813 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1814 msgid ""
1815 "The fanotify API was introduced in Linux 2.6.36 and enabled in Linux "
1816 "2.6.37. fdinfo support was added in Linux 3.8."
1817 msgstr ""
1818
1819 #. type: SH
1820 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1821 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1822 #, no-wrap
1823 msgid "NOTES"
1824 msgstr ""
1825
1826 #. type: Plain text
1827 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1828 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1829 msgid ""
1830 "The fanotify API is available only if the kernel was built with the "
1831 "B<CONFIG_FANOTIFY> configuration option enabled. In addition, fanotify "
1832 "permission handling is available only if the "
1833 "B<CONFIG_FANOTIFY_ACCESS_PERMISSIONS> configuration option is enabled."
1834 msgstr ""
1835
1836 #. type: SS
1837 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1838 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1839 #, no-wrap
1840 msgid "Limitations and caveats"
1841 msgstr ""
1842
1843 #. type: Plain text
1844 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1845 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1846 msgid ""
1847 "Fanotify reports only events that a user-space program triggers through the "
1848 "filesystem API. As a result, it does not catch remote events that occur on "
1849 "network filesystems."
1850 msgstr ""
1851
1852 #. type: Plain text
1853 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1854 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1855 msgid ""
1856 "The fanotify API does not report file accesses and modifications that may "
1857 "occur because of B<mmap>(2), B<msync>(2), and B<munmap>(2)."
1858 msgstr ""
1859
1860 #. type: Plain text
1861 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1862 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1863 msgid ""
1864 "Events for directories are created only if the directory itself is opened, "
1865 "read, and closed. Adding, removing, or changing children of a marked "
1866 "directory does not create events for the monitored directory itself."
1867 msgstr ""
1868
1869 #. type: Plain text
1870 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1871 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1872 msgid ""
1873 "Fanotify monitoring of directories is not recursive: to monitor "
1874 "subdirectories under a directory, additional marks must be created. The "
1875 "B<FAN_CREATE> event can be used for detecting when a subdirectory has been "
1876 "created under a marked directory. An additional mark must then be set on "
1877 "the newly created subdirectory. This approach is racy, because it can lose "
1878 "events that occurred inside the newly created subdirectory, before a mark is "
1879 "added on that subdirectory. Monitoring mounts offers the capability to "
1880 "monitor a whole directory tree in a race-free manner. Monitoring "
1881 "filesystems offers the capability to monitor changes made from any mount of "
1882 "a filesystem instance in a race-free manner."
1883 msgstr ""
1884
1885 #. type: Plain text
1886 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1887 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1888 msgid "The event queue can overflow. In this case, events are lost."
1889 msgstr ""
1890
1891 #. type: SH
1892 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1893 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1894 #, no-wrap
1895 msgid "BUGS"
1896 msgstr ""
1897
1898 #. commit 820c12d5d6c0890bc93dd63893924a13041fdc35
1899 #. type: Plain text
1900 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1901 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1902 msgid ""
1903 "Before Linux 3.19, B<fallocate>(2) did not generate fanotify events. Since "
1904 "Linux 3.19, calls to B<fallocate>(2) generate B<FAN_MODIFY> events."
1905 msgstr ""
1906
1907 #. type: Plain text
1908 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1909 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1910 msgid "As of Linux 3.17, the following bugs exist:"
1911 msgstr ""
1912
1913 #. type: IP
1914 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1915 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1916 #, no-wrap
1917 msgid "\\[bu]"
1918 msgstr ""
1919
1920 #. type: Plain text
1921 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1922 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1923 msgid ""
1924 "On Linux, a filesystem object may be accessible through multiple paths, for "
1925 "example, a part of a filesystem may be remounted using the I<--bind> option "
1926 "of B<mount>(8). A listener that marked a mount will be notified only of "
1927 "events that were triggered for a filesystem object using the same mount. "
1928 "Any other event will pass unnoticed."
1929 msgstr ""
1930
1931 #. FIXME . A patch was proposed.
1932 #. type: Plain text
1933 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1934 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1935 msgid ""
1936 "When an event is generated, no check is made to see whether the user ID of "
1937 "the receiving process has authorization to read or write the file before "
1938 "passing a file descriptor for that file. This poses a security risk, when "
1939 "the B<CAP_SYS_ADMIN> capability is set for programs executed by unprivileged "
1940 "users."
1941 msgstr ""
1942
1943 #. type: Plain text
1944 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
1945 #: opensuse-leap-16-1 opensuse-tumbleweed
1946 msgid ""
1947 "If a call to B<read>(2) processes multiple events from the fanotify queue "
1948 "and an error occurs, the return value will be the total size of the events "
1949 "successfully copied to the user-space buffer before the error occurred. The "
1950 "return value will not be -1, and I<errno> will not be set. Thus, the "
1951 "reading application has no way to detect the error."
1952 msgstr ""
1953
1954 #. type: SH
1955 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1956 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1957 #, no-wrap
1958 msgid "EXAMPLES"
1959 msgstr ""
1960
1961 #. type: Plain text
1962 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1963 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1964 msgid ""
1965 "The two example programs below demonstrate the usage of the fanotify API."
1966 msgstr ""
1967
1968 #. type: SS
1969 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1970 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1971 #, no-wrap
1972 msgid "Example program: fanotify_example.c"
1973 msgstr ""
1974
1975 #. type: Plain text
1976 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1977 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1978 msgid ""
1979 "The first program is an example of fanotify being used with its event object "
1980 "information passed in the form of a file descriptor. The program marks the "
1981 "mount passed as a command-line argument and waits for events of type "
1982 "B<FAN_OPEN_PERM> and B<FAN_CLOSE_WRITE>. When a permission event occurs, a "
1983 "B<FAN_ALLOW> response is given."
1984 msgstr ""
1985
1986 #. type: Plain text
1987 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1988 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1989 msgid ""
1990 "The following shell session shows an example of running this program. This "
1991 "session involved editing the file I</home/user/temp/notes>. Before the file "
1992 "was opened, a B<FAN_OPEN_PERM> event occurred. After the file was closed, a "
1993 "B<FAN_CLOSE_WRITE> event occurred. Execution of the program ends when the "
1994 "user presses the ENTER key."
1995 msgstr ""
1996
1997 #. type: Plain text
1998 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1999 #: opensuse-tumbleweed
2000 #, no-wrap
2001 msgid ""
2002 "#B< ./fanotify_example /home>;\n"
2003 "Press enter key to terminate.\n"
2004 "Listening for events.\n"
2005 "FAN_OPEN_PERM: File /home/user/temp/notes\n"
2006 "FAN_CLOSE_WRITE: File /home/user/temp/notes\n"
2007 "\\&\n"
2008 "Listening for events stopped.\n"
2009 msgstr ""
2010
2011 #. type: SS
2012 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2013 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2014 #, no-wrap
2015 msgid "Program source: fanotify_example.c"
2016 msgstr ""
2017
2018 #. type: Plain text
2019 #: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed
2020 #, no-wrap
2021 msgid ""
2022 "#define _GNU_SOURCE /* Needed to get O_LARGEFILE definition */\n"
2023 "#include E<lt>errno.hE<gt>\n"
2024 "#include E<lt>fcntl.hE<gt>\n"
2025 "#include E<lt>limits.hE<gt>\n"
2026 "#include E<lt>poll.hE<gt>\n"
2027 "#include E<lt>stdio.hE<gt>\n"
2028 "#include E<lt>stdlib.hE<gt>\n"
2029 "#include E<lt>sys/fanotify.hE<gt>\n"
2030 "#include E<lt>unistd.hE<gt>\n"
2031 "\\&\n"
2032 "/* Read all available fanotify events from the file descriptor \\[aq]fd\\[aq]. */\n"
2033 "\\&\n"
2034 "static void\n"
2035 "handle_events(int fd)\n"
2036 "{\n"
2037 " const struct fanotify_event_metadata *metadata;\n"
2038 " struct fanotify_event_metadata buf[200];\n"
2039 " ssize_t size;\n"
2040 " char path[PATH_MAX];\n"
2041 " ssize_t path_len;\n"
2042 " char procfd_path[PATH_MAX];\n"
2043 " struct fanotify_response response;\n"
2044 "\\&\n"
2045 " /* Loop while events can be read from fanotify file descriptor. */\n"
2046 "\\&\n"
2047 " for (;;) {\n"
2048 "\\&\n"
2049 " /* Read some events. */\n"
2050 "\\&\n"
2051 " size = read(fd, buf, sizeof(buf));\n"
2052 " if (size == -1 && errno != EAGAIN) {\n"
2053 " perror(\"read\");\n"
2054 " exit(EXIT_FAILURE);\n"
2055 " }\n"
2056 "\\&\n"
2057 " /* Check if end of available data reached. */\n"
2058 "\\&\n"
2059 " if (size E<lt>= 0)\n"
2060 " break;\n"
2061 "\\&\n"
2062 " /* Point to the first event in the buffer. */\n"
2063 "\\&\n"
2064 " metadata = buf;\n"
2065 "\\&\n"
2066 " /* Loop over all events in the buffer. */\n"
2067 "\\&\n"
2068 " while (FAN_EVENT_OK(metadata, size)) {\n"
2069 "\\&\n"
2070 " /* Check that run-time and compile-time structures match. */\n"
2071 "\\&\n"
2072 " if (metadata-E<gt>vers != FANOTIFY_METADATA_VERSION) {\n"
2073 " fprintf(stderr,\n"
2074 " \"Mismatch of fanotify metadata version.\\[rs]n\");\n"
2075 " exit(EXIT_FAILURE);\n"
2076 " }\n"
2077 "\\&\n"
2078 " /* metadata-E<gt>fd contains either FAN_NOFD, indicating a\n"
2079 " queue overflow, or a file descriptor (a nonnegative\n"
2080 " integer). Here, we simply ignore queue overflow. */\n"
2081 "\\&\n"
2082 " if (metadata-E<gt>fd E<gt>= 0) {\n"
2083 "\\&\n"
2084 " /* Handle open permission event. */\n"
2085 "\\&\n"
2086 " if (metadata-E<gt>mask & FAN_OPEN_PERM) {\n"
2087 " printf(\"FAN_OPEN_PERM: \");\n"
2088 "\\&\n"
2089 " /* Allow file to be opened. */\n"
2090 "\\&\n"
2091 " response.fd = metadata-E<gt>fd;\n"
2092 " response.response = FAN_ALLOW;\n"
2093 " write(fd, &response, sizeof(response));\n"
2094 " }\n"
2095 "\\&\n"
2096 " /* Handle closing of writable file event. */\n"
2097 "\\&\n"
2098 " if (metadata-E<gt>mask & FAN_CLOSE_WRITE)\n"
2099 " printf(\"FAN_CLOSE_WRITE: \");\n"
2100 "\\&\n"
2101 " /* Retrieve and print pathname of the accessed file. */\n"
2102 "\\&\n"
2103 " snprintf(procfd_path, sizeof(procfd_path),\n"
2104 " \"/proc/self/fd/%d\", metadata-E<gt>fd);\n"
2105 " path_len = readlink(procfd_path, path,\n"
2106 " sizeof(path) - 1);\n"
2107 " if (path_len == -1) {\n"
2108 " perror(\"readlink\");\n"
2109 " exit(EXIT_FAILURE);\n"
2110 " }\n"
2111 "\\&\n"
2112 " path[path_len] = \\[aq]\\[rs]0\\[aq];\n"
2113 " printf(\"File %s\\[rs]n\", path);\n"
2114 "\\&\n"
2115 " /* Close the file descriptor of the event. */\n"
2116 "\\&\n"
2117 " close(metadata-E<gt>fd);\n"
2118 " }\n"
2119 "\\&\n"
2120 " /* Advance to next event. */\n"
2121 "\\&\n"
2122 " metadata = FAN_EVENT_NEXT(metadata, size);\n"
2123 " }\n"
2124 " }\n"
2125 "}\n"
2126 "\\&\n"
2127 "int\n"
2128 "main(int argc, char *argv[])\n"
2129 "{\n"
2130 " char buf;\n"
2131 " int fd, poll_num;\n"
2132 " nfds_t nfds;\n"
2133 " struct pollfd fds[2];\n"
2134 "\\&\n"
2135 " /* Check mount point is supplied. */\n"
2136 "\\&\n"
2137 " if (argc != 2) {\n"
2138 " fprintf(stderr, \"Usage: %s MOUNT\\[rs]n\", argv[0]);\n"
2139 " exit(EXIT_FAILURE);\n"
2140 " }\n"
2141 "\\&\n"
2142 " printf(\"Press enter key to terminate.\\[rs]n\");\n"
2143 "\\&\n"
2144 " /* Create the file descriptor for accessing the fanotify API. */\n"
2145 "\\&\n"
2146 " fd = fanotify_init(FAN_CLOEXEC | FAN_CLASS_CONTENT | FAN_NONBLOCK,\n"
2147 " O_RDONLY | O_LARGEFILE);\n"
2148 " if (fd == -1) {\n"
2149 " perror(\"fanotify_init\");\n"
2150 " exit(EXIT_FAILURE);\n"
2151 " }\n"
2152 "\\&\n"
2153 " /* Mark the mount for:\n"
2154 " - permission events before opening files\n"
2155 " - notification events after closing a write-enabled\n"
2156 " file descriptor. */\n"
2157 "\\&\n"
2158 " if (fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT,\n"
2159 " FAN_OPEN_PERM | FAN_CLOSE_WRITE, AT_FDCWD,\n"
2160 " argv[1]) == -1) {\n"
2161 " perror(\"fanotify_mark\");\n"
2162 " exit(EXIT_FAILURE);\n"
2163 " }\n"
2164 "\\&\n"
2165 " /* Prepare for polling. */\n"
2166 "\\&\n"
2167 " nfds = 2;\n"
2168 "\\&\n"
2169 " fds[0].fd = STDIN_FILENO; /* Console input */\n"
2170 " fds[0].events = POLLIN;\n"
2171 "\\&\n"
2172 " fds[1].fd = fd; /* Fanotify input */\n"
2173 " fds[1].events = POLLIN;\n"
2174 "\\&\n"
2175 " /* This is the loop to wait for incoming events. */\n"
2176 "\\&\n"
2177 " printf(\"Listening for events.\\[rs]n\");\n"
2178 "\\&\n"
2179 " for (;;) {\n"
2180 " poll_num = poll(fds, nfds, -1);\n"
2181 " if (poll_num == -1) {\n"
2182 " if (errno == EINTR) /* Interrupted by a signal */\n"
2183 " continue; /* Restart poll() */\n"
2184 "\\&\n"
2185 " perror(\"poll\"); /* Unexpected error */\n"
2186 " exit(EXIT_FAILURE);\n"
2187 " }\n"
2188 "\\&\n"
2189 " if (poll_num E<gt> 0) {\n"
2190 " if (fds[0].revents & POLLIN) {\n"
2191 "\\&\n"
2192 " /* Console input is available: empty stdin and quit. */\n"
2193 "\\&\n"
2194 " while (read(STDIN_FILENO, &buf, 1) E<gt> 0 && buf != \\[aq]\\[rs]n\\[aq])\n"
2195 " continue;\n"
2196 " break;\n"
2197 " }\n"
2198 "\\&\n"
2199 " if (fds[1].revents & POLLIN) {\n"
2200 "\\&\n"
2201 " /* Fanotify events are available. */\n"
2202 "\\&\n"
2203 " handle_events(fd);\n"
2204 " }\n"
2205 " }\n"
2206 " }\n"
2207 "\\&\n"
2208 " printf(\"Listening for events stopped.\\[rs]n\");\n"
2209 " exit(EXIT_SUCCESS);\n"
2210 "}\n"
2211 msgstr ""
2212
2213 #. type: SS
2214 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2215 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2216 #, no-wrap
2217 msgid "Example program: fanotify_fid.c"
2218 msgstr ""
2219
2220 #. type: Plain text
2221 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2222 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2223 msgid ""
2224 "The second program is an example of fanotify being used with a group that "
2225 "identifies objects by file handles. The program marks the filesystem object "
2226 "that is passed as a command-line argument and waits until an event of type "
2227 "B<FAN_CREATE> has occurred. The event mask indicates which type of "
2228 "filesystem object\\[em]either a file or a directory\\[em]was created. Once "
2229 "all events have been read from the buffer and processed accordingly, the "
2230 "program simply terminates."
2231 msgstr ""
2232
2233 #. type: Plain text
2234 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2235 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2236 msgid ""
2237 "The following shell sessions show two different invocations of this program, "
2238 "with different actions performed on a watched object."
2239 msgstr ""
2240
2241 #. type: Plain text
2242 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2243 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2244 msgid ""
2245 "The first session shows a mark being placed on I</home/user>. This is "
2246 "followed by the creation of a regular file, I</home/user/testfile.txt>. "
2247 "This results in a B<FAN_CREATE> event being generated and reported against "
2248 "the file's parent watched directory object and with the created file name. "
2249 "Program execution ends once all events captured within the buffer have been "
2250 "processed."
2251 msgstr ""
2252
2253 #. type: Plain text
2254 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
2255 #: opensuse-tumbleweed
2256 #, no-wrap
2257 msgid ""
2258 "#B< ./fanotify_fid /home/user>;\n"
2259 "Listening for events.\n"
2260 "FAN_CREATE (file created):\n"
2261 " Directory /home/user has been modified.\n"
2262 " Entry \\[aq]testfile.txt\\[aq] is not a subdirectory.\n"
2263 "All events processed successfully. Program exiting.\n"
2264 "\\&\n"
2265 "$B< touch /home/user/testfile.txt>; # In another terminal\n"
2266 msgstr ""
2267
2268 #. type: Plain text
2269 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2270 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2271 msgid ""
2272 "The second session shows a mark being placed on I</home/user>. This is "
2273 "followed by the creation of a directory, I</home/user/testdir>. This "
2274 "specific action results in a B<FAN_CREATE> event being generated and is "
2275 "reported with the B<FAN_ONDIR> flag set and with the created directory name."
2276 msgstr ""
2277
2278 #. type: Plain text
2279 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
2280 #: opensuse-tumbleweed
2281 #, no-wrap
2282 msgid ""
2283 "#B< ./fanotify_fid /home/user>;\n"
2284 "Listening for events.\n"
2285 "FAN_CREATE | FAN_ONDIR (subdirectory created):\n"
2286 " Directory /home/user has been modified.\n"
2287 " Entry \\[aq]testdir\\[aq] is a subdirectory.\n"
2288 "All events processed successfully. Program exiting.\n"
2289 "\\&\n"
2290 "$B< mkdir -p /home/user/testdir>; # In another terminal\n"
2291 msgstr ""
2292
2293 #. type: SS
2294 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2295 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2296 #, no-wrap
2297 msgid "Program source: fanotify_fid.c"
2298 msgstr ""
2299
2300 #. type: Plain text
2301 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
2302 #: opensuse-tumbleweed
2303 #, no-wrap
2304 msgid ""
2305 "#define _GNU_SOURCE\n"
2306 "#include E<lt>errno.hE<gt>\n"
2307 "#include E<lt>fcntl.hE<gt>\n"
2308 "#include E<lt>limits.hE<gt>\n"
2309 "#include E<lt>stdio.hE<gt>\n"
2310 "#include E<lt>stdlib.hE<gt>\n"
2311 "#include E<lt>sys/types.hE<gt>\n"
2312 "#include E<lt>sys/stat.hE<gt>\n"
2313 "#include E<lt>sys/fanotify.hE<gt>\n"
2314 "#include E<lt>unistd.hE<gt>\n"
2315 "\\&\n"
2316 "#define BUF_SIZE 256\n"
2317 "\\&\n"
2318 "int\n"
2319 "main(int argc, char *argv[])\n"
2320 "{\n"
2321 " int fd, ret, event_fd, mount_fd;\n"
2322 " ssize_t size, path_len;\n"
2323 " char path[PATH_MAX];\n"
2324 " char procfd_path[PATH_MAX];\n"
2325 " char events_buf[BUF_SIZE];\n"
2326 " struct file_handle *file_handle;\n"
2327 " struct fanotify_event_metadata *metadata;\n"
2328 " struct fanotify_event_info_fid *fid;\n"
2329 " const char *file_name;\n"
2330 " struct stat sb;\n"
2331 "\\&\n"
2332 " if (argc != 2) {\n"
2333 " fprintf(stderr, \"Invalid number of command line arguments.\\[rs]n\");\n"
2334 " exit(EXIT_FAILURE);\n"
2335 " }\n"
2336 "\\&\n"
2337 " mount_fd = open(argv[1], O_DIRECTORY | O_RDONLY);\n"
2338 " if (mount_fd == -1) {\n"
2339 " perror(argv[1]);\n"
2340 " exit(EXIT_FAILURE);\n"
2341 " }\n"
2342 "\\&\n"
2343 " /* Create an fanotify file descriptor with FAN_REPORT_DFID_NAME as\n"
2344 " a flag so that program can receive fid events with directory\n"
2345 " entry name. */\n"
2346 "\\&\n"
2347 " fd = fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME, 0);\n"
2348 " if (fd == -1) {\n"
2349 " perror(\"fanotify_init\");\n"
2350 " exit(EXIT_FAILURE);\n"
2351 " }\n"
2352 "\\&\n"
2353 " /* Place a mark on the filesystem object supplied in argv[1]. */\n"
2354 "\\&\n"
2355 " ret = fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_ONLYDIR,\n"
2356 " FAN_CREATE | FAN_ONDIR,\n"
2357 " AT_FDCWD, argv[1]);\n"
2358 " if (ret == -1) {\n"
2359 " perror(\"fanotify_mark\");\n"
2360 " exit(EXIT_FAILURE);\n"
2361 " }\n"
2362 "\\&\n"
2363 " printf(\"Listening for events.\\[rs]n\");\n"
2364 "\\&\n"
2365 " /* Read events from the event queue into a buffer. */\n"
2366 "\\&\n"
2367 " size = read(fd, events_buf, sizeof(events_buf));\n"
2368 " if (size == -1 && errno != EAGAIN) {\n"
2369 " perror(\"read\");\n"
2370 " exit(EXIT_FAILURE);\n"
2371 " }\n"
2372 "\\&\n"
2373 " /* Process all events within the buffer. */\n"
2374 "\\&\n"
2375 " for (metadata = (struct fanotify_event_metadata *) events_buf;\n"
2376 " FAN_EVENT_OK(metadata, size);\n"
2377 " metadata = FAN_EVENT_NEXT(metadata, size)) {\n"
2378 " fid = (struct fanotify_event_info_fid *) (metadata + 1);\n"
2379 " file_handle = (struct file_handle *) fid-E<gt>handle;\n"
2380 "\\&\n"
2381 " /* Ensure that the event info is of the correct type. */\n"
2382 "\\&\n"
2383 " if (fid-E<gt>hdr.info_type == FAN_EVENT_INFO_TYPE_FID ||\n"
2384 " fid-E<gt>hdr.info_type == FAN_EVENT_INFO_TYPE_DFID) {\n"
2385 " file_name = NULL;\n"
2386 " } else if (fid-E<gt>hdr.info_type == FAN_EVENT_INFO_TYPE_DFID_NAME) {\n"
2387 " file_name = file_handle-E<gt>f_handle +\n"
2388 " file_handle-E<gt>handle_bytes;\n"
2389 " } else {\n"
2390 " fprintf(stderr, \"Received unexpected event info type.\\[rs]n\");\n"
2391 " exit(EXIT_FAILURE);\n"
2392 " }\n"
2393 "\\&\n"
2394 " if (metadata-E<gt>mask == FAN_CREATE)\n"
2395 " printf(\"FAN_CREATE (file created):\\[rs]n\");\n"
2396 "\\&\n"
2397 " if (metadata-E<gt>mask == (FAN_CREATE | FAN_ONDIR))\n"
2398 " printf(\"FAN_CREATE | FAN_ONDIR (subdirectory created):\\[rs]n\");\n"
2399 "\\&\n"
2400 "\t/* metadata-E<gt>fd is set to FAN_NOFD when the group identifies\n"
2401 "\t objects by file handles. To obtain a file descriptor for\n"
2402 "\t the file object corresponding to an event you can use the\n"
2403 "\t struct file_handle that\\[aq]s provided within the\n"
2404 "\t fanotify_event_info_fid in conjunction with the\n"
2405 "\t open_by_handle_at(2) system call. A check for ESTALE is\n"
2406 "\t done to accommodate for the situation where the file handle\n"
2407 "\t for the object was deleted prior to this system call. */\n"
2408 "\\&\n"
2409 " event_fd = open_by_handle_at(mount_fd, file_handle, O_RDONLY);\n"
2410 " if (event_fd == -1) {\n"
2411 " if (errno == ESTALE) {\n"
2412 " printf(\"File handle is no longer valid. \"\n"
2413 " \"File has been deleted\\[rs]n\");\n"
2414 " continue;\n"
2415 " } else {\n"
2416 " perror(\"open_by_handle_at\");\n"
2417 " exit(EXIT_FAILURE);\n"
2418 " }\n"
2419 " }\n"
2420 "\\&\n"
2421 " snprintf(procfd_path, sizeof(procfd_path), \"/proc/self/fd/%d\",\n"
2422 " event_fd);\n"
2423 "\\&\n"
2424 " /* Retrieve and print the path of the modified dentry. */\n"
2425 "\\&\n"
2426 " path_len = readlink(procfd_path, path, sizeof(path) - 1);\n"
2427 " if (path_len == -1) {\n"
2428 " perror(\"readlink\");\n"
2429 " exit(EXIT_FAILURE);\n"
2430 " }\n"
2431 "\\&\n"
2432 " path[path_len] = \\[aq]\\[rs]0\\[aq];\n"
2433 " printf(\"\\[rs]tDirectory \\[aq]%s\\[aq] has been modified.\\[rs]n\", path);\n"
2434 "\\&\n"
2435 " if (file_name) {\n"
2436 " ret = fstatat(event_fd, file_name, &sb, 0);\n"
2437 " if (ret == -1) {\n"
2438 " if (errno != ENOENT) {\n"
2439 " perror(\"fstatat\");\n"
2440 " exit(EXIT_FAILURE);\n"
2441 " }\n"
2442 " printf(\"\\[rs]tEntry \\[aq]%s\\[aq] does not exist.\\[rs]n\", file_name);\n"
2443 " } else if ((sb.st_mode & S_IFMT) == S_IFDIR) {\n"
2444 " printf(\"\\[rs]tEntry \\[aq]%s\\[aq] is a subdirectory.\\[rs]n\", file_name);\n"
2445 " } else {\n"
2446 " printf(\"\\[rs]tEntry \\[aq]%s\\[aq] is not a subdirectory.\\[rs]n\",\n"
2447 " file_name);\n"
2448 " }\n"
2449 " }\n"
2450 "\\&\n"
2451 " /* Close associated file descriptor for this event. */\n"
2452 "\\&\n"
2453 " close(event_fd);\n"
2454 " }\n"
2455 "\\&\n"
2456 " printf(\"All events processed successfully. Program exiting.\\[rs]n\");\n"
2457 " exit(EXIT_SUCCESS);\n"
2458 "}\n"
2459 msgstr ""
2460
2461 #. type: SH
2462 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2463 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2464 #, no-wrap
2465 msgid "SEE ALSO"
2466 msgstr ""
2467
2468 #. type: Plain text
2469 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2470 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2471 msgid "B<fanotify_init>(2), B<fanotify_mark>(2), B<inotify>(7)"
2472 msgstr ""
2473
2474 #. type: TH
2475 #: debian-trixie
2476 #, no-wrap
2477 msgid "2024-06-15"
2478 msgstr ""
2479
2480 #. type: TH
2481 #: debian-trixie
2482 #, no-wrap
2483 msgid "Linux man-pages 6.9.1"
2484 msgstr ""
2485
2486 #. type: Plain text
2487 #: debian-trixie
2488 msgid ""
2489 "This is the length of the data for the current event and the offset to the "
2490 "next event in the buffer. Unless the group identifies filesystem objects by "
2491 "file handles, the value of I<event_len> is always "
2492 "B<FAN_EVENT_METADATA_LEN>. For a group that identifies filesystem objects "
2493 "by file handles, I<event_len> also includes the variable length file "
2494 "identifier records."
2495 msgstr ""
2496
2497 #. type: Plain text
2498 #: debian-trixie
2499 msgid ""
2500 "This is the length of the structure. The field was introduced to facilitate "
2501 "the implementation of optional headers per event type. No such optional "
2502 "headers exist in the current implementation."
2503 msgstr ""
2504
2505 #. type: Plain text
2506 #: debian-trixie fedora-44 fedora-rawhide
2507 msgid ""
2508 "A unique integer value representing the type of information record object "
2509 "received for an event. The value of this field can be set to one of the "
2510 "following: B<FAN_EVENT_INFO_TYPE_FID>, B<FAN_EVENT_INFO_TYPE_DFID>, "
2511 "B<FAN_EVENT_INFO_TYPE_DFID_NAME>, or B<FAN_EVENT_INFO_TYPE_PIDFD>. The "
2512 "value set for this field is dependent on the flags that have been supplied "
2513 "to B<fanotify_init>(2). Refer to the field details of each information "
2514 "record object type below to understand the different cases in which the "
2515 "I<info_type> values can be set."
2516 msgstr ""
2517
2518 #. type: Plain text
2519 #: debian-trixie
2520 msgid ""
2521 "This is a unique identifier of the filesystem containing the object "
2522 "associated with the event. It is a structure of type I<__kernel_fsid_t> and "
2523 "contains the same value as I<f_fsid> when calling B<statfs>(2)."
2524 msgstr ""
2525
2526 #. type: Plain text
2527 #: debian-trixie
2528 msgid ""
2529 "This field contains a variable-length structure of type I<struct "
2530 "file_handle>. It is an opaque handle that corresponds to a specified object "
2531 "on a filesystem as returned by B<name_to_handle_at>(2). It can be used to "
2532 "uniquely identify a file on a filesystem and can be passed as an argument to "
2533 "B<open_by_handle_at>(2). If the value of I<info_type> field is "
2534 "B<FAN_EVENT_INFO_TYPE_DFID_NAME>, the file handle is followed by a null "
2535 "terminated string that identifies the created/deleted/moved directory entry "
2536 "name. For other events such as B<FAN_OPEN>, B<FAN_ATTRIB>, "
2537 "B<FAN_DELETE_SELF>, and B<FAN_MOVE_SELF>, if the value of I<info_type> field "
2538 "is B<FAN_EVENT_INFO_TYPE_FID>, the I<handle> identifies the object "
2539 "correlated to the event. If the value of I<info_type> field is "
2540 "B<FAN_EVENT_INFO_TYPE_DFID>, the I<handle> identifies the directory object "
2541 "correlated to the event or the parent directory of a non-directory object "
2542 "correlated to the event. If the value of I<info_type> field is "
2543 "B<FAN_EVENT_INFO_TYPE_DFID_NAME>, the I<handle> identifies the same "
2544 "directory object that would be reported with B<FAN_EVENT_INFO_TYPE_DFID> and "
2545 "the file handle is followed by a null terminated string that identifies the "
2546 "name of a directory entry in that directory, or '.' to identify the "
2547 "directory object itself."
2548 msgstr ""
2549
2550 #. type: TP
2551 #: debian-trixie
2552 #, no-wrap
2553 msgid "B<FAN_EVENT_OK(meta, len)>"
2554 msgstr ""
2555
2556 #. type: Plain text
2557 #: debian-trixie
2558 msgid ""
2559 "This macro checks the remaining length I<len> of the buffer I<meta> against "
2560 "the length of the metadata structure and the I<event_len> field of the first "
2561 "metadata structure in the buffer."
2562 msgstr ""
2563
2564 #. type: TP
2565 #: debian-trixie
2566 #, no-wrap
2567 msgid "B<FAN_EVENT_NEXT(meta, len)>"
2568 msgstr ""
2569
2570 #. type: Plain text
2571 #: debian-trixie
2572 msgid ""
2573 "This macro uses the length indicated in the I<event_len> field of the "
2574 "metadata structure pointed to by I<meta> to calculate the address of the "
2575 "next metadata structure that follows I<meta>. I<len> is the number of bytes "
2576 "of metadata that currently remain in the buffer. The macro returns a "
2577 "pointer to the next metadata structure that follows I<meta>, and reduces "
2578 "I<len> by the number of bytes in the metadata structure that has been "
2579 "skipped over (i.e., it subtracts I<meta-E<gt>event_len> from I<len>)."
2580 msgstr ""
2581
2582 #. type: Plain text
2583 #: debian-trixie fedora-44 fedora-rawhide
2584 msgid ""
2585 "This field indicates whether or not the permission is to be granted. Its "
2586 "value must be either B<FAN_ALLOW> to allow the file operation or B<FAN_DENY> "
2587 "to deny the file operation."
2588 msgstr ""
2589
2590 #. type: Plain text
2591 #: debian-trixie fedora-44 fedora-rawhide
2592 msgid ""
2593 "If access is denied, the requesting application call will receive an "
2594 "B<EPERM> error. Additionally, if the notification group has been created "
2595 "with the B<FAN_ENABLE_AUDIT> flag, then the B<FAN_AUDIT> flag can be set in "
2596 "the I<response> field. In that case, the audit subsystem will log "
2597 "information about the access decision to the audit logs."
2598 msgstr ""
2599
2600 #. type: Plain text
2601 #: debian-trixie fedora-44 fedora-rawhide
2602 msgid ""
2603 "Errors not directly related to a file (i.e. super block corruption) are "
2604 "reported with an invalid I<handle>. For these errors, the I<handle> will "
2605 "have the field I<handle_type> set to B<FILEID_INVALID>, and the handle "
2606 "buffer size set to B<0>."
2607 msgstr ""
2608
2609 #. commit 5b8fea65d197f408bb00b251c70d842826d6b70b
2610 #. type: Plain text
2611 #: debian-trixie
2612 msgid ""
2613 "Since Linux 5.13, the following interfaces can be used to control the amount "
2614 "of kernel resources consumed by fanotify:"
2615 msgstr ""
2616
2617 #. type: Plain text
2618 #: debian-trixie
2619 msgid ""
2620 "If a call to B<read>(2) processes multiple events from the fanotify queue "
2621 "and an error occurs, the return value will be the total length of the events "
2622 "successfully copied to the user-space buffer before the error occurred. The "
2623 "return value will not be -1, and I<errno> will not be set. Thus, the "
2624 "reading application has no way to detect the error."
2625 msgstr ""
2626
2627 #. type: Plain text
2628 #: debian-trixie fedora-44 fedora-rawhide
2629 #, no-wrap
2630 msgid ""
2631 "# B<./fanotify_example /home>\n"
2632 "Press enter key to terminate.\n"
2633 "Listening for events.\n"
2634 "FAN_OPEN_PERM: File /home/user/temp/notes\n"
2635 "FAN_CLOSE_WRITE: File /home/user/temp/notes\n"
2636 "\\&\n"
2637 "Listening for events stopped.\n"
2638 msgstr ""
2639
2640 #. type: Plain text
2641 #: debian-trixie
2642 #, no-wrap
2643 msgid ""
2644 "#define _GNU_SOURCE /* Needed to get O_LARGEFILE definition */\n"
2645 "#include E<lt>errno.hE<gt>\n"
2646 "#include E<lt>fcntl.hE<gt>\n"
2647 "#include E<lt>limits.hE<gt>\n"
2648 "#include E<lt>poll.hE<gt>\n"
2649 "#include E<lt>stdio.hE<gt>\n"
2650 "#include E<lt>stdlib.hE<gt>\n"
2651 "#include E<lt>sys/fanotify.hE<gt>\n"
2652 "#include E<lt>unistd.hE<gt>\n"
2653 "\\&\n"
2654 "/* Read all available fanotify events from the file descriptor \\[aq]fd\\[aq]. */\n"
2655 "\\&\n"
2656 "static void\n"
2657 "handle_events(int fd)\n"
2658 "{\n"
2659 " const struct fanotify_event_metadata *metadata;\n"
2660 " struct fanotify_event_metadata buf[200];\n"
2661 " ssize_t len;\n"
2662 " char path[PATH_MAX];\n"
2663 " ssize_t path_len;\n"
2664 " char procfd_path[PATH_MAX];\n"
2665 " struct fanotify_response response;\n"
2666 "\\&\n"
2667 " /* Loop while events can be read from fanotify file descriptor. */\n"
2668 "\\&\n"
2669 " for (;;) {\n"
2670 "\\&\n"
2671 " /* Read some events. */\n"
2672 "\\&\n"
2673 " len = read(fd, buf, sizeof(buf));\n"
2674 " if (len == -1 && errno != EAGAIN) {\n"
2675 " perror(\"read\");\n"
2676 " exit(EXIT_FAILURE);\n"
2677 " }\n"
2678 "\\&\n"
2679 " /* Check if end of available data reached. */\n"
2680 "\\&\n"
2681 " if (len E<lt>= 0)\n"
2682 " break;\n"
2683 "\\&\n"
2684 " /* Point to the first event in the buffer. */\n"
2685 "\\&\n"
2686 " metadata = buf;\n"
2687 "\\&\n"
2688 " /* Loop over all events in the buffer. */\n"
2689 "\\&\n"
2690 " while (FAN_EVENT_OK(metadata, len)) {\n"
2691 "\\&\n"
2692 " /* Check that run-time and compile-time structures match. */\n"
2693 "\\&\n"
2694 " if (metadata-E<gt>vers != FANOTIFY_METADATA_VERSION) {\n"
2695 " fprintf(stderr,\n"
2696 " \"Mismatch of fanotify metadata version.\\[rs]n\");\n"
2697 " exit(EXIT_FAILURE);\n"
2698 " }\n"
2699 "\\&\n"
2700 " /* metadata-E<gt>fd contains either FAN_NOFD, indicating a\n"
2701 " queue overflow, or a file descriptor (a nonnegative\n"
2702 " integer). Here, we simply ignore queue overflow. */\n"
2703 "\\&\n"
2704 " if (metadata-E<gt>fd E<gt>= 0) {\n"
2705 "\\&\n"
2706 " /* Handle open permission event. */\n"
2707 "\\&\n"
2708 " if (metadata-E<gt>mask & FAN_OPEN_PERM) {\n"
2709 " printf(\"FAN_OPEN_PERM: \");\n"
2710 "\\&\n"
2711 " /* Allow file to be opened. */\n"
2712 "\\&\n"
2713 " response.fd = metadata-E<gt>fd;\n"
2714 " response.response = FAN_ALLOW;\n"
2715 " write(fd, &response, sizeof(response));\n"
2716 " }\n"
2717 "\\&\n"
2718 " /* Handle closing of writable file event. */\n"
2719 "\\&\n"
2720 " if (metadata-E<gt>mask & FAN_CLOSE_WRITE)\n"
2721 " printf(\"FAN_CLOSE_WRITE: \");\n"
2722 "\\&\n"
2723 " /* Retrieve and print pathname of the accessed file. */\n"
2724 "\\&\n"
2725 " snprintf(procfd_path, sizeof(procfd_path),\n"
2726 " \"/proc/self/fd/%d\", metadata-E<gt>fd);\n"
2727 " path_len = readlink(procfd_path, path,\n"
2728 " sizeof(path) - 1);\n"
2729 " if (path_len == -1) {\n"
2730 " perror(\"readlink\");\n"
2731 " exit(EXIT_FAILURE);\n"
2732 " }\n"
2733 "\\&\n"
2734 " path[path_len] = \\[aq]\\[rs]0\\[aq];\n"
2735 " printf(\"File %s\\[rs]n\", path);\n"
2736 "\\&\n"
2737 " /* Close the file descriptor of the event. */\n"
2738 "\\&\n"
2739 " close(metadata-E<gt>fd);\n"
2740 " }\n"
2741 "\\&\n"
2742 " /* Advance to next event. */\n"
2743 "\\&\n"
2744 " metadata = FAN_EVENT_NEXT(metadata, len);\n"
2745 " }\n"
2746 " }\n"
2747 "}\n"
2748 "\\&\n"
2749 "int\n"
2750 "main(int argc, char *argv[])\n"
2751 "{\n"
2752 " char buf;\n"
2753 " int fd, poll_num;\n"
2754 " nfds_t nfds;\n"
2755 " struct pollfd fds[2];\n"
2756 "\\&\n"
2757 " /* Check mount point is supplied. */\n"
2758 "\\&\n"
2759 " if (argc != 2) {\n"
2760 " fprintf(stderr, \"Usage: %s MOUNT\\[rs]n\", argv[0]);\n"
2761 " exit(EXIT_FAILURE);\n"
2762 " }\n"
2763 "\\&\n"
2764 " printf(\"Press enter key to terminate.\\[rs]n\");\n"
2765 "\\&\n"
2766 " /* Create the file descriptor for accessing the fanotify API. */\n"
2767 "\\&\n"
2768 " fd = fanotify_init(FAN_CLOEXEC | FAN_CLASS_CONTENT | FAN_NONBLOCK,\n"
2769 " O_RDONLY | O_LARGEFILE);\n"
2770 " if (fd == -1) {\n"
2771 " perror(\"fanotify_init\");\n"
2772 " exit(EXIT_FAILURE);\n"
2773 " }\n"
2774 "\\&\n"
2775 " /* Mark the mount for:\n"
2776 " - permission events before opening files\n"
2777 " - notification events after closing a write-enabled\n"
2778 " file descriptor. */\n"
2779 "\\&\n"
2780 " if (fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT,\n"
2781 " FAN_OPEN_PERM | FAN_CLOSE_WRITE, AT_FDCWD,\n"
2782 " argv[1]) == -1) {\n"
2783 " perror(\"fanotify_mark\");\n"
2784 " exit(EXIT_FAILURE);\n"
2785 " }\n"
2786 "\\&\n"
2787 " /* Prepare for polling. */\n"
2788 "\\&\n"
2789 " nfds = 2;\n"
2790 "\\&\n"
2791 " fds[0].fd = STDIN_FILENO; /* Console input */\n"
2792 " fds[0].events = POLLIN;\n"
2793 "\\&\n"
2794 " fds[1].fd = fd; /* Fanotify input */\n"
2795 " fds[1].events = POLLIN;\n"
2796 "\\&\n"
2797 " /* This is the loop to wait for incoming events. */\n"
2798 "\\&\n"
2799 " printf(\"Listening for events.\\[rs]n\");\n"
2800 "\\&\n"
2801 " while (1) {\n"
2802 " poll_num = poll(fds, nfds, -1);\n"
2803 " if (poll_num == -1) {\n"
2804 " if (errno == EINTR) /* Interrupted by a signal */\n"
2805 " continue; /* Restart poll() */\n"
2806 "\\&\n"
2807 " perror(\"poll\"); /* Unexpected error */\n"
2808 " exit(EXIT_FAILURE);\n"
2809 " }\n"
2810 "\\&\n"
2811 " if (poll_num E<gt> 0) {\n"
2812 " if (fds[0].revents & POLLIN) {\n"
2813 "\\&\n"
2814 " /* Console input is available: empty stdin and quit. */\n"
2815 "\\&\n"
2816 " while (read(STDIN_FILENO, &buf, 1) E<gt> 0 && buf != \\[aq]\\[rs]n\\[aq])\n"
2817 " continue;\n"
2818 " break;\n"
2819 " }\n"
2820 "\\&\n"
2821 " if (fds[1].revents & POLLIN) {\n"
2822 "\\&\n"
2823 " /* Fanotify events are available. */\n"
2824 "\\&\n"
2825 " handle_events(fd);\n"
2826 " }\n"
2827 " }\n"
2828 " }\n"
2829 "\\&\n"
2830 " printf(\"Listening for events stopped.\\[rs]n\");\n"
2831 " exit(EXIT_SUCCESS);\n"
2832 "}\n"
2833 msgstr ""
2834
2835 #. type: Plain text
2836 #: debian-trixie fedora-44 fedora-rawhide
2837 #, no-wrap
2838 msgid ""
2839 "# B<./fanotify_fid /home/user>\n"
2840 "Listening for events.\n"
2841 "FAN_CREATE (file created):\n"
2842 " Directory /home/user has been modified.\n"
2843 " Entry \\[aq]testfile.txt\\[aq] is not a subdirectory.\n"
2844 "All events processed successfully. Program exiting.\n"
2845 "\\&\n"
2846 "$ B<touch /home/user/testfile.txt> # In another terminal\n"
2847 msgstr ""
2848
2849 #. type: Plain text
2850 #: debian-trixie fedora-44 fedora-rawhide
2851 #, no-wrap
2852 msgid ""
2853 "# B<./fanotify_fid /home/user>\n"
2854 "Listening for events.\n"
2855 "FAN_CREATE | FAN_ONDIR (subdirectory created):\n"
2856 " Directory /home/user has been modified.\n"
2857 " Entry \\[aq]testdir\\[aq] is a subdirectory.\n"
2858 "All events processed successfully. Program exiting.\n"
2859 "\\&\n"
2860 "$ B<mkdir -p /home/user/testdir> # In another terminal\n"
2861 msgstr ""
2862
2863 #. type: Plain text
2864 #: debian-trixie
2865 #, no-wrap
2866 msgid ""
2867 "#define _GNU_SOURCE\n"
2868 "#include E<lt>errno.hE<gt>\n"
2869 "#include E<lt>fcntl.hE<gt>\n"
2870 "#include E<lt>limits.hE<gt>\n"
2871 "#include E<lt>stdio.hE<gt>\n"
2872 "#include E<lt>stdlib.hE<gt>\n"
2873 "#include E<lt>sys/types.hE<gt>\n"
2874 "#include E<lt>sys/stat.hE<gt>\n"
2875 "#include E<lt>sys/fanotify.hE<gt>\n"
2876 "#include E<lt>unistd.hE<gt>\n"
2877 "\\&\n"
2878 "#define BUF_SIZE 256\n"
2879 "\\&\n"
2880 "int\n"
2881 "main(int argc, char *argv[])\n"
2882 "{\n"
2883 " int fd, ret, event_fd, mount_fd;\n"
2884 " ssize_t len, path_len;\n"
2885 " char path[PATH_MAX];\n"
2886 " char procfd_path[PATH_MAX];\n"
2887 " char events_buf[BUF_SIZE];\n"
2888 " struct file_handle *file_handle;\n"
2889 " struct fanotify_event_metadata *metadata;\n"
2890 " struct fanotify_event_info_fid *fid;\n"
2891 " const char *file_name;\n"
2892 " struct stat sb;\n"
2893 "\\&\n"
2894 " if (argc != 2) {\n"
2895 " fprintf(stderr, \"Invalid number of command line arguments.\\[rs]n\");\n"
2896 " exit(EXIT_FAILURE);\n"
2897 " }\n"
2898 "\\&\n"
2899 " mount_fd = open(argv[1], O_DIRECTORY | O_RDONLY);\n"
2900 " if (mount_fd == -1) {\n"
2901 " perror(argv[1]);\n"
2902 " exit(EXIT_FAILURE);\n"
2903 " }\n"
2904 "\\&\n"
2905 " /* Create an fanotify file descriptor with FAN_REPORT_DFID_NAME as\n"
2906 " a flag so that program can receive fid events with directory\n"
2907 " entry name. */\n"
2908 "\\&\n"
2909 " fd = fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME, 0);\n"
2910 " if (fd == -1) {\n"
2911 " perror(\"fanotify_init\");\n"
2912 " exit(EXIT_FAILURE);\n"
2913 " }\n"
2914 "\\&\n"
2915 " /* Place a mark on the filesystem object supplied in argv[1]. */\n"
2916 "\\&\n"
2917 " ret = fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_ONLYDIR,\n"
2918 " FAN_CREATE | FAN_ONDIR,\n"
2919 " AT_FDCWD, argv[1]);\n"
2920 " if (ret == -1) {\n"
2921 " perror(\"fanotify_mark\");\n"
2922 " exit(EXIT_FAILURE);\n"
2923 " }\n"
2924 "\\&\n"
2925 " printf(\"Listening for events.\\[rs]n\");\n"
2926 "\\&\n"
2927 " /* Read events from the event queue into a buffer. */\n"
2928 "\\&\n"
2929 " len = read(fd, events_buf, sizeof(events_buf));\n"
2930 " if (len == -1 && errno != EAGAIN) {\n"
2931 " perror(\"read\");\n"
2932 " exit(EXIT_FAILURE);\n"
2933 " }\n"
2934 "\\&\n"
2935 " /* Process all events within the buffer. */\n"
2936 "\\&\n"
2937 " for (metadata = (struct fanotify_event_metadata *) events_buf;\n"
2938 " FAN_EVENT_OK(metadata, len);\n"
2939 " metadata = FAN_EVENT_NEXT(metadata, len)) {\n"
2940 " fid = (struct fanotify_event_info_fid *) (metadata + 1);\n"
2941 " file_handle = (struct file_handle *) fid-E<gt>handle;\n"
2942 "\\&\n"
2943 " /* Ensure that the event info is of the correct type. */\n"
2944 "\\&\n"
2945 " if (fid-E<gt>hdr.info_type == FAN_EVENT_INFO_TYPE_FID ||\n"
2946 " fid-E<gt>hdr.info_type == FAN_EVENT_INFO_TYPE_DFID) {\n"
2947 " file_name = NULL;\n"
2948 " } else if (fid-E<gt>hdr.info_type == FAN_EVENT_INFO_TYPE_DFID_NAME) {\n"
2949 " file_name = file_handle-E<gt>f_handle +\n"
2950 " file_handle-E<gt>handle_bytes;\n"
2951 " } else {\n"
2952 " fprintf(stderr, \"Received unexpected event info type.\\[rs]n\");\n"
2953 " exit(EXIT_FAILURE);\n"
2954 " }\n"
2955 "\\&\n"
2956 " if (metadata-E<gt>mask == FAN_CREATE)\n"
2957 " printf(\"FAN_CREATE (file created):\\[rs]n\");\n"
2958 "\\&\n"
2959 " if (metadata-E<gt>mask == (FAN_CREATE | FAN_ONDIR))\n"
2960 " printf(\"FAN_CREATE | FAN_ONDIR (subdirectory created):\\[rs]n\");\n"
2961 "\\&\n"
2962 "\t/* metadata-E<gt>fd is set to FAN_NOFD when the group identifies\n"
2963 "\t objects by file handles. To obtain a file descriptor for\n"
2964 "\t the file object corresponding to an event you can use the\n"
2965 "\t struct file_handle that\\[aq]s provided within the\n"
2966 "\t fanotify_event_info_fid in conjunction with the\n"
2967 "\t open_by_handle_at(2) system call. A check for ESTALE is\n"
2968 "\t done to accommodate for the situation where the file handle\n"
2969 "\t for the object was deleted prior to this system call. */\n"
2970 "\\&\n"
2971 " event_fd = open_by_handle_at(mount_fd, file_handle, O_RDONLY);\n"
2972 " if (event_fd == -1) {\n"
2973 " if (errno == ESTALE) {\n"
2974 " printf(\"File handle is no longer valid. \"\n"
2975 " \"File has been deleted\\[rs]n\");\n"
2976 " continue;\n"
2977 " } else {\n"
2978 " perror(\"open_by_handle_at\");\n"
2979 " exit(EXIT_FAILURE);\n"
2980 " }\n"
2981 " }\n"
2982 "\\&\n"
2983 " snprintf(procfd_path, sizeof(procfd_path), \"/proc/self/fd/%d\",\n"
2984 " event_fd);\n"
2985 "\\&\n"
2986 " /* Retrieve and print the path of the modified dentry. */\n"
2987 "\\&\n"
2988 " path_len = readlink(procfd_path, path, sizeof(path) - 1);\n"
2989 " if (path_len == -1) {\n"
2990 " perror(\"readlink\");\n"
2991 " exit(EXIT_FAILURE);\n"
2992 " }\n"
2993 "\\&\n"
2994 " path[path_len] = \\[aq]\\[rs]0\\[aq];\n"
2995 " printf(\"\\[rs]tDirectory \\[aq]%s\\[aq] has been modified.\\[rs]n\", path);\n"
2996 "\\&\n"
2997 " if (file_name) {\n"
2998 " ret = fstatat(event_fd, file_name, &sb, 0);\n"
2999 " if (ret == -1) {\n"
3000 " if (errno != ENOENT) {\n"
3001 " perror(\"fstatat\");\n"
3002 " exit(EXIT_FAILURE);\n"
3003 " }\n"
3004 " printf(\"\\[rs]tEntry \\[aq]%s\\[aq] does not exist.\\[rs]n\", file_name);\n"
3005 " } else if ((sb.st_mode & S_IFMT) == S_IFDIR) {\n"
3006 " printf(\"\\[rs]tEntry \\[aq]%s\\[aq] is a subdirectory.\\[rs]n\", file_name);\n"
3007 " } else {\n"
3008 " printf(\"\\[rs]tEntry \\[aq]%s\\[aq] is not a subdirectory.\\[rs]n\",\n"
3009 " file_name);\n"
3010 " }\n"
3011 " }\n"
3012 "\\&\n"
3013 " /* Close associated file descriptor for this event. */\n"
3014 "\\&\n"
3015 " close(event_fd);\n"
3016 " }\n"
3017 "\\&\n"
3018 " printf(\"All events processed successfully. Program exiting.\\[rs]n\");\n"
3019 " exit(EXIT_SUCCESS);\n"
3020 "}\n"
3021 msgstr ""
3022
3023 #. type: TH
3024 #: fedora-44 fedora-rawhide
3025 #, no-wrap
3026 msgid "2024-11-17"
3027 msgstr ""
3028
3029 #. type: TH
3030 #: fedora-44 fedora-rawhide
3031 #, no-wrap
3032 msgid "Linux man-pages 6.13"
3033 msgstr ""
3034
3035 #. type: Plain text
3036 #: fedora-44 fedora-rawhide
3037 #, no-wrap
3038 msgid ""
3039 "#define _GNU_SOURCE /* Needed to get O_LARGEFILE definition */\n"
3040 "#include E<lt>errno.hE<gt>\n"
3041 "#include E<lt>fcntl.hE<gt>\n"
3042 "#include E<lt>limits.hE<gt>\n"
3043 "#include E<lt>poll.hE<gt>\n"
3044 "#include E<lt>stdio.hE<gt>\n"
3045 "#include E<lt>stdlib.hE<gt>\n"
3046 "#include E<lt>sys/fanotify.hE<gt>\n"
3047 "#include E<lt>unistd.hE<gt>\n"
3048 "\\&\n"
3049 "/* Read all available fanotify events from the file descriptor \\[aq]fd\\[aq]. */\n"
3050 "\\&\n"
3051 "static void\n"
3052 "handle_events(int fd)\n"
3053 "{\n"
3054 " const struct fanotify_event_metadata *metadata;\n"
3055 " struct fanotify_event_metadata buf[200];\n"
3056 " ssize_t size;\n"
3057 " char path[PATH_MAX];\n"
3058 " ssize_t path_len;\n"
3059 " char procfd_path[PATH_MAX];\n"
3060 " struct fanotify_response response;\n"
3061 "\\&\n"
3062 " /* Loop while events can be read from fanotify file descriptor. */\n"
3063 "\\&\n"
3064 " for (;;) {\n"
3065 "\\&\n"
3066 " /* Read some events. */\n"
3067 "\\&\n"
3068 " size = read(fd, buf, sizeof(buf));\n"
3069 " if (size == -1 && errno != EAGAIN) {\n"
3070 " perror(\"read\");\n"
3071 " exit(EXIT_FAILURE);\n"
3072 " }\n"
3073 "\\&\n"
3074 " /* Check if end of available data reached. */\n"
3075 "\\&\n"
3076 " if (size E<lt>= 0)\n"
3077 " break;\n"
3078 "\\&\n"
3079 " /* Point to the first event in the buffer. */\n"
3080 "\\&\n"
3081 " metadata = buf;\n"
3082 "\\&\n"
3083 " /* Loop over all events in the buffer. */\n"
3084 "\\&\n"
3085 " while (FAN_EVENT_OK(metadata, size)) {\n"
3086 "\\&\n"
3087 " /* Check that run-time and compile-time structures match. */\n"
3088 "\\&\n"
3089 " if (metadata-E<gt>vers != FANOTIFY_METADATA_VERSION) {\n"
3090 " fprintf(stderr,\n"
3091 " \"Mismatch of fanotify metadata version.\\[rs]n\");\n"
3092 " exit(EXIT_FAILURE);\n"
3093 " }\n"
3094 "\\&\n"
3095 " /* metadata-E<gt>fd contains either FAN_NOFD, indicating a\n"
3096 " queue overflow, or a file descriptor (a nonnegative\n"
3097 " integer). Here, we simply ignore queue overflow. */\n"
3098 "\\&\n"
3099 " if (metadata-E<gt>fd E<gt>= 0) {\n"
3100 "\\&\n"
3101 " /* Handle open permission event. */\n"
3102 "\\&\n"
3103 " if (metadata-E<gt>mask & FAN_OPEN_PERM) {\n"
3104 " printf(\"FAN_OPEN_PERM: \");\n"
3105 "\\&\n"
3106 " /* Allow file to be opened. */\n"
3107 "\\&\n"
3108 " response.fd = metadata-E<gt>fd;\n"
3109 " response.response = FAN_ALLOW;\n"
3110 " write(fd, &response, sizeof(response));\n"
3111 " }\n"
3112 "\\&\n"
3113 " /* Handle closing of writable file event. */\n"
3114 "\\&\n"
3115 " if (metadata-E<gt>mask & FAN_CLOSE_WRITE)\n"
3116 " printf(\"FAN_CLOSE_WRITE: \");\n"
3117 "\\&\n"
3118 " /* Retrieve and print pathname of the accessed file. */\n"
3119 "\\&\n"
3120 " snprintf(procfd_path, sizeof(procfd_path),\n"
3121 " \"/proc/self/fd/%d\", metadata-E<gt>fd);\n"
3122 " path_len = readlink(procfd_path, path,\n"
3123 " sizeof(path) - 1);\n"
3124 " if (path_len == -1) {\n"
3125 " perror(\"readlink\");\n"
3126 " exit(EXIT_FAILURE);\n"
3127 " }\n"
3128 "\\&\n"
3129 " path[path_len] = \\[aq]\\[rs]0\\[aq];\n"
3130 " printf(\"File %s\\[rs]n\", path);\n"
3131 "\\&\n"
3132 " /* Close the file descriptor of the event. */\n"
3133 "\\&\n"
3134 " close(metadata-E<gt>fd);\n"
3135 " }\n"
3136 "\\&\n"
3137 " /* Advance to next event. */\n"
3138 "\\&\n"
3139 " metadata = FAN_EVENT_NEXT(metadata, size);\n"
3140 " }\n"
3141 " }\n"
3142 "}\n"
3143 "\\&\n"
3144 "int\n"
3145 "main(int argc, char *argv[])\n"
3146 "{\n"
3147 " char buf;\n"
3148 " int fd, poll_num;\n"
3149 " nfds_t nfds;\n"
3150 " struct pollfd fds[2];\n"
3151 "\\&\n"
3152 " /* Check mount point is supplied. */\n"
3153 "\\&\n"
3154 " if (argc != 2) {\n"
3155 " fprintf(stderr, \"Usage: %s MOUNT\\[rs]n\", argv[0]);\n"
3156 " exit(EXIT_FAILURE);\n"
3157 " }\n"
3158 "\\&\n"
3159 " printf(\"Press enter key to terminate.\\[rs]n\");\n"
3160 "\\&\n"
3161 " /* Create the file descriptor for accessing the fanotify API. */\n"
3162 "\\&\n"
3163 " fd = fanotify_init(FAN_CLOEXEC | FAN_CLASS_CONTENT | FAN_NONBLOCK,\n"
3164 " O_RDONLY | O_LARGEFILE);\n"
3165 " if (fd == -1) {\n"
3166 " perror(\"fanotify_init\");\n"
3167 " exit(EXIT_FAILURE);\n"
3168 " }\n"
3169 "\\&\n"
3170 " /* Mark the mount for:\n"
3171 " - permission events before opening files\n"
3172 " - notification events after closing a write-enabled\n"
3173 " file descriptor. */\n"
3174 "\\&\n"
3175 " if (fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT,\n"
3176 " FAN_OPEN_PERM | FAN_CLOSE_WRITE, AT_FDCWD,\n"
3177 " argv[1]) == -1) {\n"
3178 " perror(\"fanotify_mark\");\n"
3179 " exit(EXIT_FAILURE);\n"
3180 " }\n"
3181 "\\&\n"
3182 " /* Prepare for polling. */\n"
3183 "\\&\n"
3184 " nfds = 2;\n"
3185 "\\&\n"
3186 " fds[0].fd = STDIN_FILENO; /* Console input */\n"
3187 " fds[0].events = POLLIN;\n"
3188 "\\&\n"
3189 " fds[1].fd = fd; /* Fanotify input */\n"
3190 " fds[1].events = POLLIN;\n"
3191 "\\&\n"
3192 " /* This is the loop to wait for incoming events. */\n"
3193 "\\&\n"
3194 " printf(\"Listening for events.\\[rs]n\");\n"
3195 "\\&\n"
3196 " while (1) {\n"
3197 " poll_num = poll(fds, nfds, -1);\n"
3198 " if (poll_num == -1) {\n"
3199 " if (errno == EINTR) /* Interrupted by a signal */\n"
3200 " continue; /* Restart poll() */\n"
3201 "\\&\n"
3202 " perror(\"poll\"); /* Unexpected error */\n"
3203 " exit(EXIT_FAILURE);\n"
3204 " }\n"
3205 "\\&\n"
3206 " if (poll_num E<gt> 0) {\n"
3207 " if (fds[0].revents & POLLIN) {\n"
3208 "\\&\n"
3209 " /* Console input is available: empty stdin and quit. */\n"
3210 "\\&\n"
3211 " while (read(STDIN_FILENO, &buf, 1) E<gt> 0 && buf != \\[aq]\\[rs]n\\[aq])\n"
3212 " continue;\n"
3213 " break;\n"
3214 " }\n"
3215 "\\&\n"
3216 " if (fds[1].revents & POLLIN) {\n"
3217 "\\&\n"
3218 " /* Fanotify events are available. */\n"
3219 "\\&\n"
3220 " handle_events(fd);\n"
3221 " }\n"
3222 " }\n"
3223 " }\n"
3224 "\\&\n"
3225 " printf(\"Listening for events stopped.\\[rs]n\");\n"
3226 " exit(EXIT_SUCCESS);\n"
3227 "}\n"
3228 msgstr ""
3229
3230 #. type: Plain text
3231 #: fedora-44 fedora-rawhide
3232 #, no-wrap
3233 msgid ""
3234 "#define _GNU_SOURCE\n"
3235 "#include E<lt>errno.hE<gt>\n"
3236 "#include E<lt>fcntl.hE<gt>\n"
3237 "#include E<lt>limits.hE<gt>\n"
3238 "#include E<lt>stdio.hE<gt>\n"
3239 "#include E<lt>stdlib.hE<gt>\n"
3240 "#include E<lt>sys/types.hE<gt>\n"
3241 "#include E<lt>sys/stat.hE<gt>\n"
3242 "#include E<lt>sys/fanotify.hE<gt>\n"
3243 "#include E<lt>unistd.hE<gt>\n"
3244 "\\&\n"
3245 "#define BUF_SIZE 256\n"
3246 "\\&\n"
3247 "int\n"
3248 "main(int argc, char *argv[])\n"
3249 "{\n"
3250 " int fd, ret, event_fd, mount_fd;\n"
3251 " ssize_t size, path_len;\n"
3252 " char path[PATH_MAX];\n"
3253 " char procfd_path[PATH_MAX];\n"
3254 " char events_buf[BUF_SIZE];\n"
3255 " struct file_handle *file_handle;\n"
3256 " struct fanotify_event_metadata *metadata;\n"
3257 " struct fanotify_event_info_fid *fid;\n"
3258 " const char *file_name;\n"
3259 " struct stat sb;\n"
3260 "\\&\n"
3261 " if (argc != 2) {\n"
3262 " fprintf(stderr, \"Invalid number of command line arguments.\\[rs]n\");\n"
3263 " exit(EXIT_FAILURE);\n"
3264 " }\n"
3265 "\\&\n"
3266 " mount_fd = open(argv[1], O_DIRECTORY | O_RDONLY);\n"
3267 " if (mount_fd == -1) {\n"
3268 " perror(argv[1]);\n"
3269 " exit(EXIT_FAILURE);\n"
3270 " }\n"
3271 "\\&\n"
3272 " /* Create an fanotify file descriptor with FAN_REPORT_DFID_NAME as\n"
3273 " a flag so that program can receive fid events with directory\n"
3274 " entry name. */\n"
3275 "\\&\n"
3276 " fd = fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME, 0);\n"
3277 " if (fd == -1) {\n"
3278 " perror(\"fanotify_init\");\n"
3279 " exit(EXIT_FAILURE);\n"
3280 " }\n"
3281 "\\&\n"
3282 " /* Place a mark on the filesystem object supplied in argv[1]. */\n"
3283 "\\&\n"
3284 " ret = fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_ONLYDIR,\n"
3285 " FAN_CREATE | FAN_ONDIR,\n"
3286 " AT_FDCWD, argv[1]);\n"
3287 " if (ret == -1) {\n"
3288 " perror(\"fanotify_mark\");\n"
3289 " exit(EXIT_FAILURE);\n"
3290 " }\n"
3291 "\\&\n"
3292 " printf(\"Listening for events.\\[rs]n\");\n"
3293 "\\&\n"
3294 " /* Read events from the event queue into a buffer. */\n"
3295 "\\&\n"
3296 " size = read(fd, events_buf, sizeof(events_buf));\n"
3297 " if (size == -1 && errno != EAGAIN) {\n"
3298 " perror(\"read\");\n"
3299 " exit(EXIT_FAILURE);\n"
3300 " }\n"
3301 "\\&\n"
3302 " /* Process all events within the buffer. */\n"
3303 "\\&\n"
3304 " for (metadata = (struct fanotify_event_metadata *) events_buf;\n"
3305 " FAN_EVENT_OK(metadata, size);\n"
3306 " metadata = FAN_EVENT_NEXT(metadata, size)) {\n"
3307 " fid = (struct fanotify_event_info_fid *) (metadata + 1);\n"
3308 " file_handle = (struct file_handle *) fid-E<gt>handle;\n"
3309 "\\&\n"
3310 " /* Ensure that the event info is of the correct type. */\n"
3311 "\\&\n"
3312 " if (fid-E<gt>hdr.info_type == FAN_EVENT_INFO_TYPE_FID ||\n"
3313 " fid-E<gt>hdr.info_type == FAN_EVENT_INFO_TYPE_DFID) {\n"
3314 " file_name = NULL;\n"
3315 " } else if (fid-E<gt>hdr.info_type == FAN_EVENT_INFO_TYPE_DFID_NAME) {\n"
3316 " file_name = file_handle-E<gt>f_handle +\n"
3317 " file_handle-E<gt>handle_bytes;\n"
3318 " } else {\n"
3319 " fprintf(stderr, \"Received unexpected event info type.\\[rs]n\");\n"
3320 " exit(EXIT_FAILURE);\n"
3321 " }\n"
3322 "\\&\n"
3323 " if (metadata-E<gt>mask == FAN_CREATE)\n"
3324 " printf(\"FAN_CREATE (file created):\\[rs]n\");\n"
3325 "\\&\n"
3326 " if (metadata-E<gt>mask == (FAN_CREATE | FAN_ONDIR))\n"
3327 " printf(\"FAN_CREATE | FAN_ONDIR (subdirectory created):\\[rs]n\");\n"
3328 "\\&\n"
3329 "\t/* metadata-E<gt>fd is set to FAN_NOFD when the group identifies\n"
3330 "\t objects by file handles. To obtain a file descriptor for\n"
3331 "\t the file object corresponding to an event you can use the\n"
3332 "\t struct file_handle that\\[aq]s provided within the\n"
3333 "\t fanotify_event_info_fid in conjunction with the\n"
3334 "\t open_by_handle_at(2) system call. A check for ESTALE is\n"
3335 "\t done to accommodate for the situation where the file handle\n"
3336 "\t for the object was deleted prior to this system call. */\n"
3337 "\\&\n"
3338 " event_fd = open_by_handle_at(mount_fd, file_handle, O_RDONLY);\n"
3339 " if (event_fd == -1) {\n"
3340 " if (errno == ESTALE) {\n"
3341 " printf(\"File handle is no longer valid. \"\n"
3342 " \"File has been deleted\\[rs]n\");\n"
3343 " continue;\n"
3344 " } else {\n"
3345 " perror(\"open_by_handle_at\");\n"
3346 " exit(EXIT_FAILURE);\n"
3347 " }\n"
3348 " }\n"
3349 "\\&\n"
3350 " snprintf(procfd_path, sizeof(procfd_path), \"/proc/self/fd/%d\",\n"
3351 " event_fd);\n"
3352 "\\&\n"
3353 " /* Retrieve and print the path of the modified dentry. */\n"
3354 "\\&\n"
3355 " path_len = readlink(procfd_path, path, sizeof(path) - 1);\n"
3356 " if (path_len == -1) {\n"
3357 " perror(\"readlink\");\n"
3358 " exit(EXIT_FAILURE);\n"
3359 " }\n"
3360 "\\&\n"
3361 " path[path_len] = \\[aq]\\[rs]0\\[aq];\n"
3362 " printf(\"\\[rs]tDirectory \\[aq]%s\\[aq] has been modified.\\[rs]n\", path);\n"
3363 "\\&\n"
3364 " if (file_name) {\n"
3365 " ret = fstatat(event_fd, file_name, &sb, 0);\n"
3366 " if (ret == -1) {\n"
3367 " if (errno != ENOENT) {\n"
3368 " perror(\"fstatat\");\n"
3369 " exit(EXIT_FAILURE);\n"
3370 " }\n"
3371 " printf(\"\\[rs]tEntry \\[aq]%s\\[aq] does not exist.\\[rs]n\", file_name);\n"
3372 " } else if ((sb.st_mode & S_IFMT) == S_IFDIR) {\n"
3373 " printf(\"\\[rs]tEntry \\[aq]%s\\[aq] is a subdirectory.\\[rs]n\", file_name);\n"
3374 " } else {\n"
3375 " printf(\"\\[rs]tEntry \\[aq]%s\\[aq] is not a subdirectory.\\[rs]n\",\n"
3376 " file_name);\n"
3377 " }\n"
3378 " }\n"
3379 "\\&\n"
3380 " /* Close associated file descriptor for this event. */\n"
3381 "\\&\n"
3382 " close(event_fd);\n"
3383 " }\n"
3384 "\\&\n"
3385 " printf(\"All events processed successfully. Program exiting.\\[rs]n\");\n"
3386 " exit(EXIT_SUCCESS);\n"
3387 "}\n"
3388 msgstr ""
3389
3390 #. type: TH
3391 #: mageia-cauldron
3392 #, no-wrap
3393 msgid "2026-02-08"
3394 msgstr ""
3395
3396 #. type: TH
3397 #: mageia-cauldron
3398 #, no-wrap
3399 msgid "Linux man-pages 6.17"
3400 msgstr ""
3401
3402 #. type: Plain text
3403 #: mageia-cauldron
3404 #, no-wrap
3405 msgid ""
3406 "#define _GNU_SOURCE /* Needed to get O_LARGEFILE definition */\n"
3407 "#include E<lt>errno.hE<gt>\n"
3408 "#include E<lt>fcntl.hE<gt>\n"
3409 "#include E<lt>limits.hE<gt>\n"
3410 "#include E<lt>poll.hE<gt>\n"
3411 "#include E<lt>stdio.hE<gt>\n"
3412 "#include E<lt>stdlib.hE<gt>\n"
3413 "#include E<lt>sys/fanotify.hE<gt>\n"
3414 "#include E<lt>unistd.hE<gt>\n"
3415 "\\&\n"
3416 "/* Read all available fanotify events from the file descriptor \\[aq]fd\\[aq]. */\n"
3417 "\\&\n"
3418 "static void\n"
3419 "handle_events(int fd)\n"
3420 "{\n"
3421 " const struct fanotify_event_metadata *metadata;\n"
3422 " struct fanotify_event_metadata buf[200];\n"
3423 " ssize_t size;\n"
3424 " char path[PATH_MAX];\n"
3425 " ssize_t path_len;\n"
3426 " char procfd_path[PATH_MAX];\n"
3427 " struct fanotify_response response;\n"
3428 "\\&\n"
3429 " /* Loop while events can be read from fanotify file descriptor. */\n"
3430 "\\&\n"
3431 " for (;;) {\n"
3432 "\\&\n"
3433 " /* Read some events. */\n"
3434 "\\&\n"
3435 " size = read(fd, buf, sizeof(buf));\n"
3436 " if (size == -1 && errno != EAGAIN) {\n"
3437 " perror(\"read\");\n"
3438 " exit(EXIT_FAILURE);\n"
3439 " }\n"
3440 "\\&\n"
3441 " /* Check if end of available data reached. */\n"
3442 "\\&\n"
3443 " if (size E<lt>= 0)\n"
3444 " break;\n"
3445 "\\&\n"
3446 " /* Point to the first event in the buffer. */\n"
3447 "\\&\n"
3448 " metadata = buf;\n"
3449 "\\&\n"
3450 " /* Loop over all events in the buffer. */\n"
3451 "\\&\n"
3452 " while (FAN_EVENT_OK(metadata, size)) {\n"
3453 "\\&\n"
3454 " /* Check that run-time and compile-time structures match. */\n"
3455 "\\&\n"
3456 " if (metadata-E<gt>vers != FANOTIFY_METADATA_VERSION) {\n"
3457 " fprintf(stderr,\n"
3458 " \"Mismatch of fanotify metadata version.\\[rs]n\");\n"
3459 " exit(EXIT_FAILURE);\n"
3460 " }\n"
3461 "\\&\n"
3462 " /* metadata-E<gt>fd contains either FAN_NOFD, indicating a\n"
3463 " queue overflow, or a file descriptor (a nonnegative\n"
3464 " integer). Here, we simply ignore queue overflow. */\n"
3465 "\\&\n"
3466 " if (metadata-E<gt>fd E<gt>= 0) {\n"
3467 "\\&\n"
3468 " /* Handle open permission event. */\n"
3469 "\\&\n"
3470 " if (metadata-E<gt>mask & FAN_OPEN_PERM) {\n"
3471 " printf(\"FAN_OPEN_PERM: \");\n"
3472 "\\&\n"
3473 " /* Allow file to be opened. */\n"
3474 "\\&\n"
3475 " response.fd = metadata-E<gt>fd;\n"
3476 " response.response = FAN_ALLOW;\n"
3477 " write(fd, &response, sizeof(response));\n"
3478 " }\n"
3479 "\\&\n"
3480 " /* Handle closing of writable file event. */\n"
3481 "\\&\n"
3482 " if (metadata-E<gt>mask & FAN_CLOSE_WRITE)\n"
3483 " printf(\"FAN_CLOSE_WRITE: \");\n"
3484 "\\&\n"
3485 " /* Retrieve and print pathname of the accessed file. */\n"
3486 "\\&\n"
3487 " snprintf(procfd_path, sizeof(procfd_path),\n"
3488 " \"/proc/self/fd/%d\", metadata-E<gt>fd);\n"
3489 " path_len = readlink(procfd_path, path,\n"
3490 " sizeof(path) - 1);\n"
3491 " if (path_len == -1) {\n"
3492 " perror(\"readlink\");\n"
3493 " exit(EXIT_FAILURE);\n"
3494 " }\n"
3495 "\\&\n"
3496 " path[path_len] = \\[aq]\\[rs]0\\[aq];\n"
3497 " printf(\"File %s\\[rs]n\", path);\n"
3498 "\\&\n"
3499 " /* Close the file descriptor of the event. */\n"
3500 "\\&\n"
3501 " close(metadata-E<gt>fd);\n"
3502 " }\n"
3503 "\\&\n"
3504 " /* Advance to next event. */\n"
3505 "\\&\n"
3506 " metadata = FAN_EVENT_NEXT(metadata, size);\n"
3507 " }\n"
3508 " }\n"
3509 "}\n"
3510 "\\&\n"
3511 "int\n"
3512 "main(int argc, char *argv[])\n"
3513 "{\n"
3514 " char buf;\n"
3515 " int fd, poll_num;\n"
3516 " nfds_t nfds;\n"
3517 " struct pollfd fds[2];\n"
3518 "\\&\n"
3519 " /* Check mount point is supplied. */\n"
3520 "\\&\n"
3521 " if (argc != 2) {\n"
3522 " fprintf(stderr, \"Usage: %s MOUNT\\[rs]n\", argv[0]);\n"
3523 " exit(EXIT_FAILURE);\n"
3524 " }\n"
3525 "\\&\n"
3526 " printf(\"Press enter key to terminate.\\[rs]n\");\n"
3527 "\\&\n"
3528 " /* Create the file descriptor for accessing the fanotify API. */\n"
3529 "\\&\n"
3530 " fd = fanotify_init(FAN_CLOEXEC | FAN_CLASS_CONTENT | FAN_NONBLOCK,\n"
3531 " O_RDONLY | O_LARGEFILE);\n"
3532 " if (fd == -1) {\n"
3533 " perror(\"fanotify_init\");\n"
3534 " exit(EXIT_FAILURE);\n"
3535 " }\n"
3536 "\\&\n"
3537 " /* Mark the mount for:\n"
3538 " - permission events before opening files\n"
3539 " - notification events after closing a write-enabled\n"
3540 " file descriptor. */\n"
3541 "\\&\n"
3542 " if (fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT,\n"
3543 " FAN_OPEN_PERM | FAN_CLOSE_WRITE, AT_FDCWD,\n"
3544 " argv[1]) == -1) {\n"
3545 " perror(\"fanotify_mark\");\n"
3546 " exit(EXIT_FAILURE);\n"
3547 " }\n"
3548 "\\&\n"
3549 " /* Prepare for polling. */\n"
3550 "\\&\n"
3551 " nfds = 2;\n"
3552 "\\&\n"
3553 " fds[0].fd = STDIN_FILENO; /* Console input */\n"
3554 " fds[0].events = POLLIN;\n"
3555 "\\&\n"
3556 " fds[1].fd = fd; /* Fanotify input */\n"
3557 " fds[1].events = POLLIN;\n"
3558 "\\&\n"
3559 " /* This is the loop to wait for incoming events. */\n"
3560 "\\&\n"
3561 " printf(\"Listening for events.\\[rs]n\");\n"
3562 "\\&\n"
3563 " while (1) {\n"
3564 " poll_num = poll(fds, nfds, -1);\n"
3565 " if (poll_num == -1) {\n"
3566 " if (errno == EINTR) /* Interrupted by a signal */\n"
3567 " continue; /* Restart poll() */\n"
3568 "\\&\n"
3569 " perror(\"poll\"); /* Unexpected error */\n"
3570 " exit(EXIT_FAILURE);\n"
3571 " }\n"
3572 "\\&\n"
3573 " if (poll_num E<gt> 0) {\n"
3574 " if (fds[0].revents & POLLIN) {\n"
3575 "\\&\n"
3576 " /* Console input is available: empty stdin and quit. */\n"
3577 "\\&\n"
3578 " while (read(STDIN_FILENO, &buf, 1) E<gt> 0 && buf != \\[aq]\\[rs]n\\[aq])\n"
3579 " continue;\n"
3580 " break;\n"
3581 " }\n"
3582 "\\&\n"
3583 " if (fds[1].revents & POLLIN) {\n"
3584 "\\&\n"
3585 " /* Fanotify events are available. */\n"
3586 "\\&\n"
3587 " handle_events(fd);\n"
3588 " }\n"
3589 " }\n"
3590 " }\n"
3591 "\\&\n"
3592 " printf(\"Listening for events stopped.\\[rs]n\");\n"
3593 " exit(EXIT_SUCCESS);\n"
3594 "}\n"
3595 msgstr ""
3596
3597 #. type: TH
3598 #: opensuse-leap-16-1 opensuse-tumbleweed
3599 #, no-wrap
3600 msgid "Linux man-pages (unreleased)"
3601 msgstr ""