16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2607ca46eSDavid Howells #ifndef _UAPI_LINUX_FANOTIFY_H 3607ca46eSDavid Howells #define _UAPI_LINUX_FANOTIFY_H 4607ca46eSDavid Howells 5607ca46eSDavid Howells #include <linux/types.h> 6607ca46eSDavid Howells 7607ca46eSDavid Howells /* the following events that user-space can register for */ 8607ca46eSDavid Howells #define FAN_ACCESS 0x00000001 /* File was accessed */ 9607ca46eSDavid Howells #define FAN_MODIFY 0x00000002 /* File was modified */ 10235328d1SAmir Goldstein #define FAN_ATTRIB 0x00000004 /* Metadata changed */ 11607ca46eSDavid Howells #define FAN_CLOSE_WRITE 0x00000008 /* Writtable file closed */ 12607ca46eSDavid Howells #define FAN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */ 13607ca46eSDavid Howells #define FAN_OPEN 0x00000020 /* File was opened */ 14235328d1SAmir Goldstein #define FAN_MOVED_FROM 0x00000040 /* File was moved from X */ 15235328d1SAmir Goldstein #define FAN_MOVED_TO 0x00000080 /* File was moved to Y */ 16235328d1SAmir Goldstein #define FAN_CREATE 0x00000100 /* Subfile was created */ 17235328d1SAmir Goldstein #define FAN_DELETE 0x00000200 /* Subfile was deleted */ 18235328d1SAmir Goldstein #define FAN_DELETE_SELF 0x00000400 /* Self was deleted */ 19235328d1SAmir Goldstein #define FAN_MOVE_SELF 0x00000800 /* Self was moved */ 209b076f1cSMatthew Bobrowski #define FAN_OPEN_EXEC 0x00001000 /* File was opened for exec */ 21607ca46eSDavid Howells 22607ca46eSDavid Howells #define FAN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ 238d11a4f4SGabriel Krisman Bertazi #define FAN_FS_ERROR 0x00008000 /* Filesystem error */ 24607ca46eSDavid Howells 25607ca46eSDavid Howells #define FAN_OPEN_PERM 0x00010000 /* File open in perm check */ 26607ca46eSDavid Howells #define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */ 2766917a31SMatthew Bobrowski #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */ 28607ca46eSDavid Howells 296473ea76SAmir Goldstein #define FAN_EVENT_ON_CHILD 0x08000000 /* Interested in child events */ 30607ca46eSDavid Howells 313982534bSAmir Goldstein #define FAN_RENAME 0x10000000 /* File was renamed */ 323982534bSAmir Goldstein 336473ea76SAmir Goldstein #define FAN_ONDIR 0x40000000 /* Event occurred against dir */ 34607ca46eSDavid Howells 35607ca46eSDavid Howells /* helper events */ 36607ca46eSDavid Howells #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */ 37235328d1SAmir Goldstein #define FAN_MOVE (FAN_MOVED_FROM | FAN_MOVED_TO) /* moves */ 38607ca46eSDavid Howells 39607ca46eSDavid Howells /* flags used for fanotify_init() */ 40607ca46eSDavid Howells #define FAN_CLOEXEC 0x00000001 41607ca46eSDavid Howells #define FAN_NONBLOCK 0x00000002 42607ca46eSDavid Howells 43d54f4fbaSAmir Goldstein /* These are NOT bitwise flags. Both bits are used together. */ 44607ca46eSDavid Howells #define FAN_CLASS_NOTIF 0x00000000 45607ca46eSDavid Howells #define FAN_CLASS_CONTENT 0x00000004 46607ca46eSDavid Howells #define FAN_CLASS_PRE_CONTENT 0x00000008 4723c9deebSAmir Goldstein 4823c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 49607ca46eSDavid Howells #define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ 50607ca46eSDavid Howells FAN_CLASS_PRE_CONTENT) 51607ca46eSDavid Howells 52607ca46eSDavid Howells #define FAN_UNLIMITED_QUEUE 0x00000010 53607ca46eSDavid Howells #define FAN_UNLIMITED_MARKS 0x00000020 54de8cd83eSSteve Grubb #define FAN_ENABLE_AUDIT 0x00000040 55607ca46eSDavid Howells 56d0a6a87eSAmir Goldstein /* Flags to determine fanotify event format */ 57af579bebSMatthew Bobrowski #define FAN_REPORT_PIDFD 0x00000080 /* Report pidfd for event->pid */ 58d0a6a87eSAmir Goldstein #define FAN_REPORT_TID 0x00000100 /* event->pid is thread id */ 59e9e0c890SAmir Goldstein #define FAN_REPORT_FID 0x00000200 /* Report unique file id */ 6083b7a598SAmir Goldstein #define FAN_REPORT_DIR_FID 0x00000400 /* Report unique directory id */ 61929943b3SAmir Goldstein #define FAN_REPORT_NAME 0x00000800 /* Report events with name */ 62d61fd650SAmir Goldstein #define FAN_REPORT_TARGET_FID 0x00001000 /* Report dirent target id */ 63929943b3SAmir Goldstein 64929943b3SAmir Goldstein /* Convenience macro - FAN_REPORT_NAME requires FAN_REPORT_DIR_FID */ 65929943b3SAmir Goldstein #define FAN_REPORT_DFID_NAME (FAN_REPORT_DIR_FID | FAN_REPORT_NAME) 66d61fd650SAmir Goldstein /* Convenience macro - FAN_REPORT_TARGET_FID requires all other FID flags */ 67d61fd650SAmir Goldstein #define FAN_REPORT_DFID_NAME_TARGET (FAN_REPORT_DFID_NAME | \ 68d61fd650SAmir Goldstein FAN_REPORT_FID | FAN_REPORT_TARGET_FID) 69d0a6a87eSAmir Goldstein 7023c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 71607ca46eSDavid Howells #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \ 72607ca46eSDavid Howells FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\ 73607ca46eSDavid Howells FAN_UNLIMITED_MARKS) 74607ca46eSDavid Howells 75607ca46eSDavid Howells /* flags used for fanotify_modify_mark() */ 76607ca46eSDavid Howells #define FAN_MARK_ADD 0x00000001 77607ca46eSDavid Howells #define FAN_MARK_REMOVE 0x00000002 78607ca46eSDavid Howells #define FAN_MARK_DONT_FOLLOW 0x00000004 79607ca46eSDavid Howells #define FAN_MARK_ONLYDIR 0x00000008 80d54f4fbaSAmir Goldstein /* FAN_MARK_MOUNT is 0x00000010 */ 81607ca46eSDavid Howells #define FAN_MARK_IGNORED_MASK 0x00000020 82607ca46eSDavid Howells #define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040 83607ca46eSDavid Howells #define FAN_MARK_FLUSH 0x00000080 84d54f4fbaSAmir Goldstein /* FAN_MARK_FILESYSTEM is 0x00000100 */ 857d5e005dSAmir Goldstein #define FAN_MARK_EVICTABLE 0x00000200 86d54f4fbaSAmir Goldstein 87d54f4fbaSAmir Goldstein /* These are NOT bitwise flags. Both bits can be used togther. */ 88d54f4fbaSAmir Goldstein #define FAN_MARK_INODE 0x00000000 89d54f4fbaSAmir Goldstein #define FAN_MARK_MOUNT 0x00000010 90d54f4fbaSAmir Goldstein #define FAN_MARK_FILESYSTEM 0x00000100 91607ca46eSDavid Howells 9223c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 93607ca46eSDavid Howells #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\ 94607ca46eSDavid Howells FAN_MARK_REMOVE |\ 95607ca46eSDavid Howells FAN_MARK_DONT_FOLLOW |\ 96607ca46eSDavid Howells FAN_MARK_ONLYDIR |\ 9723c9deebSAmir Goldstein FAN_MARK_MOUNT |\ 98607ca46eSDavid Howells FAN_MARK_IGNORED_MASK |\ 99607ca46eSDavid Howells FAN_MARK_IGNORED_SURV_MODIFY |\ 10023c9deebSAmir Goldstein FAN_MARK_FLUSH) 101607ca46eSDavid Howells 10223c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 103607ca46eSDavid Howells #define FAN_ALL_EVENTS (FAN_ACCESS |\ 104607ca46eSDavid Howells FAN_MODIFY |\ 105607ca46eSDavid Howells FAN_CLOSE |\ 106607ca46eSDavid Howells FAN_OPEN) 107607ca46eSDavid Howells 108607ca46eSDavid Howells /* 109607ca46eSDavid Howells * All events which require a permission response from userspace 110607ca46eSDavid Howells */ 11123c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 112607ca46eSDavid Howells #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\ 113607ca46eSDavid Howells FAN_ACCESS_PERM) 114607ca46eSDavid Howells 11523c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 116607ca46eSDavid Howells #define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\ 117607ca46eSDavid Howells FAN_ALL_PERM_EVENTS |\ 118607ca46eSDavid Howells FAN_Q_OVERFLOW) 119607ca46eSDavid Howells 120607ca46eSDavid Howells #define FANOTIFY_METADATA_VERSION 3 121607ca46eSDavid Howells 122607ca46eSDavid Howells struct fanotify_event_metadata { 123607ca46eSDavid Howells __u32 event_len; 124607ca46eSDavid Howells __u8 vers; 125607ca46eSDavid Howells __u8 reserved; 126607ca46eSDavid Howells __u16 metadata_len; 127607ca46eSDavid Howells __aligned_u64 mask; 128607ca46eSDavid Howells __s32 fd; 129607ca46eSDavid Howells __s32 pid; 130607ca46eSDavid Howells }; 131607ca46eSDavid Howells 1325e469c83SAmir Goldstein #define FAN_EVENT_INFO_TYPE_FID 1 13344d705b0SAmir Goldstein #define FAN_EVENT_INFO_TYPE_DFID_NAME 2 13483b7a598SAmir Goldstein #define FAN_EVENT_INFO_TYPE_DFID 3 135af579bebSMatthew Bobrowski #define FAN_EVENT_INFO_TYPE_PIDFD 4 136130a3c74SGabriel Krisman Bertazi #define FAN_EVENT_INFO_TYPE_ERROR 5 1375e469c83SAmir Goldstein 1387326e382SAmir Goldstein /* Special info types for FAN_RENAME */ 1397326e382SAmir Goldstein #define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME 10 1407326e382SAmir Goldstein /* Reserved for FAN_EVENT_INFO_TYPE_OLD_DFID 11 */ 1417326e382SAmir Goldstein #define FAN_EVENT_INFO_TYPE_NEW_DFID_NAME 12 1427326e382SAmir Goldstein /* Reserved for FAN_EVENT_INFO_TYPE_NEW_DFID 13 */ 1437326e382SAmir Goldstein 1445e469c83SAmir Goldstein /* Variable length info record following event metadata */ 1455e469c83SAmir Goldstein struct fanotify_event_info_header { 1465e469c83SAmir Goldstein __u8 info_type; 1475e469c83SAmir Goldstein __u8 pad; 1485e469c83SAmir Goldstein __u16 len; 1495e469c83SAmir Goldstein }; 1505e469c83SAmir Goldstein 15144d705b0SAmir Goldstein /* 15283b7a598SAmir Goldstein * Unique file identifier info record. 15383b7a598SAmir Goldstein * This structure is used for records of types FAN_EVENT_INFO_TYPE_FID, 15483b7a598SAmir Goldstein * FAN_EVENT_INFO_TYPE_DFID and FAN_EVENT_INFO_TYPE_DFID_NAME. 15583b7a598SAmir Goldstein * For FAN_EVENT_INFO_TYPE_DFID_NAME there is additionally a null terminated 15683b7a598SAmir Goldstein * name immediately after the file handle. 15744d705b0SAmir Goldstein */ 1585e469c83SAmir Goldstein struct fanotify_event_info_fid { 1595e469c83SAmir Goldstein struct fanotify_event_info_header hdr; 1605e469c83SAmir Goldstein __kernel_fsid_t fsid; 1615e469c83SAmir Goldstein /* 1625e469c83SAmir Goldstein * Following is an opaque struct file_handle that can be passed as 1635e469c83SAmir Goldstein * an argument to open_by_handle_at(2). 1645e469c83SAmir Goldstein */ 165*94dfc73eSGustavo A. R. Silva unsigned char handle[]; 1665e469c83SAmir Goldstein }; 1675e469c83SAmir Goldstein 168af579bebSMatthew Bobrowski /* 169af579bebSMatthew Bobrowski * This structure is used for info records of type FAN_EVENT_INFO_TYPE_PIDFD. 170af579bebSMatthew Bobrowski * It holds a pidfd for the pid that was responsible for generating an event. 171af579bebSMatthew Bobrowski */ 172af579bebSMatthew Bobrowski struct fanotify_event_info_pidfd { 173af579bebSMatthew Bobrowski struct fanotify_event_info_header hdr; 174af579bebSMatthew Bobrowski __s32 pidfd; 175af579bebSMatthew Bobrowski }; 176af579bebSMatthew Bobrowski 177130a3c74SGabriel Krisman Bertazi struct fanotify_event_info_error { 178130a3c74SGabriel Krisman Bertazi struct fanotify_event_info_header hdr; 179130a3c74SGabriel Krisman Bertazi __s32 error; 180130a3c74SGabriel Krisman Bertazi __u32 error_count; 181130a3c74SGabriel Krisman Bertazi }; 182130a3c74SGabriel Krisman Bertazi 183607ca46eSDavid Howells struct fanotify_response { 184607ca46eSDavid Howells __s32 fd; 185607ca46eSDavid Howells __u32 response; 186607ca46eSDavid Howells }; 187607ca46eSDavid Howells 188607ca46eSDavid Howells /* Legit userspace responses to a _PERM event */ 189607ca46eSDavid Howells #define FAN_ALLOW 0x01 190607ca46eSDavid Howells #define FAN_DENY 0x02 191de8cd83eSSteve Grubb #define FAN_AUDIT 0x10 /* Bit mask to create audit record for result */ 192de8cd83eSSteve Grubb 193607ca46eSDavid Howells /* No fd set in event */ 194607ca46eSDavid Howells #define FAN_NOFD -1 195af579bebSMatthew Bobrowski #define FAN_NOPIDFD FAN_NOFD 196af579bebSMatthew Bobrowski #define FAN_EPIDFD -2 197607ca46eSDavid Howells 198607ca46eSDavid Howells /* Helper functions to deal with fanotify_event_metadata buffers */ 199607ca46eSDavid Howells #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata)) 200607ca46eSDavid Howells 201607ca46eSDavid Howells #define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \ 202607ca46eSDavid Howells (struct fanotify_event_metadata*)(((char *)(meta)) + \ 203607ca46eSDavid Howells (meta)->event_len)) 204607ca46eSDavid Howells 205607ca46eSDavid Howells #define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \ 206607ca46eSDavid Howells (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \ 207607ca46eSDavid Howells (long)(meta)->event_len <= (long)(len)) 208607ca46eSDavid Howells 209607ca46eSDavid Howells #endif /* _UAPI_LINUX_FANOTIFY_H */ 210