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

NAME

6       fanotify_mark - add, remove, or modify an fanotify mark on a filesystem
7       object
8

SYNOPSIS

10       #include <sys/fanotify.h>
11
12       int fanotify_mark(int fanotify_fd, unsigned int flags,
13                         uint64_t mask, int dirfd, const char *pathname);
14

DESCRIPTION

16       For an overview of the fanotify API, see fanotify(7).
17
18       fanotify_mark() adds, removes,  or  modifies  an  fanotify  mark  on  a
19       filesystem  object.   The  caller  must  have  read  permission  on the
20       filesystem object that is to be marked.
21
22       The  fanotify_fd  argument  is  a  file  descriptor  returned  by  fan‐
23       otify_init(2).
24
25       flags  is  a  bit mask describing the modification to perform.  It must
26       include exactly one of the following values:
27
28       FAN_MARK_ADD
29              The events in mask will be added to the mark  mask  (or  to  the
30              ignore  mask).   mask  must be nonempty or the error EINVAL will
31              occur.
32
33       FAN_MARK_REMOVE
34              The events in argument mask will be removed from the  mark  mask
35              (or  from  the ignore mask).  mask must be nonempty or the error
36              EINVAL will occur.
37
38       FAN_MARK_FLUSH
39              Remove either all marks for filesystems, all marks  for  mounts,
40              or  all marks for directories and files from the fanotify group.
41              If flags contains  FAN_MARK_MOUNT,  all  marks  for  mounts  are
42              removed  from the group.  If flags contains FAN_MARK_FILESYSTEM,
43              all marks for filesystems are removed from  the  group.   Other‐
44              wise,  all marks for directories and files are removed.  No flag
45              other than and at  most  one  of  the  flags  FAN_MARK_MOUNT  or
46              FAN_MARK_FILESYSTEM    can   be   used   in   conjunction   with
47              FAN_MARK_FLUSH.  mask is ignored.
48
49       If none of the values above is specified, or more than  one  is  speci‐
50       fied, the call fails with the error EINVAL.
51
52       In  addition,  zero  or  more  of the following values may be ORed into
53       flags:
54
55       FAN_MARK_DONT_FOLLOW
56              If pathname is a symbolic link, mark  the  link  itself,  rather
57              than  the file to which it refers.  (By default, fanotify_mark()
58              dereferences pathname if it is a symbolic link.)
59
60       FAN_MARK_ONLYDIR
61              If the filesystem object to be marked is not  a  directory,  the
62              error ENOTDIR shall be raised.
63
64       FAN_MARK_MOUNT
65              Mark  the mount point specified by pathname.  If pathname is not
66              itself a mount point, the mount point containing  pathname  will
67              be  marked.   All directories, subdirectories, and the contained
68              files of the mount point will be monitored.  This  value  cannot
69              be  used if the fanotify_fd file descriptor has been initialized
70              with the flag FAN_REPORT_FID or if any of the new directory mod‐
71              ification  events  are  provided as a mask.  Attempting to do so
72              will result in the error EINVAL being returned.
73
74       FAN_MARK_FILESYSTEM (since Linux 4.20)
75              Mark the filesystem specified by pathname.  The filesystem  con‐
76              taining  pathname  will  be marked.  All the contained files and
77              directories of the filesystem from any mount point will be moni‐
78              tored.
79
80       FAN_MARK_IGNORED_MASK
81              The  events in mask shall be added to or removed from the ignore
82              mask.
83
84       FAN_MARK_IGNORED_SURV_MODIFY
85              The ignore mask shall survive modify events.  If  this  flag  is
86              not  set,  the ignore mask is cleared when a modify event occurs
87              for the ignored file or directory.
88
89       mask defines which events shall be listened  for  (or  which  shall  be
90       ignored).  It is a bit mask composed of the following values:
91
92       FAN_ACCESS
93              Create  an  event  when  a  file  or directory (but see BUGS) is
94              accessed (read).
95
96       FAN_MODIFY
97              Create an event when a file is modified (write).
98
99       FAN_CLOSE_WRITE
100              Create an event when a writable file is closed.
101
102       FAN_CLOSE_NOWRITE
103              Create an event when a read-only file or directory is closed.
104
105       FAN_OPEN
106              Create an event when a file or directory is opened.
107
108       FAN_OPEN_EXEC  (since Linux 5.0)
109              Create an event when a file is opened with the intent to be exe‐
110              cuted.  See NOTES for additional details.
111
112       FAN_ATTRIB
113              Create  an  event  when the metadata for a file or directory has
114              changed.
115
116       FAN_CREATE
117              Create an event when a file or directory has been created  in  a
118              marked parent directory.
119
120       FAN_DELETE
121              Create  an  event when a file or directory has been deleted in a
122              marked parent directory.
123
124       FAN_DELETE_SELF
125              Create an event when  a  marked  file  or  directory  itself  is
126              deleted.
127
128       FAN_MOVED_FROM
129              Create  an  event when a file or directory has been moved from a
130              marked parent directory.
131
132       FAN_MOVED_TO
133              Create an event when a file or directory has  been  moved  to  a
134              marked parent directory.
135
136       FAN_Q_OVERFLOW
137              Create an event when an overflow of the event queue occurs.  The
138              size  of  the  event  queue  is  limited  to  16384  entries  if
139              FAN_UNLIMITED_QUEUE is not set in fanotify_init(2).
140
141       FAN_OPEN_PERM
142              Create an event when a permission to open a file or directory is
143              requested.    An   fanotify   file   descriptor   created   with
144              FAN_CLASS_PRE_CONTENT or FAN_CLASS_CONTENT is required.
145
146       FAN_OPEN_EXEC_PERM (since Linux 5.0)
147              Create  an  event when a permission to open a file for execution
148              is  requested.   An  fanotify  file  descriptor   created   with
149              FAN_CLASS_PRE_CONTENT  or  FAN_CLASS_CONTENT  is  required.  See
150              NOTES for additional details.
151
152       FAN_ACCESS_PERM
153              Create an event when a permission to read a file or directory is
154              requested.    An   fanotify   file   descriptor   created   with
155              FAN_CLASS_PRE_CONTENT or FAN_CLASS_CONTENT is required.
156
157       FAN_ONDIR
158              Create events  for  directories—for  example,  when  opendir(3),
159              readdir(3)  (but see BUGS), and closedir(3) are called.  Without
160              this flag, only events for files  are  created.   The  FAN_ONDIR
161              flag  is  reported in an event mask only if the fanotify_fd file
162              descriptor has been initialized with  the  flag  FAN_REPORT_FID.
163              In  the  context  of directory entry events, such as FAN_CREATE,
164              FAN_DELETE, FAN_MOVED_FROM, and FAN_MOVED_TO for example, speci‐
165              fying  the  flag FAN_ONDIR is required in order to create events
166              when  subdirectory  entries  are   modified   (i.e.,   mkdir(2)/
167              rmdir(2)).  Subdirectory entry modification events will never be
168              merged with nonsubdirectory  entry  modification  events.   This
169              flag  is  never  reported  individually  within  an event and is
170              always supplied in conjunction with another event type.
171
172       FAN_EVENT_ON_CHILD
173              Events for the immediate children of marked directories shall be
174              created.   The  flag  has  no  effect  when  marking  mounts and
175              filesystems.  Note that events are not generated for children of
176              the  subdirectories  of marked directories.  To monitor complete
177              directory trees it is necessary to mark the relevant mount.
178
179       The following composed values are defined:
180
181       FAN_CLOSE
182              A file is closed (FAN_CLOSE_WRITE|FAN_CLOSE_NOWRITE).
183
184       FAN_MOVE
185              A      file      or      directory      has      been      moved
186              (FAN_MOVED_FROM|FAN_MOVED_TO).
187
188       The filesystem object to be marked is determined by the file descriptor
189       dirfd and the pathname specified in pathname:
190
191       *  If pathname is NULL, dirfd  defines  the  filesystem  object  to  be
192          marked.
193
194       *  If pathname is NULL, and dirfd takes the special value AT_FDCWD, the
195          current working directory is to be marked.
196
197       *  If pathname is absolute, it defines  the  filesystem  object  to  be
198          marked, and dirfd is ignored.
199
200       *  If pathname is relative, and dirfd does not have the value AT_FDCWD,
201          then the filesystem object to be marked is determined by  interpret‐
202          ing pathname relative the directory referred to by dirfd.
203
204       *  If  pathname is relative, and dirfd has the value AT_FDCWD, then the
205          filesystem object to be marked is determined by  interpreting  path‐
206          name relative the current working directory.
207

