summaryrefslogtreecommitdiffstats
path: root/man7/inotify.7
diff options
context:
space:
mode:
Diffstat (limited to 'man7/inotify.7')
-rw-r--r--man7/inotify.7142
1 files changed, 72 insertions, 70 deletions
diff --git a/man7/inotify.7 b/man7/inotify.7
index bd3972f80..59bdb03b5 100644
--- a/man7/inotify.7
+++ b/man7/inotify.7
@@ -17,42 +17,42 @@ for the directory itself, and for files inside the directory.
.P
The following system calls are used with this API:
.IP \[bu] 3
-.BR inotify_init (2)
+.MR inotify_init 2
creates an inotify instance and returns a file descriptor
referring to the inotify instance.
The more recent
-.BR inotify_init1 (2)
+.MR inotify_init1 2
is like
-.BR inotify_init (2),
+.MR inotify_init 2 ,
but has a
.I flags
argument that provides access to some extra functionality.
.IP \[bu]
-.BR inotify_add_watch (2)
+.MR inotify_add_watch 2
manipulates the "watch list" associated with an inotify instance.
Each item ("watch") in the watch list specifies the pathname of
a file or directory,
along with some set of events that the kernel should monitor for the
file referred to by that pathname.
-.BR inotify_add_watch (2)
+.MR inotify_add_watch 2
either creates a new watch item, or modifies an existing watch.
Each watch has a unique "watch descriptor", an integer
returned by
-.BR inotify_add_watch (2)
+.MR inotify_add_watch 2
when the watch is created.
.IP \[bu]
When events occur for monitored files and directories,
those events are made available to the application as structured data that
can be read from the inotify file descriptor using
-.BR read (2)
+.MR read 2
(see below).
.IP \[bu]
-.BR inotify_rm_watch (2)
+.MR inotify_rm_watch 2
removes an item from an inotify watch list.
.IP \[bu]
When all file descriptors referring to an inotify
instance have been closed (using
-.BR close (2)),
+.MR close 2 ),
the underlying object and its resources are
freed for reuse by the kernel;
all associated watches are automatically freed.
@@ -67,20 +67,20 @@ It is probably wise to do some consistency checking,
and rebuild the cache when inconsistencies are detected.
.SS Reading events from an inotify file descriptor
To determine what events have occurred, an application
-.BR read (2)s
+.MR read 2 s
from the inotify file descriptor.
If no events have so far occurred, then,
assuming a blocking file descriptor,
-.BR read (2)
+.MR read 2
will block until at least one event occurs
(unless interrupted by a signal,
in which case the call fails with the error
.BR EINTR ;
see
-.BR signal (7)).
+.MR signal 7 ).
.P
Each successful
-.BR read (2)
+.MR read 2
returns a buffer containing one or more of the following structures:
.P
.in +4n
@@ -103,7 +103,7 @@ struct inotify_event {
.I wd
identifies the watch for which this event occurs.
It is one of the watch descriptors returned by a previous call to
-.BR inotify_add_watch (2).
+.MR inotify_add_watch 2 .
.P
.I mask
contains bits that describe the event that occurred (see below).
@@ -140,12 +140,12 @@ structure is thus
.IR "sizeof(struct inotify_event)+len" .
.P
The behavior when the buffer given to
-.BR read (2)
+.MR read 2
is too small to return information about the next event depends
on the kernel version: before Linux 2.6.21,
-.BR read (2)
+.MR read 2
returns 0; since Linux 2.6.21,
-.BR read (2)
+.MR read 2
fails with the error
.BR EINVAL .
Specifying a buffer of size
@@ -159,49 +159,50 @@ sizeof(struct inotify_event) + NAME_MAX + 1
will be sufficient to read at least one event.
.SS inotify events
The
-.BR inotify_add_watch (2)
+.MR inotify_add_watch 2
.I mask
argument and the
.I mask
field of the
.I inotify_event
structure returned when
-.BR read (2)ing
+.MR read 2 ing
an inotify file descriptor are both bit masks identifying
inotify events.
The following bits can be specified in
.I mask
when calling
-.BR inotify_add_watch (2)
+.MR inotify_add_watch 2
and may be returned in the
.I mask
field returned by
-.BR read (2):
+.MR read 2 :
.RS 4
.TP
.BR IN_ACCESS " (+)"
File was accessed (e.g.,
-.BR read (2),
-.BR execve (2)).
+.MR read 2 ,
+.MR execve 2 ).
.TP
.BR IN_ATTRIB " (*)"
Metadata changed\[em]for example, permissions (e.g.,
-.BR chmod (2)),
+.MR chmod 2 ),
timestamps (e.g.,
-.BR utimensat (2)),
+.MR utimensat 2 ),
extended attributes
-.RB ( setxattr (2)),
+\%(\c
+.MR setxattr 2 ),
link count (since Linux 2.6.25; e.g.,
.\" FIXME .
.\" Events do not occur for link count changes on a file inside a monitored
.\" directory. This differs from other metadata changes for files inside
.\" a monitored directory.
for the target of
-.BR link (2)
+.MR link 2
and for
-.BR unlink (2)),
+.MR unlink 2 ),
and user/group ID (e.g.,
-.BR chown (2)).
+.MR chown 2 ).
.TP
.BR IN_CLOSE_WRITE " (+)"
File opened for writing was closed.
@@ -211,12 +212,12 @@ File or directory not opened for writing was closed.
.TP
.BR IN_CREATE " (+)"
File/directory created in watched directory (e.g.,
-.BR open (2)
+.MR open 2
.BR O_CREAT ,
-.BR mkdir (2),
-.BR link (2),
-.BR symlink (2),
-.BR bind (2)
+.MR mkdir 2 ,
+.MR link 2 ,
+.MR symlink 2 ,
+.MR bind 2
on a UNIX domain socket).
.TP
.BR IN_DELETE " (+)"
@@ -226,7 +227,7 @@ File/directory deleted from watched directory.
Watched file/directory was itself deleted.
(This event also occurs if an object is moved to another filesystem,
since
-.BR mv (1)
+.MR mv 1
in effect copies the file to the other filesystem and
then deletes it from the original filesystem.)
In addition, an
@@ -235,8 +236,8 @@ event will subsequently be generated for the watch descriptor.
.TP
.BR IN_MODIFY " (+)"
File was modified (e.g.,
-.BR write (2),
-.BR truncate (2)).
+.MR write 2 ,
+.MR truncate 2 ).
.TP
.B IN_MOVE_SELF
Watched file/directory was itself moved.
@@ -284,7 +285,7 @@ macro is defined as a bit mask of all of the above events.
This macro can be used as the
.I mask
argument when calling
-.BR inotify_add_watch (2).
+.MR inotify_add_watch 2 .
.P
Two additional convenience macros are defined:
.RS 4
@@ -301,7 +302,7 @@ Equates to
The following further bits can be specified in
.I mask
when calling
-.BR inotify_add_watch (2):
+.MR inotify_add_watch 2 :
.RS 4
.TP
.BR IN_DONT_FOLLOW " (since Linux 2.6.15)"
@@ -369,19 +370,20 @@ Using this flag provides an application with a way of ensuring
that new watches do not modify existing ones.
This is useful because multiple paths may refer to the same inode,
and multiple calls to
-.BR inotify_add_watch (2)
+.MR inotify_add_watch 2
without this flag may clobber existing watch masks.
.RE
.P
The following bits may be set in the
.I mask
field returned by
-.BR read (2):
+.MR read 2 :
.RS 4
.TP
.B IN_IGNORED
Watch was removed explicitly
-.RB ( inotify_rm_watch (2))
+\%(\c
+.MR inotify_rm_watch 2 )
or automatically (file was deleted, or filesystem was unmounted).
See also BUGS.
.TP
@@ -561,7 +563,7 @@ kernel memory consumed by inotify:
.TP
.I /proc/sys/fs/inotify/max_queued_events
The value in this file is used when an application calls
-.BR inotify_init (2)
+.MR inotify_init 2
to set an upper limit on the number of events that can be
queued to the corresponding inotify instance.
Events in excess of this limit are dropped, but an
@@ -587,10 +589,10 @@ and
were added in glibc 2.5.)
.SH NOTES
Inotify file descriptors can be monitored using
-.BR select (2),
-.BR poll (2),
+.MR select 2 ,
+.MR poll 2 ,
and
-.BR epoll (7).
+.MR epoll 7 .
When an event is available, the file descriptor indicates as readable.
.P
Since Linux 2.6.25,
@@ -604,11 +606,11 @@ flag),
and
.B F_SETSIG
in
-.BR fcntl (2).
+.MR fcntl 2 .
The
.I siginfo_t
structure (described in
-.BR sigaction (2))
+.MR sigaction 2 )
that is passed to the signal handler has the following fields set:
.I si_fd
is set to the inotify file descriptor number;
@@ -647,11 +649,11 @@ the inotify file descriptor in the process's
.IR /proc/ pid /fdinfo
directory.
See
-.BR proc (5)
+.MR proc 5
for further details.
The
.B FIONREAD
-.BR ioctl (2)
+.MR ioctl 2
returns the number of bytes available to read from an
inotify file descriptor.
.SS Limitations and caveats
@@ -677,10 +679,10 @@ are not monitorable with inotify.
.P
The inotify API does not report file accesses and modifications that
may occur because of
-.BR mmap (2),
-.BR msync (2),
+.MR mmap 2 ,
+.MR msync 2 ,
and
-.BR munmap (2).
+.MR munmap 2 .
.P
The inotify API identifies affected files by filename.
However, by the time an application processes an inotify event,
@@ -730,7 +732,7 @@ As noted above, the
and
.B IN_MOVED_TO
event pair that is generated by
-.BR rename (2)
+.MR rename 2
can be matched up via their shared cookie value.
However, the task of matching has some challenges.
.P
@@ -756,7 +758,7 @@ Matching up the
and
.B IN_MOVED_TO
event pair generated by
-.BR rename (2)
+.MR rename 2
is thus inherently racy.
(Don't forget that if an object is renamed outside of a monitored directory,
there may not even be an
@@ -780,11 +782,11 @@ Applications should also allow for the possibility that the
.B IN_MOVED_FROM
event was the last event that could fit in the buffer
returned by the current call to
-.BR read (2),
+.MR read 2 ,
and the accompanying
.B IN_MOVED_TO
event might be fetched only on the next
-.BR read (2),
+.MR read 2 ,
which should be done with a (small) timeout to allow for the fact that
insertion of the
.BR IN_MOVED_FROM + IN_MOVED_TO
@@ -794,12 +796,12 @@ and also the possibility that there may not be any
event.
.SH BUGS
Before Linux 3.19,
-.BR fallocate (2)
+.MR fallocate 2
did not create any inotify events.
Since Linux 3.19,
.\" commit 820c12d5d6c0890bc93dd63893924a13041fdc35
calls to
-.BR fallocate (2)
+.MR fallocate 2
generate
.B IN_MODIFY
events.
@@ -832,12 +834,12 @@ instead checked if the most recent event could be coalesced with the
unread event.
.P
When a watch descriptor is removed by calling
-.BR inotify_rm_watch (2)
+.MR inotify_rm_watch 2
(or because a watch file is deleted or the filesystem
that contains it is unmounted),
any pending unread events for that watch descriptor remain available to read.
As watch descriptors are subsequently allocated with
-.BR inotify_add_watch (2),
+.MR inotify_add_watch 2 ,
the kernel cycles through the range of possible watch descriptors (1 to
.BR INT_MAX )
incrementally.
@@ -1086,15 +1088,15 @@ main(int argc, char* argv[])
}
.EE
.SH SEE ALSO
-.BR inotifywait (1),
-.BR inotifywatch (1),
-.BR inotify_add_watch (2),
-.BR inotify_init (2),
-.BR inotify_init1 (2),
-.BR inotify_rm_watch (2),
-.BR read (2),
-.BR stat (2),
-.BR fanotify (7)
+.MR inotifywait 1 ,
+.MR inotifywatch 1 ,
+.MR inotify_add_watch 2 ,
+.MR inotify_init 2 ,
+.MR inotify_init1 2 ,
+.MR inotify_rm_watch 2 ,
+.MR read 2 ,
+.MR stat 2 ,
+.MR fanotify 7
.P
.I Documentation/filesystems/inotify.txt
in the Linux kernel source tree