* [Qemu-devel] [PATCH] linux-user: fix inotify
@ 2017-03-02 0:54 Laurent Vivier
2017-03-02 3:55 ` Philippe Mathieu-Daudé
2017-04-25 16:33 ` Laurent Vivier
0 siblings, 2 replies; 3+ messages in thread
From: Laurent Vivier @ 2017-03-02 0:54 UTC (permalink / raw)
To: Riku Voipio; +Cc: qemu-devel, Laurent Vivier
When a fd is opened using inotify_init(), a read provides
one or more inotify_event structures:
struct inotify_event {
int wd;
uint32_t mask;
uint32_t cookie;
uint32_t len;
char name[];
};
The integer fields must be byte-swapped to the target endianness.
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index cec8428..c2c4f3a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7671,6 +7671,33 @@ static target_timer_t get_timer_id(abi_long arg)
return timerid;
}
+#if (defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)) || \
+ (defined(CONFIG_INOTIFY1) && defined(TARGET_NR_inotify_init1) && \
+ defined(__NR_inotify_init1))
+static abi_long host_to_target_data_inotify(void *buf, size_t len)
+{
+ struct inotify_event *ev;
+ int i;
+ uint32_t name_len;
+
+ for (i = 0; i < len; i += sizeof(struct inotify_event) + name_len) {
+ ev = (struct inotify_event *)((char *)buf + i);
+ name_len = ev->len;
+
+ ev->wd = tswap32(ev->wd);
+ ev->mask = tswap32(ev->mask);
+ ev->cookie = tswap32(ev->cookie);
+ ev->len = tswap32(name_len);
+ }
+
+ return len;
+}
+
+static TargetFdTrans target_inotify_trans = {
+ .host_to_target_data = host_to_target_data_inotify,
+};
+#endif
+
/* do_syscall() should always have a single exit point at the end so
that actions, such as logging of syscall results, can be performed.
All errnos that do_syscall() returns must be -TARGET_<errcode>. */
@@ -11694,6 +11721,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
#if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
case TARGET_NR_inotify_init:
ret = get_errno(sys_inotify_init());
+ fd_trans_register(ret, &target_inotify_trans);
break;
#endif
#ifdef CONFIG_INOTIFY1
@@ -11701,6 +11729,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
case TARGET_NR_inotify_init1:
ret = get_errno(sys_inotify_init1(target_to_host_bitmask(arg1,
fcntl_flags_tbl)));
+ fd_trans_register(ret, &target_inotify_trans);
break;
#endif
#endif
--
2.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user: fix inotify
2017-03-02 0:54 [Qemu-devel] [PATCH] linux-user: fix inotify Laurent Vivier
@ 2017-03-02 3:55 ` Philippe Mathieu-Daudé
2017-04-25 16:33 ` Laurent Vivier
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-03-02 3:55 UTC (permalink / raw)
To: Laurent Vivier, Riku Voipio; +Cc: qemu-devel
On 03/01/2017 09:54 PM, Laurent Vivier wrote:
> When a fd is opened using inotify_init(), a read provides
> one or more inotify_event structures:
>
> struct inotify_event {
> int wd;
> uint32_t mask;
> uint32_t cookie;
> uint32_t len;
> char name[];
> };
>
> The integer fields must be byte-swapped to the target endianness.
>
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> linux-user/syscall.c | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index cec8428..c2c4f3a 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -7671,6 +7671,33 @@ static target_timer_t get_timer_id(abi_long arg)
> return timerid;
> }
>
> +#if (defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)) || \
> + (defined(CONFIG_INOTIFY1) && defined(TARGET_NR_inotify_init1) && \
> + defined(__NR_inotify_init1))
> +static abi_long host_to_target_data_inotify(void *buf, size_t len)
> +{
> + struct inotify_event *ev;
> + int i;
> + uint32_t name_len;
> +
> + for (i = 0; i < len; i += sizeof(struct inotify_event) + name_len) {
> + ev = (struct inotify_event *)((char *)buf + i);
> + name_len = ev->len;
> +
> + ev->wd = tswap32(ev->wd);
> + ev->mask = tswap32(ev->mask);
> + ev->cookie = tswap32(ev->cookie);
> + ev->len = tswap32(name_len);
> + }
> +
> + return len;
> +}
> +
> +static TargetFdTrans target_inotify_trans = {
> + .host_to_target_data = host_to_target_data_inotify,
> +};
> +#endif
> +
> /* do_syscall() should always have a single exit point at the end so
> that actions, such as logging of syscall results, can be performed.
> All errnos that do_syscall() returns must be -TARGET_<errcode>. */
> @@ -11694,6 +11721,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
> #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
> case TARGET_NR_inotify_init:
> ret = get_errno(sys_inotify_init());
> + fd_trans_register(ret, &target_inotify_trans);
> break;
> #endif
> #ifdef CONFIG_INOTIFY1
> @@ -11701,6 +11729,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
> case TARGET_NR_inotify_init1:
> ret = get_errno(sys_inotify_init1(target_to_host_bitmask(arg1,
> fcntl_flags_tbl)));
> + fd_trans_register(ret, &target_inotify_trans);
> break;
> #endif
> #endif
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user: fix inotify
2017-03-02 0:54 [Qemu-devel] [PATCH] linux-user: fix inotify Laurent Vivier
2017-03-02 3:55 ` Philippe Mathieu-Daudé
@ 2017-04-25 16:33 ` Laurent Vivier
1 sibling, 0 replies; 3+ messages in thread
From: Laurent Vivier @ 2017-04-25 16:33 UTC (permalink / raw)
To: Riku Voipio; +Cc: qemu-devel
Ping?
Laurent
Le 02/03/2017 à 01:54, Laurent Vivier a écrit :
> When a fd is opened using inotify_init(), a read provides
> one or more inotify_event structures:
>
> struct inotify_event {
> int wd;
> uint32_t mask;
> uint32_t cookie;
> uint32_t len;
> char name[];
> };
>
> The integer fields must be byte-swapped to the target endianness.
>
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
> linux-user/syscall.c | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index cec8428..c2c4f3a 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -7671,6 +7671,33 @@ static target_timer_t get_timer_id(abi_long arg)
> return timerid;
> }
>
> +#if (defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)) || \
> + (defined(CONFIG_INOTIFY1) && defined(TARGET_NR_inotify_init1) && \
> + defined(__NR_inotify_init1))
> +static abi_long host_to_target_data_inotify(void *buf, size_t len)
> +{
> + struct inotify_event *ev;
> + int i;
> + uint32_t name_len;
> +
> + for (i = 0; i < len; i += sizeof(struct inotify_event) + name_len) {
> + ev = (struct inotify_event *)((char *)buf + i);
> + name_len = ev->len;
> +
> + ev->wd = tswap32(ev->wd);
> + ev->mask = tswap32(ev->mask);
> + ev->cookie = tswap32(ev->cookie);
> + ev->len = tswap32(name_len);
> + }
> +
> + return len;
> +}
> +
> +static TargetFdTrans target_inotify_trans = {
> + .host_to_target_data = host_to_target_data_inotify,
> +};
> +#endif
> +
> /* do_syscall() should always have a single exit point at the end so
> that actions, such as logging of syscall results, can be performed.
> All errnos that do_syscall() returns must be -TARGET_<errcode>. */
> @@ -11694,6 +11721,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
> #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
> case TARGET_NR_inotify_init:
> ret = get_errno(sys_inotify_init());
> + fd_trans_register(ret, &target_inotify_trans);
> break;
> #endif
> #ifdef CONFIG_INOTIFY1
> @@ -11701,6 +11729,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
> case TARGET_NR_inotify_init1:
> ret = get_errno(sys_inotify_init1(target_to_host_bitmask(arg1,
> fcntl_flags_tbl)));
> + fd_trans_register(ret, &target_inotify_trans);
> break;
> #endif
> #endif
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-04-25 16:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-02 0:54 [Qemu-devel] [PATCH] linux-user: fix inotify Laurent Vivier
2017-03-02 3:55 ` Philippe Mathieu-Daudé
2017-04-25 16:33 ` Laurent Vivier
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.