#include #include #include #include #include static inline _syscall0(int, inotify_init); static inline _syscall3(int, inotify_add_watch, int, fd, const char *, path, __u32, mask); static inline _syscall2(int, inotify_rm_watch, int, fd, int, wd); #define BUFSIZE 4096 typedef struct inotify_event ine; int main (int argc, char ** argv) { int fd = inotify_init(); int wd = inotify_add_watch(fd, "/tmp", IN_ALL_EVENTS); static char buf[BUFSIZE]; size_t len; while(1){ ine * pev; len = read(fd, buf, BUFSIZE); if(!len) { putchar('.'); sleep(5); continue;} pev = (ine *) buf; while(buf + len > (char *)pev) { fprintf(stderr, "%s(%u): %x\n", pev->len ? pev->name : "(self)" , pev->wd, pev->mask); pev = (ine *)((char *)(pev + 1)) + pev->len; } } }