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 */ 10607ca46eSDavid Howells #define FAN_CLOSE_WRITE 0x00000008 /* Writtable file closed */ 11607ca46eSDavid Howells #define FAN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */ 12607ca46eSDavid Howells #define FAN_OPEN 0x00000020 /* File was opened */ 139b076f1cSMatthew Bobrowski #define FAN_OPEN_EXEC 0x00001000 /* File was opened for exec */ 14607ca46eSDavid Howells 15607ca46eSDavid Howells #define FAN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ 16607ca46eSDavid Howells 17607ca46eSDavid Howells #define FAN_OPEN_PERM 0x00010000 /* File open in perm check */ 18607ca46eSDavid Howells #define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */ 19*66917a31SMatthew Bobrowski #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */ 20607ca46eSDavid Howells 21607ca46eSDavid Howells #define FAN_ONDIR 0x40000000 /* event occurred against dir */ 22607ca46eSDavid Howells 23607ca46eSDavid Howells #define FAN_EVENT_ON_CHILD 0x08000000 /* interested in child events */ 24607ca46eSDavid Howells 25607ca46eSDavid Howells /* helper events */ 26607ca46eSDavid Howells #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */ 27607ca46eSDavid Howells 28607ca46eSDavid Howells /* flags used for fanotify_init() */ 29607ca46eSDavid Howells #define FAN_CLOEXEC 0x00000001 30607ca46eSDavid Howells #define FAN_NONBLOCK 0x00000002 31607ca46eSDavid Howells 32d54f4fbaSAmir Goldstein /* These are NOT bitwise flags. Both bits are used together. */ 33607ca46eSDavid Howells #define FAN_CLASS_NOTIF 0x00000000 34607ca46eSDavid Howells #define FAN_CLASS_CONTENT 0x00000004 35607ca46eSDavid Howells #define FAN_CLASS_PRE_CONTENT 0x00000008 3623c9deebSAmir Goldstein 3723c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 38607ca46eSDavid Howells #define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ 39607ca46eSDavid Howells FAN_CLASS_PRE_CONTENT) 40607ca46eSDavid Howells 41607ca46eSDavid Howells #define FAN_UNLIMITED_QUEUE 0x00000010 42607ca46eSDavid Howells #define FAN_UNLIMITED_MARKS 0x00000020 43de8cd83eSSteve Grubb #define FAN_ENABLE_AUDIT 0x00000040 44607ca46eSDavid Howells 45d0a6a87eSAmir Goldstein /* Flags to determine fanotify event format */ 46d0a6a87eSAmir Goldstein #define FAN_REPORT_TID 0x00000100 /* event->pid is thread id */ 47d0a6a87eSAmir Goldstein 4823c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 49607ca46eSDavid Howells #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \ 50607ca46eSDavid Howells FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\ 51607ca46eSDavid Howells FAN_UNLIMITED_MARKS) 52607ca46eSDavid Howells 53607ca46eSDavid Howells /* flags used for fanotify_modify_mark() */ 54607ca46eSDavid Howells #define FAN_MARK_ADD 0x00000001 55607ca46eSDavid Howells #define FAN_MARK_REMOVE 0x00000002 56607ca46eSDavid Howells #define FAN_MARK_DONT_FOLLOW 0x00000004 57607ca46eSDavid Howells #define FAN_MARK_ONLYDIR 0x00000008 58d54f4fbaSAmir Goldstein /* FAN_MARK_MOUNT is 0x00000010 */ 59607ca46eSDavid Howells #define FAN_MARK_IGNORED_MASK 0x00000020 60607ca46eSDavid Howells #define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040 61607ca46eSDavid Howells #define FAN_MARK_FLUSH 0x00000080 62d54f4fbaSAmir Goldstein /* FAN_MARK_FILESYSTEM is 0x00000100 */ 63d54f4fbaSAmir Goldstein 64d54f4fbaSAmir Goldstein /* These are NOT bitwise flags. Both bits can be used togther. */ 65d54f4fbaSAmir Goldstein #define FAN_MARK_INODE 0x00000000 66d54f4fbaSAmir Goldstein #define FAN_MARK_MOUNT 0x00000010 67d54f4fbaSAmir Goldstein #define FAN_MARK_FILESYSTEM 0x00000100 68607ca46eSDavid Howells 6923c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 70607ca46eSDavid Howells #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\ 71607ca46eSDavid Howells FAN_MARK_REMOVE |\ 72607ca46eSDavid Howells FAN_MARK_DONT_FOLLOW |\ 73607ca46eSDavid Howells FAN_MARK_ONLYDIR |\ 7423c9deebSAmir Goldstein FAN_MARK_MOUNT |\ 75607ca46eSDavid Howells FAN_MARK_IGNORED_MASK |\ 76607ca46eSDavid Howells FAN_MARK_IGNORED_SURV_MODIFY |\ 7723c9deebSAmir Goldstein FAN_MARK_FLUSH) 78607ca46eSDavid Howells 7923c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 80607ca46eSDavid Howells #define FAN_ALL_EVENTS (FAN_ACCESS |\ 81607ca46eSDavid Howells FAN_MODIFY |\ 82607ca46eSDavid Howells FAN_CLOSE |\ 83607ca46eSDavid Howells FAN_OPEN) 84607ca46eSDavid Howells 85607ca46eSDavid Howells /* 86607ca46eSDavid Howells * All events which require a permission response from userspace 87607ca46eSDavid Howells */ 8823c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 89607ca46eSDavid Howells #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\ 90607ca46eSDavid Howells FAN_ACCESS_PERM) 91607ca46eSDavid Howells 9223c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 93607ca46eSDavid Howells #define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\ 94607ca46eSDavid Howells FAN_ALL_PERM_EVENTS |\ 95607ca46eSDavid Howells FAN_Q_OVERFLOW) 96607ca46eSDavid Howells 97607ca46eSDavid Howells #define FANOTIFY_METADATA_VERSION 3 98607ca46eSDavid Howells 99607ca46eSDavid Howells struct fanotify_event_metadata { 100607ca46eSDavid Howells __u32 event_len; 101607ca46eSDavid Howells __u8 vers; 102607ca46eSDavid Howells __u8 reserved; 103607ca46eSDavid Howells __u16 metadata_len; 104607ca46eSDavid Howells __aligned_u64 mask; 105607ca46eSDavid Howells __s32 fd; 106607ca46eSDavid Howells __s32 pid; 107607ca46eSDavid Howells }; 108607ca46eSDavid Howells 109607ca46eSDavid Howells struct fanotify_response { 110607ca46eSDavid Howells __s32 fd; 111607ca46eSDavid Howells __u32 response; 112607ca46eSDavid Howells }; 113607ca46eSDavid Howells 114607ca46eSDavid Howells /* Legit userspace responses to a _PERM event */ 115607ca46eSDavid Howells #define FAN_ALLOW 0x01 116607ca46eSDavid Howells #define FAN_DENY 0x02 117de8cd83eSSteve Grubb #define FAN_AUDIT 0x10 /* Bit mask to create audit record for result */ 118de8cd83eSSteve Grubb 119607ca46eSDavid Howells /* No fd set in event */ 120607ca46eSDavid Howells #define FAN_NOFD -1 121607ca46eSDavid Howells 122607ca46eSDavid Howells /* Helper functions to deal with fanotify_event_metadata buffers */ 123607ca46eSDavid Howells #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata)) 124607ca46eSDavid Howells 125607ca46eSDavid Howells #define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \ 126607ca46eSDavid Howells (struct fanotify_event_metadata*)(((char *)(meta)) + \ 127607ca46eSDavid Howells (meta)->event_len)) 128607ca46eSDavid Howells 129607ca46eSDavid Howells #define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \ 130607ca46eSDavid Howells (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \ 131607ca46eSDavid Howells (long)(meta)->event_len <= (long)(len)) 132607ca46eSDavid Howells 133607ca46eSDavid Howells #endif /* _UAPI_LINUX_FANOTIFY_H */ 134