Blame man2/fanotify_init.2

Packit 7cfc04
.\" Copyright (C) 2013, Heinrich Schuchardt <xypron.glpk@gmx.de>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of
Packit 7cfc04
.\" this manual under the conditions for verbatim copying, provided that
Packit 7cfc04
.\" the entire resulting derived work is distributed under the terms of
Packit 7cfc04
.\" a permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume.
Packit 7cfc04
.\" no responsibility for errors or omissions, or for damages resulting.
Packit 7cfc04
.\" from the use of the information contained herein.  The author(s) may.
Packit 7cfc04
.\" not have taken the same level of care in the production of this.
Packit 7cfc04
.\" manual, which is licensed free of charge, as they might when working.
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.TH FANOTIFY_INIT 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
fanotify_init \- create and initialize fanotify group
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.B #include <fcntl.h>
Packit 7cfc04
.br
Packit 7cfc04
.B #include <sys/fanotify.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int fanotify_init(unsigned int " flags ", unsigned int " event_f_flags );
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
For an overview of the fanotify API, see
Packit 7cfc04
.BR fanotify (7).
Packit 7cfc04
.PP
Packit 7cfc04
.BR fanotify_init ()
Packit 7cfc04
initializes a new fanotify group and returns a file descriptor for the event
Packit 7cfc04
queue associated with the group.
Packit 7cfc04
.PP
Packit 7cfc04
The file descriptor is used in calls to
Packit 7cfc04
.BR fanotify_mark (2)
Packit 7cfc04
to specify the files, directories, and mounts for which fanotify events
Packit 7cfc04
shall be created.
Packit 7cfc04
These events are received by reading from the file descriptor.
Packit 7cfc04
Some events are only informative, indicating that a file has been accessed.
Packit 7cfc04
Other events can be used to determine whether
Packit 7cfc04
another application is permitted to access a file or directory.
Packit 7cfc04
Permission to access filesystem objects is granted by writing to the file
Packit 7cfc04
descriptor.
Packit 7cfc04
.PP
Packit 7cfc04
Multiple programs may be using the fanotify interface at the same time to
Packit 7cfc04
monitor the same files.
Packit 7cfc04
.PP
Packit 7cfc04
In the current implementation, the number of fanotify groups per user is
Packit 7cfc04
limited to 128.
Packit 7cfc04
This limit cannot be overridden.
Packit 7cfc04
.PP
Packit 7cfc04
Calling
Packit 7cfc04
.BR fanotify_init ()
Packit 7cfc04
requires the
Packit 7cfc04
.B CAP_SYS_ADMIN
Packit 7cfc04
capability.
Packit 7cfc04
This constraint might be relaxed in future versions of the API.
Packit 7cfc04
Therefore, certain additional capability checks have been implemented as
Packit 7cfc04
indicated below.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I flags
Packit 7cfc04
argument contains a multi-bit field defining the notification class of the
Packit 7cfc04
listening application and further single bit fields specifying the behavior
Packit 7cfc04
of the file descriptor.
Packit 7cfc04
.PP
Packit 7cfc04
If multiple listeners for permission events exist,
Packit 7cfc04
the notification class is used to establish the sequence
Packit 7cfc04
in which the listeners receive the events.
Packit 7cfc04
.PP
Packit 7cfc04
Only one of the following notification classes may be specified in
Packit 7cfc04
.IR flags :
Packit 7cfc04
.TP
Packit 7cfc04
.B FAN_CLASS_PRE_CONTENT
Packit 7cfc04
This value allows the receipt of events notifying that a file has been
Packit 7cfc04
accessed and events for permission decisions if a file may be accessed.
Packit 7cfc04
It is intended for event listeners that need to access files before they
Packit 7cfc04
contain their final data.
Packit 7cfc04
This notification class might be used by hierarchical storage managers,
Packit 7cfc04
for example.
Packit 7cfc04
.TP
Packit 7cfc04
.B FAN_CLASS_CONTENT
Packit 7cfc04
This value allows the receipt of events notifying that a file has been
Packit 7cfc04
accessed and events for permission decisions if a file may be accessed.
Packit 7cfc04
It is intended for event listeners that need to access files when they
Packit 7cfc04
already contain their final content.
Packit 7cfc04
This notification class might be used by malware detection programs, for
Packit 7cfc04
example.
Packit 7cfc04
.TP
Packit 7cfc04
.B FAN_CLASS_NOTIF
Packit 7cfc04
This is the default value.
Packit 7cfc04
It does not need to be specified.
Packit 7cfc04
This value only allows the receipt of events notifying that a file has been
Packit 7cfc04
accessed.
Packit 7cfc04
Permission decisions before the file is accessed are not possible.
Packit 7cfc04
.PP
Packit 7cfc04
Listeners with different notification classes will receive events in the
Packit 7cfc04
order
Packit 7cfc04
.BR FAN_CLASS_PRE_CONTENT ,
Packit 7cfc04
.BR FAN_CLASS_CONTENT ,
Packit 7cfc04
.BR FAN_CLASS_NOTIF .
Packit 7cfc04
The order of notification for listeners in the same notification class
Packit 7cfc04
is undefined.
Packit 7cfc04
.PP
Packit 7cfc04
The following bits can additionally be set in
Packit 7cfc04
.IR flags :
Packit 7cfc04
.TP
Packit 7cfc04
.B FAN_CLOEXEC
Packit 7cfc04
Set the close-on-exec flag
Packit 7cfc04
.RB ( FD_CLOEXEC )
Packit 7cfc04
on the new file descriptor.
Packit 7cfc04
See the description of the
Packit 7cfc04
.B O_CLOEXEC
Packit 7cfc04
flag in
Packit 7cfc04
.BR open (2).
Packit 7cfc04
.TP
Packit 7cfc04
.B FAN_NONBLOCK
Packit 7cfc04
Enable the nonblocking flag
Packit 7cfc04
.RB ( O_NONBLOCK )
Packit 7cfc04
for the file descriptor.
Packit 7cfc04
Reading from the file descriptor will not block.
Packit 7cfc04
Instead, if no data is available,
Packit 7cfc04
.BR read (2)
Packit 7cfc04
fails with the error
Packit 7cfc04
.BR EAGAIN .
Packit 7cfc04
.TP
Packit 7cfc04
.B FAN_UNLIMITED_QUEUE
Packit 7cfc04
Remove the limit of 16384 events for the event queue.
Packit 7cfc04
Use of this flag requires the
Packit 7cfc04
.B CAP_SYS_ADMIN
Packit 7cfc04
capability.
Packit 7cfc04
.TP
Packit 7cfc04
.B FAN_UNLIMITED_MARKS
Packit 7cfc04
Remove the limit of 8192 marks.
Packit 7cfc04
Use of this flag requires the
Packit 7cfc04
.B CAP_SYS_ADMIN
Packit 7cfc04
capability.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I event_f_flags
Packit 7cfc04
argument
Packit 7cfc04
defines the file status flags that will be set on the open file descriptions
Packit 7cfc04
that are created for fanotify events.
Packit 7cfc04
For details of these flags, see the description of the
Packit 7cfc04
.I flags
Packit 7cfc04
values in
Packit 7cfc04
.BR open (2).
Packit 7cfc04
.I event_f_flags
Packit 7cfc04
includes a multi-bit field for the access mode.
Packit 7cfc04
This field can take the following values:
Packit 7cfc04
.TP
Packit 7cfc04
.B O_RDONLY
Packit 7cfc04
This value allows only read access.
Packit 7cfc04
.TP
Packit 7cfc04
.B O_WRONLY
Packit 7cfc04
This value allows only write access.
Packit 7cfc04
.TP
Packit 7cfc04
.B O_RDWR
Packit 7cfc04
This value allows read and write access.
Packit 7cfc04
.PP
Packit 7cfc04
Additional bits can be set in
Packit 7cfc04
.IR event_f_flags .
Packit 7cfc04
The most useful values are:
Packit 7cfc04
.TP
Packit 7cfc04
.B O_LARGEFILE
Packit 7cfc04
Enable support for files exceeding 2\ GB.
Packit 7cfc04
Failing to set this flag will result in an
Packit 7cfc04
.B EOVERFLOW
Packit 7cfc04
error when trying to open a large file which is monitored by
Packit 7cfc04
an fanotify group on a 32-bit system.
Packit 7cfc04
.TP
Packit 7cfc04
.BR O_CLOEXEC " (since Linux 3.18)"
Packit 7cfc04
.\" commit 0b37e097a648aa71d4db1ad108001e95b69a2da4
Packit 7cfc04
Enable the close-on-exec flag for the file descriptor.
Packit 7cfc04
See the description of the
Packit 7cfc04
.B O_CLOEXEC
Packit 7cfc04
flag in
Packit 7cfc04
.BR open (2)
Packit 7cfc04
for reasons why this may be useful.
Packit 7cfc04
.PP
Packit 7cfc04
The following are also allowable:
Packit 7cfc04
.BR O_APPEND ,
Packit 7cfc04
.BR O_DSYNC ,
Packit 7cfc04
.BR O_NOATIME ,
Packit 7cfc04
.BR O_NONBLOCK ,
Packit 7cfc04
and
Packit 7cfc04
.BR O_SYNC .
Packit 7cfc04
Specifying any other flag in
Packit 7cfc04
.I event_f_flags
Packit 7cfc04
yields the error
Packit 7cfc04
.B EINVAL
Packit 7cfc04
(but see BUGS).
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success,
Packit 7cfc04
.BR fanotify_init ()
Packit 7cfc04
returns a new file descriptor.
Packit 7cfc04
On error, \-1 is returned, and
Packit 7cfc04
.I errno
Packit 7cfc04
is set to indicate the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
An invalid value was passed in
Packit 7cfc04
.I flags
Packit 7cfc04
or
Packit 7cfc04
.IR event_f_flags .
Packit 7cfc04
.B FAN_ALL_INIT_FLAGS
Packit 7cfc04
defines all allowable bits for
Packit 7cfc04
.IR flags .
Packit 7cfc04
.TP
Packit 7cfc04
.B EMFILE
Packit 7cfc04
The number of fanotify groups for this user exceeds 128.
Packit 7cfc04
.TP
Packit 7cfc04
.B EMFILE
Packit 7cfc04
The per-process limit on the number of open file descriptors has been reached.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOMEM
Packit 7cfc04
The allocation of memory for the notification group failed.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOSYS
Packit 7cfc04
This kernel does not implement
Packit 7cfc04
.BR fanotify_init ().
Packit 7cfc04
The fanotify API is available only if the kernel was configured with
Packit 7cfc04
.BR CONFIG_FANOTIFY .
Packit 7cfc04
.TP
Packit 7cfc04
.B EPERM
Packit 7cfc04
The operation is not permitted because the caller lacks the
Packit 7cfc04
.B CAP_SYS_ADMIN
Packit 7cfc04
capability.
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
.BR fanotify_init ()
Packit 7cfc04
was introduced in version 2.6.36 of the Linux kernel and enabled in version
Packit 7cfc04
2.6.37.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
This system call is Linux-specific.
Packit 7cfc04
.SH BUGS
Packit 7cfc04
The following bug was present in Linux kernels before version 3.18:
Packit 7cfc04
.IP * 3
Packit 7cfc04
.\" Fixed by commit 0b37e097a648aa71d4db1ad108001e95b69a2da4
Packit 7cfc04
The
Packit 7cfc04
.B O_CLOEXEC
Packit 7cfc04
is ignored when passed in
Packit 7cfc04
.IR event_f_flags .
Packit 7cfc04
.PP
Packit 7cfc04
The following bug was present in Linux kernels before version 3.14:
Packit 7cfc04
.IP * 3
Packit 7cfc04
.\" Fixed by commit 48149e9d3a7e924010a0daab30a6197b7d7b6580
Packit 7cfc04
The
Packit 7cfc04
.I event_f_flags
Packit 7cfc04
argument is not checked for invalid flags.
Packit 7cfc04
Flags that are intended only for internal use,
Packit 7cfc04
such as
Packit 7cfc04
.BR FMODE_EXEC ,
Packit 7cfc04
can be set, and will consequently be set for the file descriptors
Packit 7cfc04
returned when reading from the fanotify file descriptor.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR fanotify_mark (2),
Packit 7cfc04
.BR fanotify (7)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.