Greg Kroah-Hartman | 6f52b16 | 2017-11-01 15:08:43 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 2 | #ifndef _UAPI_LINUX_FANOTIFY_H |
| 3 | #define _UAPI_LINUX_FANOTIFY_H |
| 4 | |
| 5 | #include <linux/types.h> |
| 6 | |
| 7 | /* the following events that user-space can register for */ |
| 8 | #define FAN_ACCESS 0x00000001 /* File was accessed */ |
| 9 | #define FAN_MODIFY 0x00000002 /* File was modified */ |
Amir Goldstein | 235328d | 2019-01-10 19:04:43 +0200 | [diff] [blame] | 10 | #define FAN_ATTRIB 0x00000004 /* Metadata changed */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 11 | #define FAN_CLOSE_WRITE 0x00000008 /* Writtable file closed */ |
| 12 | #define FAN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */ |
| 13 | #define FAN_OPEN 0x00000020 /* File was opened */ |
Amir Goldstein | 235328d | 2019-01-10 19:04:43 +0200 | [diff] [blame] | 14 | #define FAN_MOVED_FROM 0x00000040 /* File was moved from X */ |
| 15 | #define FAN_MOVED_TO 0x00000080 /* File was moved to Y */ |
| 16 | #define FAN_CREATE 0x00000100 /* Subfile was created */ |
| 17 | #define FAN_DELETE 0x00000200 /* Subfile was deleted */ |
| 18 | #define FAN_DELETE_SELF 0x00000400 /* Self was deleted */ |
| 19 | #define FAN_MOVE_SELF 0x00000800 /* Self was moved */ |
Matthew Bobrowski | 9b076f1 | 2018-11-08 14:07:14 +1100 | [diff] [blame] | 20 | #define FAN_OPEN_EXEC 0x00001000 /* File was opened for exec */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 21 | |
| 22 | #define FAN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ |
| 23 | |
| 24 | #define FAN_OPEN_PERM 0x00010000 /* File open in perm check */ |
| 25 | #define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */ |
Matthew Bobrowski | 66917a3 | 2018-11-08 14:12:44 +1100 | [diff] [blame] | 26 | #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 27 | |
| 28 | #define FAN_ONDIR 0x40000000 /* event occurred against dir */ |
| 29 | |
| 30 | #define FAN_EVENT_ON_CHILD 0x08000000 /* interested in child events */ |
| 31 | |
| 32 | /* helper events */ |
| 33 | #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */ |
Amir Goldstein | 235328d | 2019-01-10 19:04:43 +0200 | [diff] [blame] | 34 | #define FAN_MOVE (FAN_MOVED_FROM | FAN_MOVED_TO) /* moves */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 35 | |
| 36 | /* flags used for fanotify_init() */ |
| 37 | #define FAN_CLOEXEC 0x00000001 |
| 38 | #define FAN_NONBLOCK 0x00000002 |
| 39 | |
Amir Goldstein | d54f4fb | 2018-09-01 10:41:13 +0300 | [diff] [blame] | 40 | /* These are NOT bitwise flags. Both bits are used together. */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 41 | #define FAN_CLASS_NOTIF 0x00000000 |
| 42 | #define FAN_CLASS_CONTENT 0x00000004 |
| 43 | #define FAN_CLASS_PRE_CONTENT 0x00000008 |
Amir Goldstein | 23c9dee | 2018-10-04 00:25:35 +0300 | [diff] [blame] | 44 | |
| 45 | /* Deprecated - do not use this in programs and do not add new flags here! */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 46 | #define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ |
| 47 | FAN_CLASS_PRE_CONTENT) |
| 48 | |
| 49 | #define FAN_UNLIMITED_QUEUE 0x00000010 |
| 50 | #define FAN_UNLIMITED_MARKS 0x00000020 |
Steve Grubb | de8cd83 | 2017-10-02 20:21:39 -0400 | [diff] [blame] | 51 | #define FAN_ENABLE_AUDIT 0x00000040 |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 52 | |
Amir Goldstein | d0a6a87 | 2018-10-04 00:25:38 +0300 | [diff] [blame] | 53 | /* Flags to determine fanotify event format */ |
| 54 | #define FAN_REPORT_TID 0x00000100 /* event->pid is thread id */ |
Amir Goldstein | e9e0c89 | 2019-01-10 19:04:34 +0200 | [diff] [blame] | 55 | #define FAN_REPORT_FID 0x00000200 /* Report unique file id */ |
Amir Goldstein | d0a6a87 | 2018-10-04 00:25:38 +0300 | [diff] [blame] | 56 | |
Amir Goldstein | 23c9dee | 2018-10-04 00:25:35 +0300 | [diff] [blame] | 57 | /* Deprecated - do not use this in programs and do not add new flags here! */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 58 | #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \ |
| 59 | FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\ |
| 60 | FAN_UNLIMITED_MARKS) |
| 61 | |
| 62 | /* flags used for fanotify_modify_mark() */ |
| 63 | #define FAN_MARK_ADD 0x00000001 |
| 64 | #define FAN_MARK_REMOVE 0x00000002 |
| 65 | #define FAN_MARK_DONT_FOLLOW 0x00000004 |
| 66 | #define FAN_MARK_ONLYDIR 0x00000008 |
Amir Goldstein | d54f4fb | 2018-09-01 10:41:13 +0300 | [diff] [blame] | 67 | /* FAN_MARK_MOUNT is 0x00000010 */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 68 | #define FAN_MARK_IGNORED_MASK 0x00000020 |
| 69 | #define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040 |
| 70 | #define FAN_MARK_FLUSH 0x00000080 |
Amir Goldstein | d54f4fb | 2018-09-01 10:41:13 +0300 | [diff] [blame] | 71 | /* FAN_MARK_FILESYSTEM is 0x00000100 */ |
| 72 | |
| 73 | /* These are NOT bitwise flags. Both bits can be used togther. */ |
| 74 | #define FAN_MARK_INODE 0x00000000 |
| 75 | #define FAN_MARK_MOUNT 0x00000010 |
| 76 | #define FAN_MARK_FILESYSTEM 0x00000100 |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 77 | |
Amir Goldstein | 23c9dee | 2018-10-04 00:25:35 +0300 | [diff] [blame] | 78 | /* Deprecated - do not use this in programs and do not add new flags here! */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 79 | #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\ |
| 80 | FAN_MARK_REMOVE |\ |
| 81 | FAN_MARK_DONT_FOLLOW |\ |
| 82 | FAN_MARK_ONLYDIR |\ |
Amir Goldstein | 23c9dee | 2018-10-04 00:25:35 +0300 | [diff] [blame] | 83 | FAN_MARK_MOUNT |\ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 84 | FAN_MARK_IGNORED_MASK |\ |
| 85 | FAN_MARK_IGNORED_SURV_MODIFY |\ |
Amir Goldstein | 23c9dee | 2018-10-04 00:25:35 +0300 | [diff] [blame] | 86 | FAN_MARK_FLUSH) |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 87 | |
Amir Goldstein | 23c9dee | 2018-10-04 00:25:35 +0300 | [diff] [blame] | 88 | /* Deprecated - do not use this in programs and do not add new flags here! */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 89 | #define FAN_ALL_EVENTS (FAN_ACCESS |\ |
| 90 | FAN_MODIFY |\ |
| 91 | FAN_CLOSE |\ |
| 92 | FAN_OPEN) |
| 93 | |
| 94 | /* |
| 95 | * All events which require a permission response from userspace |
| 96 | */ |
Amir Goldstein | 23c9dee | 2018-10-04 00:25:35 +0300 | [diff] [blame] | 97 | /* Deprecated - do not use this in programs and do not add new flags here! */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 98 | #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\ |
| 99 | FAN_ACCESS_PERM) |
| 100 | |
Amir Goldstein | 23c9dee | 2018-10-04 00:25:35 +0300 | [diff] [blame] | 101 | /* Deprecated - do not use this in programs and do not add new flags here! */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 102 | #define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\ |
| 103 | FAN_ALL_PERM_EVENTS |\ |
| 104 | FAN_Q_OVERFLOW) |
| 105 | |
| 106 | #define FANOTIFY_METADATA_VERSION 3 |
| 107 | |
| 108 | struct fanotify_event_metadata { |
| 109 | __u32 event_len; |
| 110 | __u8 vers; |
| 111 | __u8 reserved; |
| 112 | __u16 metadata_len; |
| 113 | __aligned_u64 mask; |
| 114 | __s32 fd; |
| 115 | __s32 pid; |
| 116 | }; |
| 117 | |
Amir Goldstein | 5e469c8 | 2019-01-10 19:04:35 +0200 | [diff] [blame] | 118 | #define FAN_EVENT_INFO_TYPE_FID 1 |
| 119 | |
| 120 | /* Variable length info record following event metadata */ |
| 121 | struct fanotify_event_info_header { |
| 122 | __u8 info_type; |
| 123 | __u8 pad; |
| 124 | __u16 len; |
| 125 | }; |
| 126 | |
| 127 | /* Unique file identifier info record */ |
| 128 | struct fanotify_event_info_fid { |
| 129 | struct fanotify_event_info_header hdr; |
| 130 | __kernel_fsid_t fsid; |
| 131 | /* |
| 132 | * Following is an opaque struct file_handle that can be passed as |
| 133 | * an argument to open_by_handle_at(2). |
| 134 | */ |
| 135 | unsigned char handle[0]; |
| 136 | }; |
| 137 | |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 138 | struct fanotify_response { |
| 139 | __s32 fd; |
| 140 | __u32 response; |
| 141 | }; |
| 142 | |
| 143 | /* Legit userspace responses to a _PERM event */ |
| 144 | #define FAN_ALLOW 0x01 |
| 145 | #define FAN_DENY 0x02 |
Steve Grubb | de8cd83 | 2017-10-02 20:21:39 -0400 | [diff] [blame] | 146 | #define FAN_AUDIT 0x10 /* Bit mask to create audit record for result */ |
| 147 | |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 148 | /* No fd set in event */ |
| 149 | #define FAN_NOFD -1 |
| 150 | |
| 151 | /* Helper functions to deal with fanotify_event_metadata buffers */ |
| 152 | #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata)) |
| 153 | |
| 154 | #define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \ |
| 155 | (struct fanotify_event_metadata*)(((char *)(meta)) + \ |
| 156 | (meta)->event_len)) |
| 157 | |
| 158 | #define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \ |
| 159 | (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \ |
| 160 | (long)(meta)->event_len <= (long)(len)) |
| 161 | |
| 162 | #endif /* _UAPI_LINUX_FANOTIFY_H */ |