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 316473ea76SAmir Goldstein #define FAN_ONDIR 0x40000000 /* Event occurred against dir */ 32607ca46eSDavid Howells 33607ca46eSDavid Howells /* helper events */ 34607ca46eSDavid Howells #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */ 35235328d1SAmir Goldstein #define FAN_MOVE (FAN_MOVED_FROM | FAN_MOVED_TO) /* moves */ 36607ca46eSDavid Howells 37607ca46eSDavid Howells /* flags used for fanotify_init() */ 38607ca46eSDavid Howells #define FAN_CLOEXEC 0x00000001 39607ca46eSDavid Howells #define FAN_NONBLOCK 0x00000002 40607ca46eSDavid Howells 41d54f4fbaSAmir Goldstein /* These are NOT bitwise flags. Both bits are used together. */ 42607ca46eSDavid Howells #define FAN_CLASS_NOTIF 0x00000000 43607ca46eSDavid Howells #define FAN_CLASS_CONTENT 0x00000004 44607ca46eSDavid Howells #define FAN_CLASS_PRE_CONTENT 0x00000008 4523c9deebSAmir Goldstein 4623c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 47607ca46eSDavid Howells #define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ 48607ca46eSDavid Howells FAN_CLASS_PRE_CONTENT) 49607ca46eSDavid Howells 50607ca46eSDavid Howells #define FAN_UNLIMITED_QUEUE 0x00000010 51607ca46eSDavid Howells #define FAN_UNLIMITED_MARKS 0x00000020 52de8cd83eSSteve Grubb #define FAN_ENABLE_AUDIT 0x00000040 53607ca46eSDavid Howells 54d0a6a87eSAmir Goldstein /* Flags to determine fanotify event format */ 55af579bebSMatthew Bobrowski #define FAN_REPORT_PIDFD 0x00000080 /* Report pidfd for event->pid */ 56d0a6a87eSAmir Goldstein #define FAN_REPORT_TID 0x00000100 /* event->pid is thread id */ 57e9e0c890SAmir Goldstein #define FAN_REPORT_FID 0x00000200 /* Report unique file id */ 5883b7a598SAmir Goldstein #define FAN_REPORT_DIR_FID 0x00000400 /* Report unique directory id */ 59929943b3SAmir Goldstein #define FAN_REPORT_NAME 0x00000800 /* Report events with name */ 60929943b3SAmir Goldstein 61929943b3SAmir Goldstein /* Convenience macro - FAN_REPORT_NAME requires FAN_REPORT_DIR_FID */ 62929943b3SAmir Goldstein #define FAN_REPORT_DFID_NAME (FAN_REPORT_DIR_FID | FAN_REPORT_NAME) 63d0a6a87eSAmir Goldstein 6423c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 65607ca46eSDavid Howells #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \ 66607ca46eSDavid Howells FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\ 67607ca46eSDavid Howells FAN_UNLIMITED_MARKS) 68607ca46eSDavid Howells 69607ca46eSDavid Howells /* flags used for fanotify_modify_mark() */ 70607ca46eSDavid Howells #define FAN_MARK_ADD 0x00000001 71607ca46eSDavid Howells #define FAN_MARK_REMOVE 0x00000002 72607ca46eSDavid Howells #define FAN_MARK_DONT_FOLLOW 0x00000004 73607ca46eSDavid Howells #define FAN_MARK_ONLYDIR 0x00000008 74d54f4fbaSAmir Goldstein /* FAN_MARK_MOUNT is 0x00000010 */ 75607ca46eSDavid Howells #define FAN_MARK_IGNORED_MASK 0x00000020 76607ca46eSDavid Howells #define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040 77607ca46eSDavid Howells #define FAN_MARK_FLUSH 0x00000080 78d54f4fbaSAmir Goldstein /* FAN_MARK_FILESYSTEM is 0x00000100 */ 79d54f4fbaSAmir Goldstein 80d54f4fbaSAmir Goldstein /* These are NOT bitwise flags. Both bits can be used togther. */ 81d54f4fbaSAmir Goldstein #define FAN_MARK_INODE 0x00000000 82d54f4fbaSAmir Goldstein #define FAN_MARK_MOUNT 0x00000010 83d54f4fbaSAmir Goldstein #define FAN_MARK_FILESYSTEM 0x00000100 84607ca46eSDavid Howells 8523c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 86607ca46eSDavid Howells #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\ 87607ca46eSDavid Howells FAN_MARK_REMOVE |\ 88607ca46eSDavid Howells FAN_MARK_DONT_FOLLOW |\ 89607ca46eSDavid Howells FAN_MARK_ONLYDIR |\ 9023c9deebSAmir Goldstein FAN_MARK_MOUNT |\ 91607ca46eSDavid Howells FAN_MARK_IGNORED_MASK |\ 92607ca46eSDavid Howells FAN_MARK_IGNORED_SURV_MODIFY |\ 9323c9deebSAmir Goldstein FAN_MARK_FLUSH) 94607ca46eSDavid Howells 9523c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 96607ca46eSDavid Howells #define FAN_ALL_EVENTS (FAN_ACCESS |\ 97607ca46eSDavid Howells FAN_MODIFY |\ 98607ca46eSDavid Howells FAN_CLOSE |\ 99607ca46eSDavid Howells FAN_OPEN) 100607ca46eSDavid Howells 101607ca46eSDavid Howells /* 102607ca46eSDavid Howells * All events which require a permission response from userspace 103607ca46eSDavid Howells */ 10423c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 105607ca46eSDavid Howells #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\ 106607ca46eSDavid Howells FAN_ACCESS_PERM) 107607ca46eSDavid Howells 10823c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 109607ca46eSDavid Howells #define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\ 110607ca46eSDavid Howells FAN_ALL_PERM_EVENTS |\ 111607ca46eSDavid Howells FAN_Q_OVERFLOW) 112607ca46eSDavid Howells 113607ca46eSDavid Howells #define FANOTIFY_METADATA_VERSION 3 114607ca46eSDavid Howells 115607ca46eSDavid Howells struct fanotify_event_metadata { 116607ca46eSDavid Howells __u32 event_len; 117607ca46eSDavid Howells __u8 vers; 118607ca46eSDavid Howells __u8 reserved; 119607ca46eSDavid Howells __u16 metadata_len; 120607ca46eSDavid Howells __aligned_u64 mask; 121607ca46eSDavid Howells __s32 fd; 122607ca46eSDavid Howells __s32 pid; 123607ca46eSDavid Howells }; 124607ca46eSDavid Howells 1255e469c83SAmir Goldstein #define FAN_EVENT_INFO_TYPE_FID 1 12644d705b0SAmir Goldstein #define FAN_EVENT_INFO_TYPE_DFID_NAME 2 12783b7a598SAmir Goldstein #define FAN_EVENT_INFO_TYPE_DFID 3 128af579bebSMatthew Bobrowski #define FAN_EVENT_INFO_TYPE_PIDFD 4 129*130a3c74SGabriel Krisman Bertazi #define FAN_EVENT_INFO_TYPE_ERROR 5 1305e469c83SAmir Goldstein 1315e469c83SAmir Goldstein /* Variable length info record following event metadata */ 1325e469c83SAmir Goldstein struct fanotify_event_info_header { 1335e469c83SAmir Goldstein __u8 info_type; 1345e469c83SAmir Goldstein __u8 pad; 1355e469c83SAmir Goldstein __u16 len; 1365e469c83SAmir Goldstein }; 1375e469c83SAmir Goldstein 13844d705b0SAmir Goldstein /* 13983b7a598SAmir Goldstein * Unique file identifier info record. 14083b7a598SAmir Goldstein * This structure is used for records of types FAN_EVENT_INFO_TYPE_FID, 14183b7a598SAmir Goldstein * FAN_EVENT_INFO_TYPE_DFID and FAN_EVENT_INFO_TYPE_DFID_NAME. 14283b7a598SAmir Goldstein * For FAN_EVENT_INFO_TYPE_DFID_NAME there is additionally a null terminated 14383b7a598SAmir Goldstein * name immediately after the file handle. 14444d705b0SAmir Goldstein */ 1455e469c83SAmir Goldstein struct fanotify_event_info_fid { 1465e469c83SAmir Goldstein struct fanotify_event_info_header hdr; 1475e469c83SAmir Goldstein __kernel_fsid_t fsid; 1485e469c83SAmir Goldstein /* 1495e469c83SAmir Goldstein * Following is an opaque struct file_handle that can be passed as 1505e469c83SAmir Goldstein * an argument to open_by_handle_at(2). 1515e469c83SAmir Goldstein */ 1525e469c83SAmir Goldstein unsigned char handle[0]; 1535e469c83SAmir Goldstein }; 1545e469c83SAmir Goldstein 155af579bebSMatthew Bobrowski /* 156af579bebSMatthew Bobrowski * This structure is used for info records of type FAN_EVENT_INFO_TYPE_PIDFD. 157af579bebSMatthew Bobrowski * It holds a pidfd for the pid that was responsible for generating an event. 158af579bebSMatthew Bobrowski */ 159af579bebSMatthew Bobrowski struct fanotify_event_info_pidfd { 160af579bebSMatthew Bobrowski struct fanotify_event_info_header hdr; 161af579bebSMatthew Bobrowski __s32 pidfd; 162af579bebSMatthew Bobrowski }; 163af579bebSMatthew Bobrowski 164*130a3c74SGabriel Krisman Bertazi struct fanotify_event_info_error { 165*130a3c74SGabriel Krisman Bertazi struct fanotify_event_info_header hdr; 166*130a3c74SGabriel Krisman Bertazi __s32 error; 167*130a3c74SGabriel Krisman Bertazi __u32 error_count; 168*130a3c74SGabriel Krisman Bertazi }; 169*130a3c74SGabriel Krisman Bertazi 170607ca46eSDavid Howells struct fanotify_response { 171607ca46eSDavid Howells __s32 fd; 172607ca46eSDavid Howells __u32 response; 173607ca46eSDavid Howells }; 174607ca46eSDavid Howells 175607ca46eSDavid Howells /* Legit userspace responses to a _PERM event */ 176607ca46eSDavid Howells #define FAN_ALLOW 0x01 177607ca46eSDavid Howells #define FAN_DENY 0x02 178de8cd83eSSteve Grubb #define FAN_AUDIT 0x10 /* Bit mask to create audit record for result */ 179de8cd83eSSteve Grubb 180607ca46eSDavid Howells /* No fd set in event */ 181607ca46eSDavid Howells #define FAN_NOFD -1 182af579bebSMatthew Bobrowski #define FAN_NOPIDFD FAN_NOFD 183af579bebSMatthew Bobrowski #define FAN_EPIDFD -2 184607ca46eSDavid Howells 185607ca46eSDavid Howells /* Helper functions to deal with fanotify_event_metadata buffers */ 186607ca46eSDavid Howells #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata)) 187607ca46eSDavid Howells 188607ca46eSDavid Howells #define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \ 189607ca46eSDavid Howells (struct fanotify_event_metadata*)(((char *)(meta)) + \ 190607ca46eSDavid Howells (meta)->event_len)) 191607ca46eSDavid Howells 192607ca46eSDavid Howells #define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \ 193607ca46eSDavid Howells (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \ 194607ca46eSDavid Howells (long)(meta)->event_len <= (long)(len)) 195607ca46eSDavid Howells 196607ca46eSDavid Howells #endif /* _UAPI_LINUX_FANOTIFY_H */ 197