4 #include <linux/inotify.h>
6 #include <asm/unistd.h>
13 _syscall0(int, inotify_init);
14 _syscall3(int, inotify_add_watch, int, fd, const char *, path, __u32, mask);
15 _syscall2(int, inotify_rm_watch, int, fd, int, wd);
19 static int inotify_init(void)
21 return syscall(__NR_inotify_init);
24 static int inotify_add_watch(int fd, const char *path, __u32 mask)
27 return syscall(__NR_inotify_add_watch, fd, path, mask+(++xx));
30 static int inotify_rm_watch(int fd, int wd)
32 return syscall(__NR_inotify_rm_watch, fd, wd);
36 static void usage(void)
38 printf("usage: inotify <DIRECTORY>\n");
41 int main(int argc, const char *argv[])
54 if ((child = fork()) == 0) {
56 asprintf(&testname, "%s/inotify_test.dat", path);
58 close(open(testname, O_CREAT|O_RDWR, 0666));
65 wd1 = inotify_add_watch(fd, path, IN_CREATE|IN_DELETE);
66 wd2 = inotify_add_watch(fd, path, IN_CREATE|IN_DELETE);
70 int ret = read(fd, buf, sizeof(buf));
72 struct inotify_event *ev;
73 while (ret > sizeof(ev)) {
74 ev = (struct inotify_event *)p;
75 printf("%d 0x%08x %d '%s'\n",
76 ev->wd, ev->mask, ev->len, ev->name);
77 p += sizeof(*ev) + ev->len;
78 ret -= sizeof(*ev) + ev->len;
82 inotify_rm_watch(fd, wd1);
83 inotify_rm_watch(fd, wd2);