1INOTIFY_ADD_WATCH(2)       Linux Programmer's Manual      INOTIFY_ADD_WATCH(2)
2
3
4

NAME

6       inotify_add_watch - add a watch to an initialized inotify instance
7

SYNOPSIS

9       #include <sys/inotify.h>
10
11       int inotify_add_watch(int fd, const char *pathname, uint32_t mask);
12

DESCRIPTION

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

RETURN VALUE

36       On success, inotify_add_watch() returns a nonnegative watch descriptor.
37       On error, -1 is returned and errno is set appropriately.
38

ERRORS

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 mask  contains
48              both  IN_MASK_ADD  and  IN_MASK_CREATE;  or fd is not an inotify
49              file descriptor.
50
51       ENAMETOOLONG
52              pathname is too long.
53
54       ENOENT A directory component in pathname does not exist or  is  a  dan‐
55              gling symbolic link.
56
57       ENOMEM Insufficient kernel memory was available.
58
59       ENOSPC The  user  limit  on  the  total  number  of inotify watches was
60              reached or the kernel failed to allocate a needed resource.
61
62       ENOTDIR
63              mask contains IN_ONLYDIR and pathname is not a directory.
64
65       EEXIST mask contains IN_MASK_CREATE  and  pathname  refers  to  a  file
66              already being watched by the same fd.
67

VERSIONS

69       Inotify was merged into the 2.6.13 Linux kernel.
70

CONFORMING TO

72       This system call is Linux-specific.
73

SEE ALSO

75       inotify_init(2), inotify_rm_watch(2), inotify(7)
76

COLOPHON

78       This  page  is  part of release 5.02 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-03-06              INOTIFY_ADD_WATCH(2)
Impressum