]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/inotify_add_watch.2
dlopen.3: tfix
[thirdparty/man-pages.git] / man2 / inotify_add_watch.2
CommitLineData
efa25b17
MK
1.\" Copyright (C) 2005 Robert Love
2.\" and Copyright, 2006 Michael Kerrisk
4d2b74dd 3.\"
1dd72f9c 4.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4d2b74dd
MK
5.\" This is free documentation; you can redistribute it and/or
6.\" modify it under the terms of the GNU General Public License as
7.\" published by the Free Software Foundation; either version 2 of
8.\" the License, or (at your option) any later version.
9.\"
10.\" The GNU General Public License's references to "object code"
11.\" and "executables" are to be interpreted as the output of any
12.\" document formatting or typesetting system, including
13.\" intermediate and printed output.
14.\"
15.\" This manual is distributed in the hope that it will be useful,
16.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18.\" GNU General Public License for more details.
19.\"
20.\" You should have received a copy of the GNU General Public
c715f741
MK
21.\" License along with this manual; if not, see
22.\" <http://www.gnu.org/licenses/>.
6a8d8745 23.\" %%%LICENSE_END
4d2b74dd
MK
24.\"
25.\" 2005-07-19 Robert Love <rlove@rlove.org> - initial version
26.\" 2006-02-07 mtk, various changes
27.\"
e8426ca2 28.TH INOTIFY_ADD_WATCH 2 2020-04-11 "Linux" "Linux Programmer's Manual"
4d2b74dd
MK
29.SH NAME
30inotify_add_watch \- add a watch to an initialized inotify instance
31.SH SYNOPSIS
6e969f22 32.B #include <sys/inotify.h>
68e4db0a 33.PP
93440c02 34.BI "int inotify_add_watch(int " fd ", const char *" pathname ", uint32_t " mask );
4d2b74dd
MK
35.SH DESCRIPTION
36.BR inotify_add_watch ()
c13182ef 37adds a new watch, or modifies an existing watch,
dd28cb72
MK
38for the file whose location is specified in
39.IR pathname ;
40the caller must have read permission for this file.
c13182ef 41The
4d2b74dd 42.I fd
dd28cb72
MK
43argument is a file descriptor referring to the
44inotify instance whose watch list is to be modified.
45The events to be monitored for
46.I pathname
47are specified in the
48.I mask
49bit-mask argument.
4d2b74dd
MK
50See
51.BR inotify (7)
52for a description of the bits that can be set in
53.IR mask .
efeece04 54.PP
4d2b74dd
MK
55A successful call to
56.BR inotify_add_watch ()
7499e6bc 57returns a unique watch descriptor for this inotify instance,
30e2a22a 58for the filesystem object (inode) that corresponds to
7499e6bc
MK
59.IR pathname .
60If the filesystem object
4d2b74dd 61was not previously being watched by this inotify instance,
c13182ef 62then the watch descriptor is newly allocated.
7499e6bc
MK
63If the filesystem object was already being watched
64(perhaps via a different link to the same object), then the descriptor
4d2b74dd 65for the existing watch is returned.
efeece04 66.PP
4d2b74dd
MK
67The watch descriptor is returned by later
68.BR read (2)s
c13182ef 69from the inotify file descriptor.
4d2b74dd
MK
70These reads fetch
71.I inotify_event
325f18da
MK
72structures (see
73.BR inotify (7))
9ee4a2b6 74indicating filesystem events;
325f18da 75the watch descriptor inside this structure identifies
4d2b74dd 76the object for which the event occurred.
47297adb 77.SH RETURN VALUE
4d2b74dd
MK
78On success,
79.BR inotify_add_watch ()
ed09120a 80returns a watch descriptor (a nonnegative integer).
dec985f9 81On error, \-1 is returned and
4d2b74dd
MK
82.I errno
83is set appropriately.
84.SH ERRORS
85.TP
1b3fc756 86.B EACCES
4d2b74dd
MK
87Read access to the given file is not permitted.
88.TP
89.B EBADF
90The given file descriptor is not valid.
91.TP
49a2a105
MK
92.B EEXIST
93.I mask
94contains
95.B IN_MASK_CREATE
96and
97.I pathname
98refers to a file already being watched by the same
99.IR fd .
100.TP
4d2b74dd 101.B EFAULT
93440c02 102.I pathname
4d2b74dd
MK
103points outside of the process's accessible address space.
104.TP
105.B EINVAL
e935e108 106The given event mask contains no valid events; or
4e821a8a
HW
107.I mask
108contains both
109.B IN_MASK_ADD
110and
6f202877
MK
111.BR IN_MASK_CREATE ;
112or
9f5774a9
MK
113.I fd
114is not an inotify file descriptor.
4d2b74dd 115.TP
d54837e8
MK
116.B ENAMETOOLONG
117.I pathname
118is too long.
119.TP
6a03b9dd
MK
120.B ENOENT
121A directory component in
122.I pathname
123does not exist or is a dangling symbolic link.
124.TP
4d2b74dd
MK
125.B ENOMEM
126Insufficient kernel memory was available.
127.TP
128.B ENOSPC
129The user limit on the total number of inotify watches was reached or the
130kernel failed to allocate a needed resource.
12507e51
PM
131.TP
132.B ENOTDIR
133.I mask
134contains
135.B IN_ONLYDIR
136and
137.I pathname
138is not a directory.
ff457ccb 139.SH VERSIONS
4d2b74dd 140Inotify was merged into the 2.6.13 Linux kernel.
47297adb 141.SH CONFORMING TO
8382f16d 142This system call is Linux-specific.
232057c3
MK
143.SH EXAMPLE
144See
145.BR inotify (7).
47297adb 146.SH SEE ALSO
4d2b74dd 147.BR inotify_init (2),
c13182ef 148.BR inotify_rm_watch (2),
ccd2b351 149.BR inotify (7)