| | 1 | /* |
| | 2 | * This header is used if <sys/inotify.h> cannot be found. |
| | 3 | * |
| | 4 | * Inode based directory notification for Linux |
| | 5 | * |
| | 6 | * Copyright (C) 2005 John McCutchan |
| | 7 | */ |
| | 8 | |
| | 9 | #ifndef _LINUX_INOTIFY_H |
| | 10 | #define _LINUX_INOTIFY_H |
| | 11 | |
| | 12 | #include <stdint.h> |
| | 13 | #include <sys/syscall.h> |
| | 14 | #include <unistd.h> |
| | 15 | #include <asm/unistd.h> |
| | 16 | |
| | 17 | /* |
| | 18 | * struct inotify_event - structure read from the inotify device for each event |
| | 19 | * |
| | 20 | * When you are watching a directory, you will receive the filename for events |
| | 21 | * such as IN_CREATE, IN_DELETE, IN_OPEN, IN_CLOSE, ..., relative to the wd. |
| | 22 | */ |
| | 23 | struct inotify_event { |
| | 24 | int wd; /* watch descriptor */ |
| | 25 | uint32_t mask; /* watch mask */ |
| | 26 | uint32_t cookie; /* cookie to synchronize two events */ |
| | 27 | uint32_t len; /* length (including nulls) of name */ |
| | 28 | char name __flexarr; /* stub for possible name */ |
| | 29 | }; |
| | 30 | |
| | 31 | /* the following are legal, implemented events that user-space can watch for */ |
| | 32 | #define IN_ACCESS 0x00000001 /* File was accessed */ |
| | 33 | #define IN_MODIFY 0x00000002 /* File was modified */ |
| | 34 | #define IN_ATTRIB 0x00000004 /* Metadata changed */ |
| | 35 | #define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed */ |
| | 36 | #define IN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */ |
| | 37 | #define IN_OPEN 0x00000020 /* File was opened */ |
| | 38 | #define IN_MOVED_FROM 0x00000040 /* File was moved from X */ |
| | 39 | #define IN_MOVED_TO 0x00000080 /* File was moved to Y */ |
| | 40 | #define IN_CREATE 0x00000100 /* Subfile was created */ |
| | 41 | #define IN_DELETE 0x00000200 /* Subfile was deleted */ |
| | 42 | #define IN_DELETE_SELF 0x00000400 /* Self was deleted */ |
| | 43 | #define IN_MOVE_SELF 0x00000800 /* Self was moved */ |
| | 44 | |
| | 45 | /* the following are legal events. they are sent as needed to any watch */ |
| | 46 | #define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted */ |
| | 47 | #define IN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ |
| | 48 | #define IN_IGNORED 0x00008000 /* File was ignored */ |
| | 49 | |
| | 50 | /* helper events */ |
| | 51 | #define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* close */ |
| | 52 | #define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */ |
| | 53 | |
| | 54 | /* special flags */ |
| | 55 | #define IN_ONLYDIR 0x01000000 /* only watch the path if it is a directory */ |
| | 56 | #define IN_DONT_FOLLOW 0x02000000 /* don't follow a sym link */ |
| | 57 | #define IN_MASK_ADD 0x20000000 /* add to the mask of an already existing watch */ |
| | 58 | #define IN_ISDIR 0x40000000 /* event occurred against dir */ |
| | 59 | #define IN_ONESHOT 0x80000000 /* only send event once */ |
| | 60 | |
| | 61 | /* |
| | 62 | * All of the events - we build the list by hand so that we can add flags in |
| | 63 | * the future and not break backward compatibility. Apps will get only the |
| | 64 | * events that they originally wanted. Be sure to add new events here! |
| | 65 | */ |
| | 66 | #define IN_ALL_EVENTS (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \ |
| | 67 | IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | \ |
| | 68 | IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF | \ |
| | 69 | IN_MOVE_SELF) |
| | 70 | |
| | 71 | #if 0 |
| | 72 | #if defined (__alpha__) |
| | 73 | # define __NR_inotify_init 444 |
| | 74 | # define __NR_inotify_add_watch 445 |
| | 75 | # define __NR_inotify_rm_watch 446 |
| | 76 | |
| | 77 | #elif defined (__arm__) |
| | 78 | # define __NR_inotify_init (__NR_SYSCALL_BASE+316) |
| | 79 | # define __NR_inotify_add_watch (__NR_SYSCALL_BASE+317) |
| | 80 | # define __NR_inotify_rm_watch (__NR_SYSCALL_BASE+318) |
| | 81 | |
| | 82 | #elif defined (__frv__) |
| | 83 | # define __NR_inotify_init 291 |
| | 84 | # define __NR_inotify_add_watch 292 |
| | 85 | # define __NR_inotify_rm_watch 293 |
| | 86 | |
| | 87 | #elif defined(__i386__) |
| | 88 | # define __NR_inotify_init 291 |
| | 89 | # define __NR_inotify_add_watch 292 |
| | 90 | # define __NR_inotify_rm_watch 293 |
| | 91 | |
| | 92 | #elif defined (__ia64__) |
| | 93 | # define __NR_inotify_init 1277 |
| | 94 | # define __NR_inotify_add_watch 1278 |
| | 95 | # define __NR_inotify_rm_watch 1279 |
| | 96 | |
| | 97 | #elif defined (__mips__) |
| | 98 | # if _MIPS_SIM == _MIPS_SIM_ABI32 |
| | 99 | # define __NR_inotify_init (__NR_Linux + 284) |
| | 100 | # define __NR_inotify_add_watch (__NR_Linux + 285) |
| | 101 | # define __NR_inotify_rm_watch (__NR_Linux + 286) |
| | 102 | # endif |
| | 103 | # if _MIPS_SIM == _MIPS_SIM_ABI64 |
| | 104 | # define __NR_inotify_init (__NR_Linux + 243) |
| | 105 | # define __NR_inotify_add_watch (__NR_Linux + 243) |
| | 106 | # define __NR_inotify_rm_watch (__NR_Linux + 243) |
| | 107 | # endif |
| | 108 | # if _MIPS_SIM == _MIPS_SIM_NABI32 |
| | 109 | # define __NR_inotify_init (__NR_Linux + 247) |
| | 110 | # define __NR_inotify_add_watch (__NR_Linux + 248) |
| | 111 | # define __NR_inotify_rm_watch (__NR_Linux + 249) |
| | 112 | # endif |
| | 113 | |
| | 114 | #elif defined(__parisc__) |
| | 115 | # define __NR_inotify_init (__NR_Linux + 269) |
| | 116 | # define __NR_inotify_add_watch (__NR_Linux + 270) |
| | 117 | # define __NR_inotify_rm_watch (__NR_Linux + 271) |
| | 118 | |
| | 119 | #elif defined(__powerpc__) || defined(__powerpc64__) |
| | 120 | # define __NR_inotify_init 275 |
| | 121 | # define __NR_inotify_add_watch 276 |
| | 122 | # define __NR_inotify_rm_watch 277 |
| | 123 | |
| | 124 | #elif defined (__s390__) |
| | 125 | # define __NR_inotify_init 284 |
| | 126 | # define __NR_inotify_add_watch 285 |
| | 127 | # define __NR_inotify_rm_watch 286 |
| | 128 | |
| | 129 | #elif defined (__sh__) |
| | 130 | # define __NR_inotify_init 290 |
| | 131 | # define __NR_inotify_add_watch 291 |
| | 132 | # define __NR_inotify_rm_watch 292 |
| | 133 | |
| | 134 | #elif defined (__sh64__) |
| | 135 | # define __NR_inotify_init 318 |
| | 136 | # define __NR_inotify_add_watch 319 |
| | 137 | # define __NR_inotify_rm_watch 320 |
| | 138 | |
| | 139 | #elif defined (__sparc__) || defined (__sparc64__) |
| | 140 | # define __NR_inotify_init 151 |
| | 141 | # define __NR_inotify_add_watch 152 |
| | 142 | # define __NR_inotify_rm_watch 156 |
| | 143 | |
| | 144 | #elif defined(__x86_64__) |
| | 145 | # define __NR_inotify_init 253 |
| | 146 | # define __NR_inotify_add_watch 254 |
| | 147 | # define __NR_inotify_rm_watch 255 |
| | 148 | |
| | 149 | #else |
| | 150 | # error "Unsupported architecture!" |
| | 151 | #endif |
| | 152 | #endif |
| | 153 | |
| | 154 | #ifndef __NR_inotify_init |
| | 155 | # error "Unsupported architecture!" |
| | 156 | #endif |
| | 157 | #ifndef __NR_inotify_add_watch |
| | 158 | # error "Unsupported architecture!" |
| | 159 | #endif |
| | 160 | #ifndef __NR_inotify_rm_watch |
| | 161 | # error "Unsupported architecture!" |
| | 162 | #endif |
| | 163 | |
| | 164 | |
| | 165 | static inline int inotify_init (void) |
| | 166 | { |
| | 167 | return syscall (__NR_inotify_init); |
| | 168 | } |
| | 169 | |
| | 170 | static inline int inotify_add_watch (int fd, const char *name, uint32_t mask) |
| | 171 | { |
| | 172 | return syscall (__NR_inotify_add_watch, fd, name, mask); |
| | 173 | } |
| | 174 | |
| | 175 | static inline int inotify_rm_watch (int fd, uint32_t wd) |
| | 176 | { |
| | 177 | return syscall (__NR_inotify_rm_watch, fd, wd); |
| | 178 | } |
| | 179 | |
| | 180 | |
| | 181 | #endif /* _LINUX_INOTIFY_H */ |