1INOTIFY_ADD_WATCH(2) Linux Programmer's Manual INOTIFY_ADD_WATCH(2)
2
3
4
6 inotify_add_watch - add a watch to an initialized inotify instance
7
9 #include <sys/inotify.h>
10
11 int inotify_add_watch(int fd, const char *pathname, uint32_t mask);
12
14 inotify_add_watch() adds a new watch, or modifies an existing watch,
15 for the file whose location is specified in pathname; the caller must
16 have read permission for this file. The fd argument is a file descrip‐
17 tor referring to the inotify instance whose watch list is to be modi‐
18 fied. The events to be monitored for pathname are specified in the
19 mask bit-mask argument. See inotify(7) for a description of the bits
20 that can be set in mask.
21
22 A successful call to inotify_add_watch() returns a unique watch
23 descriptor for this inotify instance, for the filesystem object (inode)
24 that corresponds to pathname. If the filesystem object was not previ‐
25 ously being watched by this inotify instance, then the watch descriptor
26 is newly allocated. If the filesystem object was already being watched
27 (perhaps via a different link to the same object), then the descriptor
28 for the existing watch is returned.
29
30 The watch descriptor is returned by later read(2)s from the inotify
31 file descriptor. These reads fetch inotify_event structures (see ino‐
32 tify(7)) indicating filesystem events; the watch descriptor inside this
33 structure identifies the object for which the event occurred.
34
36 On success, inotify_add_watch() returns a nonnegative watch descriptor.
37 On error, -1 is returned and errno is set appropriately.
38
40 EACCES Read access to the given file is not permitted.
41
42 EBADF The given file descriptor is not valid.
43
44 EFAULT pathname points outside of the process's accessible address
45 space.
46
47 EINVAL The given event mask contains no valid events; or fd is not an
48 inotify file descriptor.
49
50 ENAMETOOLONG
51 pathname is too long.
52
53 ENOENT A directory component in pathname does not exist or is a dan‐
54 gling symbolic link.
55
56 ENOMEM Insufficient kernel memory was available.
57
58 ENOSPC The user limit on the total number of inotify watches was
59 reached or the kernel failed to allocate a needed resource.
60
62 Inotify was merged into the 2.6.13 Linux kernel.
63
65 This system call is Linux-specific.
66
68 inotify_init(2), inotify_rm_watch(2), inotify(7)
69
71 This page is part of release 4.15 of the Linux man-pages project. A
72 description of the project, information about reporting bugs, and the
73 latest version of this page, can be found at
74 https://www.kernel.org/doc/man-pages/.
75
76
77
78Linux 2017-09-15 INOTIFY_ADD_WATCH(2)