RETURN VALUE

209       On  success,  fanotify_mark() returns 0.  On error, -1 is returned, and
210       errno is set to indicate the error.
211

ERRORS

213       EBADF  An invalid file descriptor was passed in fanotify_fd.
214
215       EINVAL An invalid value was passed in flags or mask, or fanotify_fd was
216              not an fanotify file descriptor.
217
218       EINVAL The  fanotify file descriptor was opened with FAN_CLASS_NOTIF or
219              FAN_REPORT_FID and mask contains a flag  for  permission  events
220              (FAN_OPEN_PERM or FAN_ACCESS_PERM).
221
222       ENOENT The  filesystem  object indicated by dirfd and pathname does not
223              exist.  This error also occurs when trying to remove a mark from
224              an object which is not marked.
225
226       ENOMEM The necessary memory could not be allocated.
227
228       ENOSPC The number of marks exceeds the limit of 8192 and the FAN_UNLIM‐
229              ITED_MARKS  flag  was  not  specified  when  the  fanotify  file
230              descriptor was created with fanotify_init(2).
231
232       ENOSYS This  kernel  does  not implement fanotify_mark().  The fanotify
233              API is available only if the kernel  was  configured  with  CON‐
234              FIG_FANOTIFY.
235
236       ENOTDIR
237              flags  contains  FAN_MARK_ONLYDIR, and dirfd and pathname do not
238              specify a directory.
239
240       EXDEV  The filesystem object indicated by  pathname  resides  within  a
241              filesystem  subvolume  (e.g.,  btrfs(5))  which uses a different
242              fsid than its root superblock.  This error can be returned  only
243              when  an  fanotify  file descriptor returned by fanotify_init(2)
244              has been created with FAN_REPORT_FID.
245
246       ENODEV The filesystem object indicated by pathname  is  not  associated
247              with  a  filesystem  that  supports fsid (e.g., tmpfs(5)).  This
248              error can be returned only  when  an  fanotify  file  descriptor
249              returned    by    fanotify_init(2)   has   been   created   with
250              FAN_REPORT_FID.
251
252       EOPNOTSUPP
253              The object indicated by pathname is associated with a filesystem
254              that  does not support the encoding of file handles.  This error
255              can be returned only when an fanotify file  descriptor  returned
256              by fanotify_init(2) has been created with FAN_REPORT_FID.
257

