at v5.8 5.7 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 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 */ 10#define FAN_ATTRIB 0x00000004 /* Metadata changed */ 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 */ 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 */ 20#define FAN_OPEN_EXEC 0x00001000 /* File was opened for exec */ 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 */ 26#define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */ 27#define FAN_DIR_MODIFY 0x00080000 /* Directory entry was modified */ 28 29#define FAN_EVENT_ON_CHILD 0x08000000 /* Interested in child events */ 30 31#define FAN_ONDIR 0x40000000 /* Event occurred against dir */ 32 33/* helper events */ 34#define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */ 35#define FAN_MOVE (FAN_MOVED_FROM | FAN_MOVED_TO) /* moves */ 36 37/* flags used for fanotify_init() */ 38#define FAN_CLOEXEC 0x00000001 39#define FAN_NONBLOCK 0x00000002 40 41/* These are NOT bitwise flags. Both bits are used together. */ 42#define FAN_CLASS_NOTIF 0x00000000 43#define FAN_CLASS_CONTENT 0x00000004 44#define FAN_CLASS_PRE_CONTENT 0x00000008 45 46/* Deprecated - do not use this in programs and do not add new flags here! */ 47#define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ 48 FAN_CLASS_PRE_CONTENT) 49 50#define FAN_UNLIMITED_QUEUE 0x00000010 51#define FAN_UNLIMITED_MARKS 0x00000020 52#define FAN_ENABLE_AUDIT 0x00000040 53 54/* Flags to determine fanotify event format */ 55#define FAN_REPORT_TID 0x00000100 /* event->pid is thread id */ 56#define FAN_REPORT_FID 0x00000200 /* Report unique file id */ 57 58/* Deprecated - do not use this in programs and do not add new flags here! */ 59#define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \ 60 FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\ 61 FAN_UNLIMITED_MARKS) 62 63/* flags used for fanotify_modify_mark() */ 64#define FAN_MARK_ADD 0x00000001 65#define FAN_MARK_REMOVE 0x00000002 66#define FAN_MARK_DONT_FOLLOW 0x00000004 67#define FAN_MARK_ONLYDIR 0x00000008 68/* FAN_MARK_MOUNT is 0x00000010 */ 69#define FAN_MARK_IGNORED_MASK 0x00000020 70#define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040 71#define FAN_MARK_FLUSH 0x00000080 72/* FAN_MARK_FILESYSTEM is 0x00000100 */ 73 74/* These are NOT bitwise flags. Both bits can be used togther. */ 75#define FAN_MARK_INODE 0x00000000 76#define FAN_MARK_MOUNT 0x00000010 77#define FAN_MARK_FILESYSTEM 0x00000100 78 79/* Deprecated - do not use this in programs and do not add new flags here! */ 80#define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\ 81 FAN_MARK_REMOVE |\ 82 FAN_MARK_DONT_FOLLOW |\ 83 FAN_MARK_ONLYDIR |\ 84 FAN_MARK_MOUNT |\ 85 FAN_MARK_IGNORED_MASK |\ 86 FAN_MARK_IGNORED_SURV_MODIFY |\ 87 FAN_MARK_FLUSH) 88 89/* Deprecated - do not use this in programs and do not add new flags here! */ 90#define FAN_ALL_EVENTS (FAN_ACCESS |\ 91 FAN_MODIFY |\ 92 FAN_CLOSE |\ 93 FAN_OPEN) 94 95/* 96 * All events which require a permission response from userspace 97 */ 98/* Deprecated - do not use this in programs and do not add new flags here! */ 99#define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\ 100 FAN_ACCESS_PERM) 101 102/* Deprecated - do not use this in programs and do not add new flags here! */ 103#define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\ 104 FAN_ALL_PERM_EVENTS |\ 105 FAN_Q_OVERFLOW) 106 107#define FANOTIFY_METADATA_VERSION 3 108 109struct fanotify_event_metadata { 110 __u32 event_len; 111 __u8 vers; 112 __u8 reserved; 113 __u16 metadata_len; 114 __aligned_u64 mask; 115 __s32 fd; 116 __s32 pid; 117}; 118 119#define FAN_EVENT_INFO_TYPE_FID 1 120#define FAN_EVENT_INFO_TYPE_DFID_NAME 2 121 122/* Variable length info record following event metadata */ 123struct fanotify_event_info_header { 124 __u8 info_type; 125 __u8 pad; 126 __u16 len; 127}; 128 129/* 130 * Unique file identifier info record. This is used both for 131 * FAN_EVENT_INFO_TYPE_FID records and for FAN_EVENT_INFO_TYPE_DFID_NAME 132 * records. For FAN_EVENT_INFO_TYPE_DFID_NAME there is additionally a null 133 * terminated name immediately after the file handle. 134 */ 135struct fanotify_event_info_fid { 136 struct fanotify_event_info_header hdr; 137 __kernel_fsid_t fsid; 138 /* 139 * Following is an opaque struct file_handle that can be passed as 140 * an argument to open_by_handle_at(2). 141 */ 142 unsigned char handle[0]; 143}; 144 145struct fanotify_response { 146 __s32 fd; 147 __u32 response; 148}; 149 150/* Legit userspace responses to a _PERM event */ 151#define FAN_ALLOW 0x01 152#define FAN_DENY 0x02 153#define FAN_AUDIT 0x10 /* Bit mask to create audit record for result */ 154 155/* No fd set in event */ 156#define FAN_NOFD -1 157 158/* Helper functions to deal with fanotify_event_metadata buffers */ 159#define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata)) 160 161#define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \ 162 (struct fanotify_event_metadata*)(((char *)(meta)) + \ 163 (meta)->event_len)) 164 165#define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \ 166 (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \ 167 (long)(meta)->event_len <= (long)(len)) 168 169#endif /* _UAPI_LINUX_FANOTIFY_H */