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 */ 13*9b076f1cSMatthew 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 */ 19607ca46eSDavid Howells 20607ca46eSDavid Howells #define FAN_ONDIR 0x40000000 /* event occurred against dir */ 21607ca46eSDavid Howells 22607ca46eSDavid Howells #define FAN_EVENT_ON_CHILD 0x08000000 /* interested in child events */ 23607ca46eSDavid Howells 24607ca46eSDavid Howells /* helper events */ 25607ca46eSDavid Howells #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */ 26607ca46eSDavid Howells 27607ca46eSDavid Howells /* flags used for fanotify_init() */ 28607ca46eSDavid Howells #define FAN_CLOEXEC 0x00000001 29607ca46eSDavid Howells #define FAN_NONBLOCK 0x00000002 30607ca46eSDavid Howells 31d54f4fbaSAmir Goldstein /* These are NOT bitwise flags. Both bits are used together. */ 32607ca46eSDavid Howells #define FAN_CLASS_NOTIF 0x00000000 33607ca46eSDavid Howells #define FAN_CLASS_CONTENT 0x00000004 34607ca46eSDavid Howells #define FAN_CLASS_PRE_CONTENT 0x00000008 3523c9deebSAmir Goldstein 3623c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 37607ca46eSDavid Howells #define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ 38607ca46eSDavid Howells FAN_CLASS_PRE_CONTENT) 39607ca46eSDavid Howells 40607ca46eSDavid Howells #define FAN_UNLIMITED_QUEUE 0x00000010 41607ca46eSDavid Howells #define FAN_UNLIMITED_MARKS 0x00000020 42de8cd83eSSteve Grubb #define FAN_ENABLE_AUDIT 0x00000040 43607ca46eSDavid Howells 44d0a6a87eSAmir Goldstein /* Flags to determine fanotify event format */ 45d0a6a87eSAmir Goldstein #define FAN_REPORT_TID 0x00000100 /* event->pid is thread id */ 46d0a6a87eSAmir Goldstein 4723c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 48607ca46eSDavid Howells #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \ 49607ca46eSDavid Howells FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\ 50607ca46eSDavid Howells FAN_UNLIMITED_MARKS) 51607ca46eSDavid Howells 52607ca46eSDavid Howells /* flags used for fanotify_modify_mark() */ 53607ca46eSDavid Howells #define FAN_MARK_ADD 0x00000001 54607ca46eSDavid Howells #define FAN_MARK_REMOVE 0x00000002 55607ca46eSDavid Howells #define FAN_MARK_DONT_FOLLOW 0x00000004 56607ca46eSDavid Howells #define FAN_MARK_ONLYDIR 0x00000008 57d54f4fbaSAmir Goldstein /* FAN_MARK_MOUNT is 0x00000010 */ 58607ca46eSDavid Howells #define FAN_MARK_IGNORED_MASK 0x00000020 59607ca46eSDavid Howells #define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040 60607ca46eSDavid Howells #define FAN_MARK_FLUSH 0x00000080 61d54f4fbaSAmir Goldstein /* FAN_MARK_FILESYSTEM is 0x00000100 */ 62d54f4fbaSAmir Goldstein 63d54f4fbaSAmir Goldstein /* These are NOT bitwise flags. Both bits can be used togther. */ 64d54f4fbaSAmir Goldstein #define FAN_MARK_INODE 0x00000000 65d54f4fbaSAmir Goldstein #define FAN_MARK_MOUNT 0x00000010 66d54f4fbaSAmir Goldstein #define FAN_MARK_FILESYSTEM 0x00000100 67607ca46eSDavid Howells 6823c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 69607ca46eSDavid Howells #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\ 70607ca46eSDavid Howells FAN_MARK_REMOVE |\ 71607ca46eSDavid Howells FAN_MARK_DONT_FOLLOW |\ 72607ca46eSDavid Howells FAN_MARK_ONLYDIR |\ 7323c9deebSAmir Goldstein FAN_MARK_MOUNT |\ 74607ca46eSDavid Howells FAN_MARK_IGNORED_MASK |\ 75607ca46eSDavid Howells FAN_MARK_IGNORED_SURV_MODIFY |\ 7623c9deebSAmir Goldstein FAN_MARK_FLUSH) 77607ca46eSDavid Howells 7823c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 79607ca46eSDavid Howells #define FAN_ALL_EVENTS (FAN_ACCESS |\ 80607ca46eSDavid Howells FAN_MODIFY |\ 81607ca46eSDavid Howells FAN_CLOSE |\ 82607ca46eSDavid Howells FAN_OPEN) 83607ca46eSDavid Howells 84607ca46eSDavid Howells /* 85607ca46eSDavid Howells * All events which require a permission response from userspace 86607ca46eSDavid Howells */ 8723c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 88607ca46eSDavid Howells #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\ 89607ca46eSDavid Howells FAN_ACCESS_PERM) 90607ca46eSDavid Howells 9123c9deebSAmir Goldstein /* Deprecated - do not use this in programs and do not add new flags here! */ 92607ca46eSDavid Howells #define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\ 93607ca46eSDavid Howells FAN_ALL_PERM_EVENTS |\ 94607ca46eSDavid Howells FAN_Q_OVERFLOW) 95607ca46eSDavid Howells 96607ca46eSDavid Howells #define FANOTIFY_METADATA_VERSION 3 97607ca46eSDavid Howells 98607ca46eSDavid Howells struct fanotify_event_metadata { 99607ca46eSDavid Howells __u32 event_len; 100607ca46eSDavid Howells __u8 vers; 101607ca46eSDavid Howells __u8 reserved; 102607ca46eSDavid Howells __u16 metadata_len; 103607ca46eSDavid Howells __aligned_u64 mask; 104607ca46eSDavid Howells __s32 fd; 105607ca46eSDavid Howells __s32 pid; 106607ca46eSDavid Howells }; 107607ca46eSDavid Howells 108607ca46eSDavid Howells struct fanotify_response { 109607ca46eSDavid Howells __s32 fd; 110607ca46eSDavid Howells __u32 response; 111607ca46eSDavid Howells }; 112607ca46eSDavid Howells 113607ca46eSDavid Howells /* Legit userspace responses to a _PERM event */ 114607ca46eSDavid Howells #define FAN_ALLOW 0x01 115607ca46eSDavid Howells #define FAN_DENY 0x02 116de8cd83eSSteve Grubb #define FAN_AUDIT 0x10 /* Bit mask to create audit record for result */ 117de8cd83eSSteve Grubb 118607ca46eSDavid Howells /* No fd set in event */ 119607ca46eSDavid Howells #define FAN_NOFD -1 120607ca46eSDavid Howells 121607ca46eSDavid Howells /* Helper functions to deal with fanotify_event_metadata buffers */ 122607ca46eSDavid Howells #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata)) 123607ca46eSDavid Howells 124607ca46eSDavid Howells #define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \ 125607ca46eSDavid Howells (struct fanotify_event_metadata*)(((char *)(meta)) + \ 126607ca46eSDavid Howells (meta)->event_len)) 127607ca46eSDavid Howells 128607ca46eSDavid Howells #define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \ 129607ca46eSDavid Howells (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \ 130607ca46eSDavid Howells (long)(meta)->event_len <= (long)(len)) 131607ca46eSDavid Howells 132607ca46eSDavid Howells #endif /* _UAPI_LINUX_FANOTIFY_H */ 133