From patchwork Thu Sep 22 15:06:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Markovic X-Patchwork-Id: 673503 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sg1QW1XFdz9t2b for ; Fri, 23 Sep 2016 01:59:31 +1000 (AEST) Received: from localhost ([::1]:51755 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn6PI-0004Qq-Nm for incoming@patchwork.ozlabs.org; Thu, 22 Sep 2016 11:59:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn5cr-00015L-2Y for qemu-devel@nongnu.org; Thu, 22 Sep 2016 11:09:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bn5cl-0004k8-SW for qemu-devel@nongnu.org; Thu, 22 Sep 2016 11:09:23 -0400 Received: from mx2.rt-rk.com ([89.216.37.149]:46466 helo=mail.rt-rk.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn5cl-0004jz-FN for qemu-devel@nongnu.org; Thu, 22 Sep 2016 11:09:19 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.rt-rk.com (Postfix) with ESMTP id B8F4E1A2256; Thu, 22 Sep 2016 17:09:18 +0200 (CEST) X-Virus-Scanned: amavisd-new at rt-rk.com Received: from mcs19.domain.local (mcs19.domain.local [10.10.13.51]) by mail.rt-rk.com (Postfix) with ESMTPSA id 929711A20A0; Thu, 22 Sep 2016 17:09:18 +0200 (CEST) From: Aleksandar Markovic To: qemu-devel@nongnu.org, riku.voipio@iki.fi, laurent@vivier.eu, peter.maydell@linaro.org, petar.jovanovic@imgtec.com, miodrag.dinic@imgtec.com, aleksandar.rikalo@imgtec.com, aleksandar.markovic@imgtec.com Date: Thu, 22 Sep 2016 17:06:33 +0200 Message-Id: <20160922150646.78163-6-aleksandar.markovic@rt-rk.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160922150646.78163-1-aleksandar.markovic@rt-rk.com> References: <20160922150646.78163-1-aleksandar.markovic@rt-rk.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 89.216.37.149 Subject: [Qemu-devel] [PATCH v6 05/10] linux-user: Add support for ustat() syscall X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Aleksandar Markovic This patch implements Qemu user mode ustat() syscall support. Syscall ustat() returns information about a mounted filesystem. Its declaration is: int ustat(dev_t dev, struct ustat *ubuf); Its Linux kernel implementation is at fs/compat.c, line 334. The Qemu implementation proposed in this patch is similar to the Qemu implementations of statfs(), fstatfs() and other related syscalls. It is based on invocation of host's ustat(), and its key part is in the correspondent case segment of the main switch statement of the function do_syscall(), in file linux-user/syscalls.c. All necessary conversions of data structures from target to host and from host to target are covered. Support for target_ustat is included. Sufficient support for "-strace" option for this syscall is already present, and this patch does not change it. This patch also fixes failures of LTP tests ustat01, and ustat02, if executed on Qemu-emulated systems. Signed-off-by: Aleksandar Markovic --- linux-user/syscall.c | 23 +++++++++++++++++++++-- linux-user/syscall_defs.h | 6 ++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 7bcd73f..7d7a57f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -48,6 +48,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base, #include #include #include +#include #include #include #include @@ -8100,9 +8101,27 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ret = get_errno(chroot(p)); unlock_user(p, arg1, 0); break; -#ifdef TARGET_NR_ustat +#if defined(TARGET_NR_ustat) case TARGET_NR_ustat: - goto unimplemented; + { + struct ustat ust; + + ret = get_errno(ustat(arg1, &ust)); + if (!is_error(ret)) { + struct target_ustat *target_ust; + + if (!lock_user_struct(VERIFY_WRITE, target_ust, arg2, 0)) { + goto efault; + } + __put_user(ust.f_tfree, &target_ust->f_tfree); + __put_user(ust.f_tinode, &target_ust->f_tinode); + memcpy(target_ust->f_fname, ust.f_fname, 6); + memcpy(target_ust->f_fpack, ust.f_fpack, 6); + unlock_user_struct(target_ust, arg2, 1); + } + } + break; + #endif #ifdef TARGET_NR_dup2 case TARGET_NR_dup2: diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 4cb66ff..8a49f6f 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -2158,6 +2158,12 @@ struct target_statfs64 { }; #endif +struct target_ustat { + abi_ulong f_tfree; + abi_int f_tinode; + char f_fname[6]; + char f_fpack[6]; +}; #define TARGET_F_DUPFD 0 /* dup */ #define TARGET_F_GETFD 1 /* get close_on_exec */