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 de‐
23 scriptor 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 watch descriptor (a nonnega‐
37 tive integer). On error, -1 is returned and errno is set appropri‐
38 ately.
39
41 EACCES Read access to the given file is not permitted.
42
43 EBADF The given file descriptor is not valid.
44
45 EEXIST mask contains IN_MASK_CREATE and pathname refers to a file al‐
46 ready being watched by the same fd.
47
48 EFAULT pathname points outside of the process's accessible address
49 space.
50
51 EINVAL The given event mask contains no valid events; or mask contains
52 both IN_MASK_ADD and IN_MASK_CREATE; or fd is not an inotify
53 file descriptor.
54
55 ENAMETOOLONG
56 pathname is too long.
57
58 ENOENT A directory component in pathname does not exist or is a dan‐
59 gling symbolic link.
60
61 ENOMEM Insufficient kernel memory was available.
62
63 ENOSPC The user limit on the total number of inotify watches was
64 reached or the kernel failed to allocate a needed resource.
65
66 ENOTDIR
67 mask contains IN_ONLYDIR and pathname is not a directory.
68
70 Inotify was merged into the 2.6.13 Linux kernel.
71
73 This system call is Linux-specific.
74
76 See inotify(7).
77
79 inotify_init(2), inotify_rm_watch(2), inotify(7)
80
82 This page is part of release 5.10 of the Linux man-pages project. A
83 description of the project, information about reporting bugs, and the
84 latest version of this page, can be found at
85 https://www.kernel.org/doc/man-pages/.
86
87
88
89Linux 2020-04-11 INOTIFY_ADD_WATCH(2)