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 (since Linux 5.1)
113              Create  an  event  when the metadata for a file or directory has
114              changed.
115
116       FAN_CREATE (since Linux 5.1)
117              Create an event when a file or directory has been created  in  a
118              marked parent directory.
119
120       FAN_DELETE (since Linux 5.1)
121              Create  an  event when a file or directory has been deleted in a
122              marked parent directory.
123
124       FAN_DELETE_SELF (since Linux 5.1)
125              Create an event when  a  marked  file  or  directory  itself  is
126              deleted.
127
128       FAN_MOVED_FROM (since Linux 5.1)
129              Create  an  event when a file or directory has been moved from a
130              marked parent directory.
131
132       FAN_MOVED_TO (since Linux 5.1)
133              Create an event when a file or directory has  been  moved  to  a
134              marked parent directory.
135
136       FAN_MOVE_SELF (since Linux 5.1)
137              Create  an event when a marked file or directory itself has been
138              moved.
139
140       FAN_Q_OVERFLOW
141              Create an event when an overflow of the event queue occurs.  The
142              size  of  the  event  queue  is  limited  to  16384  entries  if
143              FAN_UNLIMITED_QUEUE is not set in fanotify_init(2).
144
145       FAN_OPEN_PERM
146              Create an event when a permission to open a file or directory is
147              requested.    An   fanotify   file   descriptor   created   with
148              FAN_CLASS_PRE_CONTENT or FAN_CLASS_CONTENT is required.
149
150       FAN_OPEN_EXEC_PERM (since Linux 5.0)
151              Create an event when a permission to open a file  for  execution
152              is   requested.    An  fanotify  file  descriptor  created  with
153              FAN_CLASS_PRE_CONTENT or  FAN_CLASS_CONTENT  is  required.   See
154              NOTES for additional details.
155
156       FAN_ACCESS_PERM
157              Create an event when a permission to read a file or directory is
158              requested.    An   fanotify   file   descriptor   created   with
159              FAN_CLASS_PRE_CONTENT or FAN_CLASS_CONTENT is required.
160
161       FAN_ONDIR
162              Create  events  for  directories—for  example,  when opendir(3),
163              readdir(3) (but see BUGS), and closedir(3) are called.   Without
164              this  flag,  only  events  for files are created.  The FAN_ONDIR
165              flag is reported in an event mask only if the  fanotify_fd  file
166              descriptor  has  been  initialized with the flag FAN_REPORT_FID.
167              In the context of directory entry events,  such  as  FAN_CREATE,
168              FAN_DELETE, FAN_MOVED_FROM, and FAN_MOVED_TO for example, speci‐
169              fying the flag FAN_ONDIR is required in order to  create  events
170              when   subdirectory   entries   are  modified  (i.e.,  mkdir(2)/
171              rmdir(2)).  Subdirectory entry modification events will never be
172              merged  with  nonsubdirectory  entry  modification events.  This
173              flag is never reported  individually  within  an  event  and  is
174              always supplied in conjunction with another event type.
175
176       FAN_EVENT_ON_CHILD
177              Events for the immediate children of marked directories shall be
178              created.  The  flag  has  no  effect  when  marking  mounts  and
179              filesystems.  Note that events are not generated for children of
180              the subdirectories of marked directories.  To  monitor  complete
181              directory trees it is necessary to mark the relevant mount.
182
183       The following composed values are defined:
184
185       FAN_CLOSE
186              A file is closed (FAN_CLOSE_WRITE|FAN_CLOSE_NOWRITE).
187
188       FAN_MOVE
189              A      file      or      directory      has      been      moved
190              (FAN_MOVED_FROM|FAN_MOVED_TO).
191
192       The filesystem object to be marked is determined by the file descriptor
193       dirfd and the pathname specified in pathname:
194
195       *  If  pathname  is  NULL,  dirfd  defines  the filesystem object to be
196          marked.
197
198       *  If pathname is NULL, and dirfd takes the special value AT_FDCWD, the
199          current working directory is to be marked.
200
201       *  If  pathname  is  absolute,  it  defines the filesystem object to be
202          marked, and dirfd is ignored.
203
204       *  If pathname is relative, and dirfd does not have the value AT_FDCWD,
205          then  the filesystem object to be marked is determined by interpret‐
206          ing pathname relative the directory referred to by dirfd.
207
208       *  If pathname is relative, and dirfd has the value AT_FDCWD, then  the
209          filesystem  object  to be marked is determined by interpreting path‐
210          name relative the current working directory.
211

RETURN VALUE

213       On success, fanotify_mark() returns 0.  On error, -1 is  returned,  and
214       errno is set to indicate the error.
215

ERRORS

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

VERSIONS

263       fanotify_mark() was introduced in version 2.6.36 of  the  Linux  kernel
264       and enabled in version 2.6.37.
265

CONFORMING TO

267       This system call is Linux-specific.
268

NOTES

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

BUGS

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

SEE ALSO

306       fanotify_init(2), fanotify(7)
307

COLOPHON

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