Start of man-pages-5.14: updating Changes and Changes.old
[man-pages.git] / man2 / inotify_add_watch.2
blobbea4f1b2cf17e4724daa4cfde43021e4c25c953d
1 .\" Copyright (C) 2005 Robert Love
2 .\" and Copyright, 2006 Michael Kerrisk
3 .\"
4 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
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
21 .\" License along with this manual; if not, see
22 .\" <http://www.gnu.org/licenses/>.
23 .\" %%%LICENSE_END
24 .\"
25 .\" 2005-07-19 Robert Love <rlove@rlove.org> - initial version
26 .\" 2006-02-07 mtk, various changes
27 .\"
28 .TH INOTIFY_ADD_WATCH 2 2021-03-22 "Linux" "Linux Programmer's Manual"
29 .SH NAME
30 inotify_add_watch \- add a watch to an initialized inotify instance
31 .SH SYNOPSIS
32 .nf
33 .B #include <sys/inotify.h>
34 .PP
35 .BI "int inotify_add_watch(int " fd ", const char *" pathname ", uint32_t " mask );
36 .fi
37 .SH DESCRIPTION
38 .BR inotify_add_watch ()
39 adds a new watch, or modifies an existing watch,
40 for the file whose location is specified in
41 .IR pathname ;
42 the caller must have read permission for this file.
43 The
44 .I fd
45 argument is a file descriptor referring to the
46 inotify instance whose watch list is to be modified.
47 The events to be monitored for
48 .I pathname
49 are specified in the
50 .I mask
51 bit-mask argument.
52 See
53 .BR inotify (7)
54 for a description of the bits that can be set in
55 .IR mask .
56 .PP
57 A successful call to
58 .BR inotify_add_watch ()
59 returns a unique watch descriptor for this inotify instance,
60 for the filesystem object (inode) that corresponds to
61 .IR pathname .
62 If the filesystem object
63 was not previously being watched by this inotify instance,
64 then the watch descriptor is newly allocated.
65 If the filesystem object was already being watched
66 (perhaps via a different link to the same object), then the descriptor
67 for the existing watch is returned.
68 .PP
69 The watch descriptor is returned by later
70 .BR read (2)s
71 from the inotify file descriptor.
72 These reads fetch
73 .I inotify_event
74 structures (see
75 .BR inotify (7))
76 indicating filesystem events;
77 the watch descriptor inside this structure identifies
78 the object for which the event occurred.
79 .SH RETURN VALUE
80 On success,
81 .BR inotify_add_watch ()
82 returns a watch descriptor (a nonnegative integer).
83 On error, \-1 is returned and
84 .I errno
85 is set to indicate the error.
86 .SH ERRORS
87 .TP
88 .B EACCES
89 Read access to the given file is not permitted.
90 .TP
91 .B EBADF
92 The given file descriptor is not valid.
93 .TP
94 .B EEXIST
95 .I mask
96 contains
97 .B IN_MASK_CREATE
98 and
99 .I pathname
100 refers to a file already being watched by the same
101 .IR fd .
103 .B EFAULT
104 .I pathname
105 points outside of the process's accessible address space.
107 .B EINVAL
108 The given event mask contains no valid events; or
109 .I mask
110 contains both
111 .B IN_MASK_ADD
113 .BR IN_MASK_CREATE ;
115 .I fd
116 is not an inotify file descriptor.
118 .B ENAMETOOLONG
119 .I pathname
120 is too long.
122 .B ENOENT
123 A directory component in
124 .I pathname
125 does not exist or is a dangling symbolic link.
127 .B ENOMEM
128 Insufficient kernel memory was available.
130 .B ENOSPC
131 The user limit on the total number of inotify watches was reached or the
132 kernel failed to allocate a needed resource.
134 .B ENOTDIR
135 .I mask
136 contains
137 .B IN_ONLYDIR
139 .I pathname
140 is not a directory.
141 .SH VERSIONS
142 Inotify was merged into the 2.6.13 Linux kernel.
143 .SH CONFORMING TO
144 This system call is Linux-specific.
145 .SH EXAMPLES
147 .BR inotify (7).
148 .SH SEE ALSO
149 .BR inotify_init (2),
150 .BR inotify_rm_watch (2),
151 .BR inotify (7)