1inotify_add_watch(2)          System Calls Manual         inotify_add_watch(2)
2
3
4

NAME

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

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/inotify.h>
13
14       int inotify_add_watch(int fd, const char *pathname, uint32_t mask);
15

DESCRIPTION

17       inotify_add_watch()  adds  a  new watch, or modifies an existing watch,
18       for the file whose location is specified in pathname; the  caller  must
19       have read permission for this file.  The fd argument is a file descrip‐
20       tor referring to the inotify instance whose watch list is to  be  modi‐
21       fied.   The  events  to  be monitored for pathname are specified in the
22       mask bit-mask argument.  See inotify(7) for a description of  the  bits
23       that can be set in mask.
24
25       A  successful  call  to  inotify_add_watch() returns a unique watch de‐
26       scriptor for this inotify instance, for the filesystem  object  (inode)
27       that  corresponds to pathname.  If the filesystem object was not previ‐
28       ously being watched by this inotify instance, then the watch descriptor
29       is newly allocated.  If the filesystem object was already being watched
30       (perhaps via a different link to the same object), then the  descriptor
31       for the existing watch is returned.
32
33       The  watch  descriptor  is  returned by later read(2)s from the inotify
34       file descriptor.  These reads fetch inotify_event structures (see  ino‐
35       tify(7)) indicating filesystem events; the watch descriptor inside this
36       structure identifies the object for which the event occurred.
37

RETURN VALUE

39       On success, inotify_add_watch() returns a watch descriptor (a  nonnega‐
40       tive  integer).   On error, -1 is returned and errno is set to indicate
41       the error.
42

ERRORS

44       EACCES Read access to the given file is not permitted.
45
46       EBADF  The given file descriptor is not valid.
47
48       EEXIST mask contains IN_MASK_CREATE and pathname refers to a  file  al‐
49              ready being watched by the same fd.
50
51       EFAULT pathname  points  outside  of  the  process's accessible address
52              space.
53
54       EINVAL The given event mask contains no valid events; or mask  contains
55              both  IN_MASK_ADD  and  IN_MASK_CREATE;  or fd is not an inotify
56              file descriptor.
57
58       ENAMETOOLONG
59              pathname is too long.
60
61       ENOENT A directory component in pathname does not exist or  is  a  dan‐
62              gling symbolic link.
63
64       ENOMEM Insufficient kernel memory was available.
65
66       ENOSPC The  user  limit  on  the  total  number  of inotify watches was
67              reached or the kernel failed to allocate a needed resource.
68
69       ENOTDIR
70              mask contains IN_ONLYDIR and pathname is not a directory.
71

STANDARDS

73       Linux.
74

HISTORY

76       Linux 2.6.13.
77

EXAMPLES

79       See inotify(7).
80

SEE ALSO

82       inotify_init(2), inotify_rm_watch(2), inotify(7)
83
84
85
86Linux man-pages 6.05              2023-03-30              inotify_add_watch(2)
Impressum