]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/inotify_add_watch.2
dist.mk, All pages: .TH: Generate date at 'make dist'
[thirdparty/man-pages.git] / man2 / inotify_add_watch.2
1 .\" Copyright (C) 2005 Robert Love
2 .\" and Copyright, 2006 Michael Kerrisk
3 .\"
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
5 .\"
6 .\" 2005-07-19 Robert Love <rlove@rlove.org> - initial version
7 .\" 2006-02-07 mtk, various changes
8 .\"
9 .TH INOTIFY_ADD_WATCH 2 (date) "Linux man-pages (unreleased)"
10 .SH NAME
11 inotify_add_watch \- add a watch to an initialized inotify instance
12 .SH LIBRARY
13 Standard C library
14 .RI ( libc ", " \-lc )
15 .SH SYNOPSIS
16 .nf
17 .B #include <sys/inotify.h>
18 .PP
19 .BI "int inotify_add_watch(int " fd ", const char *" pathname ", uint32_t " mask );
20 .fi
21 .SH DESCRIPTION
22 .BR inotify_add_watch ()
23 adds a new watch, or modifies an existing watch,
24 for the file whose location is specified in
25 .IR pathname ;
26 the caller must have read permission for this file.
27 The
28 .I fd
29 argument is a file descriptor referring to the
30 inotify instance whose watch list is to be modified.
31 The events to be monitored for
32 .I pathname
33 are specified in the
34 .I mask
35 bit-mask argument.
36 See
37 .BR inotify (7)
38 for a description of the bits that can be set in
39 .IR mask .
40 .PP
41 A successful call to
42 .BR inotify_add_watch ()
43 returns a unique watch descriptor for this inotify instance,
44 for the filesystem object (inode) that corresponds to
45 .IR pathname .
46 If the filesystem object
47 was not previously being watched by this inotify instance,
48 then the watch descriptor is newly allocated.
49 If the filesystem object was already being watched
50 (perhaps via a different link to the same object), then the descriptor
51 for the existing watch is returned.
52 .PP
53 The watch descriptor is returned by later
54 .BR read (2)s
55 from the inotify file descriptor.
56 These reads fetch
57 .I inotify_event
58 structures (see
59 .BR inotify (7))
60 indicating filesystem events;
61 the watch descriptor inside this structure identifies
62 the object for which the event occurred.
63 .SH RETURN VALUE
64 On success,
65 .BR inotify_add_watch ()
66 returns a watch descriptor (a nonnegative integer).
67 On error, \-1 is returned and
68 .I errno
69 is set to indicate the error.
70 .SH ERRORS
71 .TP
72 .B EACCES
73 Read access to the given file is not permitted.
74 .TP
75 .B EBADF
76 The given file descriptor is not valid.
77 .TP
78 .B EEXIST
79 .I mask
80 contains
81 .B IN_MASK_CREATE
82 and
83 .I pathname
84 refers to a file already being watched by the same
85 .IR fd .
86 .TP
87 .B EFAULT
88 .I pathname
89 points outside of the process's accessible address space.
90 .TP
91 .B EINVAL
92 The given event mask contains no valid events; or
93 .I mask
94 contains both
95 .B IN_MASK_ADD
96 and
97 .BR IN_MASK_CREATE ;
98 or
99 .I fd
100 is not an inotify file descriptor.
101 .TP
102 .B ENAMETOOLONG
103 .I pathname
104 is too long.
105 .TP
106 .B ENOENT
107 A directory component in
108 .I pathname
109 does not exist or is a dangling symbolic link.
110 .TP
111 .B ENOMEM
112 Insufficient kernel memory was available.
113 .TP
114 .B ENOSPC
115 The user limit on the total number of inotify watches was reached or the
116 kernel failed to allocate a needed resource.
117 .TP
118 .B ENOTDIR
119 .I mask
120 contains
121 .B IN_ONLYDIR
122 and
123 .I pathname
124 is not a directory.
125 .SH VERSIONS
126 Inotify was merged into the 2.6.13 Linux kernel.
127 .SH STANDARDS
128 This system call is Linux-specific.
129 .SH EXAMPLES
130 See
131 .BR inotify (7).
132 .SH SEE ALSO
133 .BR inotify_init (2),
134 .BR inotify_rm_watch (2),
135 .BR inotify (7)