1570af302Sopenharmony_ci#ifndef _FANOTIFY_H 2570af302Sopenharmony_ci#define _FANOTIFY_H 3570af302Sopenharmony_ci 4570af302Sopenharmony_ci#ifdef __cplusplus 5570af302Sopenharmony_ciextern "C" { 6570af302Sopenharmony_ci#endif 7570af302Sopenharmony_ci 8570af302Sopenharmony_ci#include <sys/statfs.h> 9570af302Sopenharmony_ci 10570af302Sopenharmony_cistruct fanotify_event_metadata { 11570af302Sopenharmony_ci unsigned event_len; 12570af302Sopenharmony_ci unsigned char vers; 13570af302Sopenharmony_ci unsigned char reserved; 14570af302Sopenharmony_ci unsigned short metadata_len; 15570af302Sopenharmony_ci unsigned long long mask 16570af302Sopenharmony_ci#ifdef __GNUC__ 17570af302Sopenharmony_ci __attribute__((__aligned__(8))) 18570af302Sopenharmony_ci#endif 19570af302Sopenharmony_ci ; 20570af302Sopenharmony_ci int fd; 21570af302Sopenharmony_ci int pid; 22570af302Sopenharmony_ci}; 23570af302Sopenharmony_ci 24570af302Sopenharmony_cistruct fanotify_event_info_header { 25570af302Sopenharmony_ci unsigned char info_type; 26570af302Sopenharmony_ci unsigned char pad; 27570af302Sopenharmony_ci unsigned short len; 28570af302Sopenharmony_ci}; 29570af302Sopenharmony_ci 30570af302Sopenharmony_cistruct fanotify_event_info_fid { 31570af302Sopenharmony_ci struct fanotify_event_info_header hdr; 32570af302Sopenharmony_ci fsid_t fsid; 33570af302Sopenharmony_ci unsigned char handle[]; 34570af302Sopenharmony_ci}; 35570af302Sopenharmony_ci 36570af302Sopenharmony_cistruct fanotify_response { 37570af302Sopenharmony_ci int fd; 38570af302Sopenharmony_ci unsigned response; 39570af302Sopenharmony_ci}; 40570af302Sopenharmony_ci 41570af302Sopenharmony_ci#define FAN_ACCESS 0x01 42570af302Sopenharmony_ci#define FAN_MODIFY 0x02 43570af302Sopenharmony_ci#define FAN_ATTRIB 0x04 44570af302Sopenharmony_ci#define FAN_CLOSE_WRITE 0x08 45570af302Sopenharmony_ci#define FAN_CLOSE_NOWRITE 0x10 46570af302Sopenharmony_ci#define FAN_OPEN 0x20 47570af302Sopenharmony_ci#define FAN_MOVED_FROM 0x40 48570af302Sopenharmony_ci#define FAN_MOVED_TO 0x80 49570af302Sopenharmony_ci#define FAN_CREATE 0x100 50570af302Sopenharmony_ci#define FAN_DELETE 0x200 51570af302Sopenharmony_ci#define FAN_DELETE_SELF 0x400 52570af302Sopenharmony_ci#define FAN_MOVE_SELF 0x800 53570af302Sopenharmony_ci#define FAN_OPEN_EXEC 0x1000 54570af302Sopenharmony_ci#define FAN_Q_OVERFLOW 0x4000 55570af302Sopenharmony_ci#define FAN_OPEN_PERM 0x10000 56570af302Sopenharmony_ci#define FAN_ACCESS_PERM 0x20000 57570af302Sopenharmony_ci#define FAN_OPEN_EXEC_PERM 0x40000 58570af302Sopenharmony_ci#define FAN_DIR_MODIFY 0x00080000 59570af302Sopenharmony_ci#define FAN_EVENT_ON_CHILD 0x08000000 60570af302Sopenharmony_ci#define FAN_ONDIR 0x40000000 61570af302Sopenharmony_ci#define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) 62570af302Sopenharmony_ci#define FAN_MOVE (FAN_MOVED_FROM | FAN_MOVED_TO) 63570af302Sopenharmony_ci#define FAN_CLOEXEC 0x01 64570af302Sopenharmony_ci#define FAN_NONBLOCK 0x02 65570af302Sopenharmony_ci#define FAN_CLASS_NOTIF 0 66570af302Sopenharmony_ci#define FAN_CLASS_CONTENT 0x04 67570af302Sopenharmony_ci#define FAN_CLASS_PRE_CONTENT 0x08 68570af302Sopenharmony_ci#define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | FAN_CLASS_PRE_CONTENT) 69570af302Sopenharmony_ci#define FAN_UNLIMITED_QUEUE 0x10 70570af302Sopenharmony_ci#define FAN_UNLIMITED_MARKS 0x20 71570af302Sopenharmony_ci#define FAN_ENABLE_AUDIT 0x40 72570af302Sopenharmony_ci#define FAN_REPORT_TID 0x100 73570af302Sopenharmony_ci#define FAN_REPORT_FID 0x200 74570af302Sopenharmony_ci#define FAN_REPORT_DIR_FID 0x00000400 75570af302Sopenharmony_ci#define FAN_REPORT_NAME 0x00000800 76570af302Sopenharmony_ci#define FAN_REPORT_DFID_NAME (FAN_REPORT_DIR_FID | FAN_REPORT_NAME) 77570af302Sopenharmony_ci#define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS) 78570af302Sopenharmony_ci#define FAN_MARK_ADD 0x01 79570af302Sopenharmony_ci#define FAN_MARK_REMOVE 0x02 80570af302Sopenharmony_ci#define FAN_MARK_DONT_FOLLOW 0x04 81570af302Sopenharmony_ci#define FAN_MARK_ONLYDIR 0x08 82570af302Sopenharmony_ci#define FAN_MARK_IGNORED_MASK 0x20 83570af302Sopenharmony_ci#define FAN_MARK_IGNORED_SURV_MODIFY 0x40 84570af302Sopenharmony_ci#define FAN_MARK_FLUSH 0x80 85570af302Sopenharmony_ci#define FAN_MARK_INODE 0x00 86570af302Sopenharmony_ci#define FAN_MARK_MOUNT 0x10 87570af302Sopenharmony_ci#define FAN_MARK_FILESYSTEM 0x100 88570af302Sopenharmony_ci#define FAN_MARK_TYPE_MASK (FAN_MARK_INODE | FAN_MARK_MOUNT | FAN_MARK_FILESYSTEM) 89570af302Sopenharmony_ci#define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_DONT_FOLLOW | FAN_MARK_ONLYDIR | FAN_MARK_MOUNT | FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY | FAN_MARK_FLUSH) 90570af302Sopenharmony_ci#define FAN_ALL_EVENTS (FAN_ACCESS | FAN_MODIFY | FAN_CLOSE | FAN_OPEN) 91570af302Sopenharmony_ci#define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM | FAN_ACCESS_PERM) 92570af302Sopenharmony_ci#define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS | FAN_ALL_PERM_EVENTS | FAN_Q_OVERFLOW) 93570af302Sopenharmony_ci#define FANOTIFY_METADATA_VERSION 3 94570af302Sopenharmony_ci#define FAN_EVENT_INFO_TYPE_FID 1 95570af302Sopenharmony_ci#define FAN_EVENT_INFO_TYPE_DFID_NAME 2 96570af302Sopenharmony_ci#define FAN_EVENT_INFO_TYPE_DFID 3 97570af302Sopenharmony_ci#define FAN_ALLOW 0x01 98570af302Sopenharmony_ci#define FAN_DENY 0x02 99570af302Sopenharmony_ci#define FAN_AUDIT 0x10 100570af302Sopenharmony_ci#define FAN_NOFD -1 101570af302Sopenharmony_ci#define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata)) 102570af302Sopenharmony_ci#define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, (struct fanotify_event_metadata*)(((char *)(meta)) + (meta)->event_len)) 103570af302Sopenharmony_ci#define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && (long)(meta)->event_len <= (long)(len)) 104570af302Sopenharmony_ci 105570af302Sopenharmony_ciint fanotify_init(unsigned, unsigned); 106570af302Sopenharmony_ciint fanotify_mark(int, unsigned, unsigned long long, int, const char *); 107570af302Sopenharmony_ci 108570af302Sopenharmony_ci#ifdef __cplusplus 109570af302Sopenharmony_ci} 110570af302Sopenharmony_ci#endif 111570af302Sopenharmony_ci#endif 112