VERSIONS

259       fanotify_mark()  was  introduced  in version 2.6.36 of the Linux kernel
260       and enabled in version 2.6.37.
261

CONFORMING TO

263       This system call is Linux-specific.
264

NOTES

266   FAN_OPEN_EXEC and FAN_OPEN_EXEC_PERM
267       When using either FAN_OPEN_EXEC or FAN_OPEN_EXEC_PERM within the  mask,
268       events  of  these types will be returned only when the direct execution
269       of a program occurs.  More specifically,  this  means  that  events  of
270       these  types  will  be  generated  for  files  that  are  opened  using
271       execve(2), execveat(2), or uselib(2).  Events of these types  will  not
272       be  raised in the situation where an interpreter is passed (or reads) a
273       script file for interpretation.
274
275       Additionally, if a mark has also  been  placed  on  the  Linux  dynamic
276       linker,  a  user  should also expect to receive an event for it when an
277       ELF object has been successfully opened using execve(2) or execveat(2).
278
279       For example, if the following ELF binary  were  to  be  invoked  and  a
280       FAN_OPEN_EXEC mark has been placed on /:
281
282           $ /bin/echo foo
283
284       The  listening  application  in  this  case would receive FAN_OPEN_EXEC
285       events for both the ELF binary and interpreter, respectively:
286
287           /bin/echo
288           /lib64/ld-linux-x86-64.so.2
289

BUGS

291       The following bugs were present in Linux kernels before version 3.16:
292
293       *  If flags contains FAN_MARK_FLUSH, dirfd and pathname must specify  a
294          valid filesystem object, even though this object is not used.
295
296       *  readdir(2) does not generate a FAN_ACCESS event.
297
298       *  If  fanotify_mark()  is  called  with  FAN_MARK_FLUSH,  flags is not
299          checked for invalid values.
300

SEE ALSO

302       fanotify_init(2), fanotify(7)
303

COLOPHON

305       This page is part of release 5.02 of the Linux  man-pages  project.   A
306       description  of  the project, information about reporting bugs, and the
307       latest    version    of    this    page,    can     be     found     at
308       https://www.kernel.org/doc/man-pages/.
309
310
311
312Linux                             2019-08-02                  FANOTIFY_MARK(2)
Impressum