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 EEXIST mask contains IN_MASK_CREATE and pathname refers to a file
45 already being watched by the same fd.
46
47 EFAULT pathname points outside of the process's accessible address
48 space.
49
50 EINVAL The given event mask contains no valid events; or mask contains
51 both IN_MASK_ADD and IN_MASK_CREATE; or fd is not an inotify
52 file descriptor.
53
54 ENAMETOOLONG
55 pathname is too long.
56
57 ENOENT A directory component in pathname does not exist or is a dan‐
58 gling symbolic link.
59
60 ENOMEM Insufficient kernel memory was available.
61
62 ENOSPC The user limit on the total number of inotify watches was
63 reached or the kernel failed to allocate a needed resource.
64
65 ENOTDIR
66 mask contains IN_ONLYDIR and pathname is not a directory.
67
69 Inotify was merged into the 2.6.13 Linux kernel.
70
72 This system call is Linux-specific.
73
75 inotify_init(2), inotify_rm_watch(2), inotify(7)
76
78 This page is part of release 5.04 of the Linux man-pages project. A
79 description of the project, information about reporting bugs, and the
80 latest version of this page, can be found at
81 https://www.kernel.org/doc/man-pages/.
82
83
84
85Linux 2019-10-10 INOTIFY_ADD_WATCH(2)