OSDN Git Service

07992787a3a3606be65073beeb133713f1f4dc23
[linuxjm/LDP_man-pages.git] / original / man2 / inotify_add_watch.2
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 2014-03-28 "Linux" "Linux Programmer's Manual"
29 .SH NAME
30 inotify_add_watch \- add a watch to an initialized inotify instance
31 .SH SYNOPSIS
32 .B #include <sys/inotify.h>
33 .sp
34 .BI "int inotify_add_watch(int " fd ", const char *" pathname ", uint32_t " mask );
35 .SH DESCRIPTION
36 .BR inotify_add_watch ()
37 adds a new watch, or modifies an existing watch,
38 for the file whose location is specified in
39 .IR pathname ;
40 the caller must have read permission for this file.
41 The
42 .I fd
43 argument is a file descriptor referring to the
44 inotify instance whose watch list is to be modified.
45 The events to be monitored for
46 .I pathname
47 are specified in the
48 .I mask
49 bit-mask argument.
50 See
51 .BR inotify (7)
52 for a description of the bits that can be set in
53 .IR mask .
54
55 A successful call to
56 .BR inotify_add_watch ()
57 returns the unique watch descriptor associated with
58 .I pathname
59 for this inotify instance.
60 If
61 .I pathname
62 was not previously being watched by this inotify instance,
63 then the watch descriptor is newly allocated.
64 If
65 .I pathname
66 was already being watched, then the descriptor
67 for the existing watch is returned.
68
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 nonnegative watch descriptor.
83 On error, \-1 is returned and
84 .I errno
85 is set appropriately.
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 EFAULT
95 .I pathname
96 points outside of the process's accessible address space.
97 .TP
98 .B EINVAL
99 The given event mask contains no valid events; or
100 .I fd
101 is not an inotify file descriptor.
102 .TP
103 .B ENAMETOOLONG
104 .I pathname
105 is too long.
106 .TP
107 .B ENOENT
108 A directory component in
109 .I pathname
110 does not exist or is a dangling symbolic link.
111 .TP
112 .B ENOMEM
113 Insufficient kernel memory was available.
114 .TP
115 .B ENOSPC
116 The user limit on the total number of inotify watches was reached or the
117 kernel failed to allocate a needed resource.
118 .SH VERSIONS
119 Inotify was merged into the 2.6.13 Linux kernel.
120 .SH CONFORMING TO
121 This system call is Linux-specific.
122 .SH SEE ALSO
123 .BR inotify_init (2),
124 .BR inotify_rm_watch (2),
125 .BR inotify (7)
126 .SH COLOPHON
127 This page is part of release 3.67 of the Linux
128 .I man-pages
129 project.
130 A description of the project,
131 information about reporting bugs,
132 and the latest version of this page,
133 can be found at
134 \%http://www.kernel.org/doc/man\-pages/.