1 /* Copyright (C) 2010-2015 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3 
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8 
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <http://www.gnu.org/licenses/>.  */
17 
18 #ifndef	_SYS_FANOTIFY_H
19 #define	_SYS_FANOTIFY_H	1
20 
21 #include <stdint.h>
22 
23 struct fanotify_event_metadata {
24 	unsigned event_len;
25 	unsigned char vers;
26 	unsigned char reserved;
27 	unsigned short metadata_len;
28 	unsigned long long mask
29 #ifdef __GNUC__
30 	__attribute__((__aligned__(8)))
31 #endif
32 	;
33 	int fd;
34 	int pid;
35 };
36 
37 struct fanotify_response {
38 	int fd;
39 	unsigned response;
40 };
41 
42 #define FAN_ACCESS 0x01
43 #define FAN_MODIFY 0x02
44 #define FAN_CLOSE_WRITE 0x08
45 #define FAN_CLOSE_NOWRITE 0x10
46 #define FAN_OPEN 0x20
47 #define FAN_Q_OVERFLOW 0x4000
48 #define FAN_OPEN_PERM 0x10000
49 #define FAN_ACCESS_PERM 0x20000
50 #define FAN_ONDIR 0x40000000
51 #define FAN_EVENT_ON_CHILD 0x08000000
52 #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE)
53 #define FAN_CLOEXEC 0x01
54 #define FAN_NONBLOCK 0x02
55 #define FAN_CLASS_NOTIF 0
56 #define FAN_CLASS_CONTENT 0x04
57 #define FAN_CLASS_PRE_CONTENT 0x08
58 #define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | FAN_CLASS_PRE_CONTENT)
59 #define FAN_UNLIMITED_QUEUE 0x10
60 #define FAN_UNLIMITED_MARKS 0x20
61 #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS)
62 #define FAN_MARK_ADD 0x01
63 #define FAN_MARK_REMOVE 0x02
64 #define FAN_MARK_DONT_FOLLOW 0x04
65 #define FAN_MARK_ONLYDIR 0x08
66 #define FAN_MARK_MOUNT 0x10
67 #define FAN_MARK_IGNORED_MASK 0x20
68 #define FAN_MARK_IGNORED_SURV_MODIFY 0x40
69 #define FAN_MARK_FLUSH 0x80
70 #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_DONT_FOLLOW | FAN_MARK_ONLYDIR | FAN_MARK_MOUNT | FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY | FAN_MARK_FLUSH)
71 #define FAN_ALL_EVENTS (FAN_ACCESS | FAN_MODIFY | FAN_CLOSE | FAN_OPEN)
72 #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM | FAN_ACCESS_PERM)
73 #define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS | FAN_ALL_PERM_EVENTS | FAN_Q_OVERFLOW)
74 #define FANOTIFY_METADATA_VERSION 3
75 #define FAN_ALLOW 0x01
76 #define FAN_DENY 0x02
77 #define FAN_NOFD -1
78 #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata))
79 #define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, (struct fanotify_event_metadata*)(((char *)(meta)) + (meta)->event_len))
80 #define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && (long)(meta)->event_len <= (long)(len))
81 
82 
83 __BEGIN_DECLS
84 
85 /* Create and initialize fanotify group.  */
86 extern int fanotify_init (unsigned int __flags, unsigned int __event_f_flags)
87   __THROW;
88 
89 /* Add, remove, or modify an fanotify mark on a filesystem object.  */
90 extern int fanotify_mark (int __fanotify_fd, unsigned int __flags,
91 			  uint64_t __mask, int __dfd, const char *__pathname)
92      __THROW;
93 
94 __END_DECLS
95 
96 #endif /* sys/fanotify.h */
97