@@ -710,6 +710,14 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
if (event_f_flags & ~FANOTIFY_INIT_ALL_EVENT_F_BITS)
return -EINVAL;
+ /*
+ * New event format info bits can only be set for the default
+ * notification class
+ */
+ if ((flags & FAN_ALL_EVENT_INFO_BITS) &&
+ (flags & FAN_ALL_CLASS_BITS) != FAN_CLASS_NOTIF)
+ return -EINVAL;
+
switch (event_f_flags & O_ACCMODE) {
case O_RDONLY:
case O_RDWR:
@@ -794,6 +802,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
if (fd < 0)
goto out_destroy_group;
+ group->fanotify_data.flags = flags;
return fd;
out_destroy_group:
@@ -181,7 +181,8 @@ struct fsnotify_group {
wait_queue_head_t access_waitq;
atomic_t bypass_perm;
#endif /* CONFIG_FANOTIFY_ACCESS_PERMISSIONS */
- int f_flags;
+ int flags; /* flags from fanotify_init() */
+ int f_flags; /* event_f_flags from fanotify_init() */
unsigned int max_marks;
struct user_struct *user;
} fanotify_data;
@@ -36,9 +36,14 @@
#define FAN_UNLIMITED_QUEUE 0x00000010
#define FAN_UNLIMITED_MARKS 0x00000020
+/* These bits determine the format of the reported events */
+#define FAN_EVENT_INFO_PARENT 0x00000100 /* Event fd maybe of parent */
+#define FAN_ALL_EVENT_INFO_BITS (FAN_EVENT_INFO_PARENT)
+
#define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \
- FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\
- FAN_UNLIMITED_MARKS)
+ FAN_ALL_CLASS_BITS | \
+ FAN_ALL_EVENT_INFO_BITS | \
+ FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS)
/* flags used for fanotify_modify_mark() */
#define FAN_MARK_ADD 0x00000001
The new init flag FAN_EVENT_INFO_PARENT indicates that the event fd may point to the parent, depending on the event. FAN_EVENT_INFO_PARENT will also be used to add support for more events, so it is stored in a new 'flags' field in the group's private data for future use. FAN_EVENT_INFO_PARENT can only be set along with the default notification class. Signed-off-by: Amir Goldstein <amir73il@gmail.com> --- fs/notify/fanotify/fanotify_user.c | 11 ++++++++++- include/linux/fsnotify_backend.h | 3 ++- include/uapi/linux/fanotify.h | 9 +++++++-- 3 files changed, 19 insertions(+), 4 deletions(-)