From 2f332e937a549f7073a74ebeb66d0a4fe70040c9 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Wed, 5 Feb 2014 15:43:04 +0000 Subject: Cleanup inotify syscalls decoding * linux/inotify.h: New file. * file.c (inotify_modes, inotify_init_flags, sys_inotify_add_watch, sys_inotify_rm_watch, sys_inotify_init1): Move... * inotify.c: ... here. (inotify_modes): Rename to inotify_flags, convert to XLAT form. (inotify_init_flags): Convert to XLAT form. * Makefile.am (strace_SOURCES): Add inotify.c. (EXTRA_DIST): Add linux/inotify.h. --- Makefile.am | 2 ++ file.c | 61 ------------------------------------------------ inotify.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ linux/inotify.h | 42 +++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 61 deletions(-) create mode 100644 inotify.c create mode 100644 linux/inotify.h diff --git a/Makefile.am b/Makefile.am index 5524293..26869fb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,6 +22,7 @@ strace_SOURCES = \ desc.c \ fanotify.c \ file.c \ + inotify.c \ io.c \ ioctl.c \ ipc.c \ @@ -107,6 +108,7 @@ EXTRA_DIST = \ linux/ia64/ioctlent.h.in \ linux/ia64/signalent.h \ linux/ia64/syscallent.h \ + linux/inotify.h \ linux/ioctlent-filter.awk \ linux/ioctlent.h.in \ linux/ioctlent.sh \ diff --git a/file.c b/file.c index cfaa1af..83ace8c 100644 --- a/file.c +++ b/file.c @@ -2706,67 +2706,6 @@ sys_sync_file_range2(struct tcb *tcp) return 0; } -static const struct xlat inotify_modes[] = { - { 0x00000001, "IN_ACCESS" }, - { 0x00000002, "IN_MODIFY" }, - { 0x00000004, "IN_ATTRIB" }, - { 0x00000008, "IN_CLOSE_WRITE"}, - { 0x00000010, "IN_CLOSE_NOWRITE"}, - { 0x00000020, "IN_OPEN" }, - { 0x00000040, "IN_MOVED_FROM" }, - { 0x00000080, "IN_MOVED_TO" }, - { 0x00000100, "IN_CREATE" }, - { 0x00000200, "IN_DELETE" }, - { 0x00000400, "IN_DELETE_SELF"}, - { 0x00000800, "IN_MOVE_SELF" }, - { 0x00002000, "IN_UNMOUNT" }, - { 0x00004000, "IN_Q_OVERFLOW" }, - { 0x00008000, "IN_IGNORED" }, - { 0x01000000, "IN_ONLYDIR" }, - { 0x02000000, "IN_DONT_FOLLOW"}, - { 0x20000000, "IN_MASK_ADD" }, - { 0x40000000, "IN_ISDIR" }, - { 0x80000000, "IN_ONESHOT" }, - XLAT_END -}; - -static const struct xlat inotify_init_flags[] = { - { 0x00000800, "IN_NONBLOCK" }, - { 0x00080000, "IN_CLOEXEC" }, - XLAT_END -}; - -int -sys_inotify_add_watch(struct tcb *tcp) -{ - if (entering(tcp)) { - printfd(tcp, tcp->u_arg[0]); - tprints(", "); - printpath(tcp, tcp->u_arg[1]); - tprints(", "); - printflags(inotify_modes, tcp->u_arg[2], "IN_???"); - } - return 0; -} - -int -sys_inotify_rm_watch(struct tcb *tcp) -{ - if (entering(tcp)) { - printfd(tcp, tcp->u_arg[0]); - tprintf(", %d", (int) tcp->u_arg[1]); - } - return 0; -} - -int -sys_inotify_init1(struct tcb *tcp) -{ - if (entering(tcp)) - printflags(inotify_init_flags, tcp->u_arg[0], "IN_???"); - return 0; -} - int sys_fallocate(struct tcb *tcp) { diff --git a/inotify.c b/inotify.c new file mode 100644 index 0000000..03689b5 --- /dev/null +++ b/inotify.c @@ -0,0 +1,72 @@ +#include "defs.h" +#include +#include + +static const struct xlat inotify_flags[] = { + XLAT(IN_ACCESS), + XLAT(IN_MODIFY), + XLAT(IN_ATTRIB), + XLAT(IN_CLOSE), + XLAT(IN_CLOSE_WRITE), + XLAT(IN_CLOSE_NOWRITE), + XLAT(IN_OPEN), + XLAT(IN_MOVE), + XLAT(IN_MOVED_FROM), + XLAT(IN_MOVED_TO), + XLAT(IN_CREATE), + XLAT(IN_DELETE), + XLAT(IN_DELETE_SELF), + XLAT(IN_MOVE_SELF), + XLAT(IN_UNMOUNT), + XLAT(IN_Q_OVERFLOW), + XLAT(IN_IGNORED), + XLAT(IN_ONLYDIR), + XLAT(IN_DONT_FOLLOW), + XLAT(IN_EXCL_UNLINK), + XLAT(IN_MASK_ADD), + XLAT(IN_ISDIR), + XLAT(IN_ONESHOT), + XLAT_END +}; + +static const struct xlat inotify_init_flags[] = { + XLAT(O_NONBLOCK), + XLAT(O_CLOEXEC), + XLAT_END +}; + +int +sys_inotify_add_watch(struct tcb *tcp) +{ + if (entering(tcp)) { + /* file descriptor */ + printfd(tcp, tcp->u_arg[0]); + tprints(", "); + /* pathname */ + printpath(tcp, tcp->u_arg[1]); + tprints(", "); + /* mask */ + printflags(inotify_flags, tcp->u_arg[2], "IN_???"); + } + return 0; +} + +int +sys_inotify_rm_watch(struct tcb *tcp) +{ + if (entering(tcp)) { + /* file descriptor */ + printfd(tcp, tcp->u_arg[0]); + /* watch descriptor */ + tprintf(", %d", (int) tcp->u_arg[1]); + } + return 0; +} + +int +sys_inotify_init1(struct tcb *tcp) +{ + if (entering(tcp)) + printflags(inotify_init_flags, tcp->u_arg[0], "IN_???"); + return 0; +} diff --git a/linux/inotify.h b/linux/inotify.h new file mode 100644 index 0000000..0af0307 --- /dev/null +++ b/linux/inotify.h @@ -0,0 +1,42 @@ +/* + * Inode based directory notification for Linux + * + * Copyright (C) 2005 John McCutchan + */ + +#ifndef _LINUX_INOTIFY_H +#define _LINUX_INOTIFY_H + +/* the following are legal, implemented events that user-space can watch for */ +#define IN_ACCESS 0x00000001 /* File was accessed */ +#define IN_MODIFY 0x00000002 /* File was modified */ +#define IN_ATTRIB 0x00000004 /* Metadata changed */ +#define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed */ +#define IN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */ +#define IN_OPEN 0x00000020 /* File was opened */ +#define IN_MOVED_FROM 0x00000040 /* File was moved from X */ +#define IN_MOVED_TO 0x00000080 /* File was moved to Y */ +#define IN_CREATE 0x00000100 /* Subfile was created */ +#define IN_DELETE 0x00000200 /* Subfile was deleted */ +#define IN_DELETE_SELF 0x00000400 /* Self was deleted */ +#define IN_MOVE_SELF 0x00000800 /* Self was moved */ + +/* the following are legal events. they are sent as needed to any watch */ +#define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted */ +#define IN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ +#define IN_IGNORED 0x00008000 /* File was ignored */ + +/* helper events */ +#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* close */ +#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */ + +/* special flags */ +#define IN_ONLYDIR 0x01000000 /* only watch the path if it is a directory */ +#define IN_DONT_FOLLOW 0x02000000 /* don't follow a sym link */ +#define IN_EXCL_UNLINK 0x04000000 /* exclude events on unlinked objects */ +#define IN_MASK_ADD 0x20000000 /* add to the mask of an already existing watch */ +#define IN_ISDIR 0x40000000 /* event occurred against dir */ +#define IN_ONESHOT 0x80000000 /* only send event once */ + + +#endif /* _LINUX_INOTIFY_H */ -- cgit v1.2.3