From patchwork Sun Jun 10 03:01:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138114 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2590007lji; Sat, 9 Jun 2018 20:31:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJTcTS2RVMKBtURCenedJuv5KDZxOZaQ5J5UOlHJbOjGlFJqTMGDtZP6NEZNDp4DiKFs2cQ X-Received: by 2002:aed:25cb:: with SMTP id y11-v6mr11554365qtc.333.1528601517703; Sat, 09 Jun 2018 20:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528601517; cv=none; d=google.com; s=arc-20160816; b=xB0c4ntdFBEMEEmieCa2O/3B26qMX7cR7ilB2StRIcFgIASR4Wxx/ocTobPk5dJ5I0 OdNn+uDQ++RCYC3q6hnspq3Kq5c94am30a5PdGk0zHSjE+9HJTGBCKmoS0uWxcTQFz2U SFPk7hi1QflEVplX6qUOfa0xJwZlp3LLZChmzEPoiE3m/NFIoSpbPrGC5s+G0CYno8SZ gP2QFssrICMgMJZl2fx9rrAaIEsvo9fX0ZYDOGVP3hORuTP0apRJV0y+Nyg4b9NiD4Hr NEPAqxYeNks8Ran4j9U7Gv+4BvA0Rl7zF31upIWalS3e/iAMSjknL5MUgb2hxeRQIoaQ OoNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=aelzVM/F3mmjQ+WdFXQpG8KOCYOaODvftBQqj0+75ys=; b=igfcHaDiuHNfH4B0uTR4rMClOT1cA8ceYT3/g9iLeu9EPy2neoO3FW2tyUHMtxGbnW 5klDhgaRWGKWDeqUxCQAC/oSFuSPmhJ8Cm689oZQ7QkwfT8jCebMlNiv+SUeBM7JezyM dNE8Kyvh1aM3JWhD76/I0ina/tJwfCJ4A6zpZuHIHsiSdCIdM9ZoZlCNo60ZJd1bkO2z xJA1xNBT1zGey1E5/R0sFBg099MLmpNjKH/9I04BJvx6Zz7FlBi9CPe97cgO0bqLVMsg irOFtck/j7hFSZZft1c3kVgej4/z3hqQEM+5yBkgudsZTxRanK5YBltzy07HgUp2ErB9 AqWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=E0zkv+0Q; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e66-v6si1165305qkc.264.2018.06.09.20.31.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 20:31:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=E0zkv+0Q; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRr5B-0001XJ-3i for patch@linaro.org; Sat, 09 Jun 2018 23:31:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40651) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqe8-0002np-H6 for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqe6-0003do-QF for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:00 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:38246) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqe6-0003db-II for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:03:58 -0400 Received: by mail-pg0-x243.google.com with SMTP id c9-v6so8135601pgf.5 for ; Sat, 09 Jun 2018 20:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aelzVM/F3mmjQ+WdFXQpG8KOCYOaODvftBQqj0+75ys=; b=E0zkv+0QUfAQK5GkIalQHbPn5jhUSSJH6qKWoOBpreB+tGIVyleJC3ua7thsacK4Uq uKEppbtjuK+8Z+8+QnzqkvJDWEcBaUS1Qjq4A07heB74ndGFoLI59CGtAA73oJZHMbPE RSVzRhDBgJeA2K1GFIXN1Ey5mfKW1t4rCdcXk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aelzVM/F3mmjQ+WdFXQpG8KOCYOaODvftBQqj0+75ys=; b=p7PXbB2Du4OlrhhMH1m+aTeSf2cGT4BOWt9RVUfyrO8VwonaCg5M5X4PNcmBIv0h10 D+N7PSZmUlRHBzTekX+HvboJcW4arTrHCJ8eR/dG+DOSH/upaKRWL7VUUWNDaFax1ALI 5C2b0EEauO4EME2P32WdvhZBySsCkNkMB+iVgRC/5RTyaLwPM5TKwHmdnNRqrAm3WmYe agLMdFrT48UjvIBPwSpt8ROBKCShLZypFti9mPAJvYTbSGxeBGWyiMILyqgMLmcBmdzI JkJ5aFF+9Dr7KQv3UsbIrVw7H7A0wZxgBkPBUkpEv7GZRymedwzl42DUkeeMFSBhuU4x Zfww== X-Gm-Message-State: APt69E1OPIIcyGsfEz5Tg204UOm+D41OC2PvsB6qX9eqIpZeDu6IsK+/ jzd2qaC5Lihp2aMydx6QN+vjU9Q4pdw= X-Received: by 2002:a62:ff1d:: with SMTP id b29-v6mr12283070pfn.181.1528599837312; Sat, 09 Jun 2018 20:03:57 -0700 (PDT) Received: from cloudburst.twiddle.net (rrcs-173-198-77-219.west.biz.rr.com. [173.198.77.219]) by smtp.gmail.com with ESMTPSA id y17-v6sm31712718pfe.33.2018.06.09.20.03.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:03:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:01:14 -1000 Message-Id: <20180610030220.3777-43-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180610030220.3777-1-richard.henderson@linaro.org> References: <20180610030220.3777-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH v2 042/108] linux-user: Split out fstatfs, fstatfs64, statfs, statfs64 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: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- linux-user/syscall.c | 193 ++++++++++++++++++++++++++++--------------- 1 file changed, 125 insertions(+), 68 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index df8422cd3a..86583988c4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7207,6 +7207,61 @@ static inline abi_long host_to_target_stat64(void *cpu_env, return 0; } +static abi_long host_to_target_statfs(abi_ulong target_addr, + struct statfs *stfs) +{ + struct target_statfs *target_stfs; + + if (!lock_user_struct(VERIFY_WRITE, target_stfs, target_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(stfs->f_type, &target_stfs->f_type); + __put_user(stfs->f_bsize, &target_stfs->f_bsize); + __put_user(stfs->f_blocks, &target_stfs->f_blocks); + __put_user(stfs->f_bfree, &target_stfs->f_bfree); + __put_user(stfs->f_bavail, &target_stfs->f_bavail); + __put_user(stfs->f_files, &target_stfs->f_files); + __put_user(stfs->f_ffree, &target_stfs->f_ffree); + __put_user(stfs->f_fsid.__val[0], &target_stfs->f_fsid.val[0]); + __put_user(stfs->f_fsid.__val[1], &target_stfs->f_fsid.val[1]); + __put_user(stfs->f_namelen, &target_stfs->f_namelen); + __put_user(stfs->f_frsize, &target_stfs->f_frsize); +#ifdef _STATFS_F_FLAGS + __put_user(stfs->f_flags, &target_stfs->f_flags); +#else + __put_user(0, &target_stfs->f_flags); +#endif + memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare)); + unlock_user_struct(target_stfs, target_addr, 1); + return 0; +} + +#ifdef TARGET_NR_statfs64 +static abi_long host_to_target_statfs64(abi_ulong target_addr, + struct statfs *stfs) +{ + struct target_statfs64 *target_stfs; + + if (!lock_user_struct(VERIFY_WRITE, target_stfs, target_addr, 0)) { + return -TARGET_EFAULT; + } + __put_user(stfs->f_type, &target_stfs->f_type); + __put_user(stfs->f_bsize, &target_stfs->f_bsize); + __put_user(stfs->f_blocks, &target_stfs->f_blocks); + __put_user(stfs->f_bfree, &target_stfs->f_bfree); + __put_user(stfs->f_bavail, &target_stfs->f_bavail); + __put_user(stfs->f_files, &target_stfs->f_files); + __put_user(stfs->f_ffree, &target_stfs->f_ffree); + __put_user(stfs->f_fsid.__val[0], &target_stfs->f_fsid.val[0]); + __put_user(stfs->f_fsid.__val[1], &target_stfs->f_fsid.val[1]); + __put_user(stfs->f_namelen, &target_stfs->f_namelen); + __put_user(stfs->f_frsize, &target_stfs->f_frsize); + memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare)); + unlock_user_struct(target_stfs, target_addr, 1); + return 0; +} +#endif + /* ??? Using host futex calls even when target atomic operations are not really atomic probably breaks things. However implementing futexes locally would make futexes shared between multiple processes @@ -8111,6 +8166,32 @@ IMPL(fork) } #endif +IMPL(fstatfs) +{ + struct statfs stfs; + abi_long ret; + + ret = get_errno(fstatfs(arg1, &stfs)); + if (!is_error(ret) && host_to_target_statfs(arg2, &stfs)) { + return -TARGET_EFAULT; + } + return ret; +} + +#ifdef TARGET_NR_fstatfs64 +IMPL(fstatfs64) +{ + struct statfs stfs; + abi_long ret; + + ret = get_errno(fstatfs(arg1, &stfs)); + if (!is_error(ret) && host_to_target_statfs64(arg3, &stfs)) { + return -TARGET_EFAULT; + } + return ret; +} +#endif + IMPL(ftruncate) { return get_errno(ftruncate(arg1, arg2)); @@ -9485,6 +9566,42 @@ IMPL(ssetmask) } #endif +IMPL(statfs) +{ + char *p = lock_user_string(arg1); + struct statfs stfs; + abi_long ret; + + if (!p) { + return -TARGET_EFAULT; + } + ret = get_errno(statfs(path(p), &stfs)); + unlock_user(p, arg1, 0); + if (!is_error(ret) && host_to_target_statfs(arg2, &stfs)) { + return -TARGET_EFAULT; + } + return ret; +} + +#ifdef TARGET_NR_statfs64 +IMPL(statfs64) +{ + char *p = lock_user_string(arg1); + struct statfs stfs; + abi_long ret; + + if (!p) { + return -TARGET_EFAULT; + } + ret = get_errno(statfs(path(p), &stfs)); + unlock_user(p, arg1, 0); + if (!is_error(ret) && host_to_target_statfs64(arg3, &stfs)) { + return -TARGET_EFAULT; + } + return ret; +} +#endif + #ifdef TARGET_NR_stime IMPL(stime) { @@ -9778,7 +9895,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, CPUState *cpu __attribute__((unused)) = ENV_GET_CPU(cpu_env); abi_long ret; struct stat st; - struct statfs stfs; void *p; switch(num) { @@ -9800,73 +9916,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, return ret; case TARGET_NR_setpriority: return get_errno(setpriority(arg1, arg2, arg3)); - case TARGET_NR_statfs: - if (!(p = lock_user_string(arg1))) { - return -TARGET_EFAULT; - } - ret = get_errno(statfs(path(p), &stfs)); - unlock_user(p, arg1, 0); - convert_statfs: - if (!is_error(ret)) { - struct target_statfs *target_stfs; - - if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg2, 0)) - return -TARGET_EFAULT; - __put_user(stfs.f_type, &target_stfs->f_type); - __put_user(stfs.f_bsize, &target_stfs->f_bsize); - __put_user(stfs.f_blocks, &target_stfs->f_blocks); - __put_user(stfs.f_bfree, &target_stfs->f_bfree); - __put_user(stfs.f_bavail, &target_stfs->f_bavail); - __put_user(stfs.f_files, &target_stfs->f_files); - __put_user(stfs.f_ffree, &target_stfs->f_ffree); - __put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]); - __put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]); - __put_user(stfs.f_namelen, &target_stfs->f_namelen); - __put_user(stfs.f_frsize, &target_stfs->f_frsize); -#ifdef _STATFS_F_FLAGS - __put_user(stfs.f_flags, &target_stfs->f_flags); -#else - __put_user(0, &target_stfs->f_flags); -#endif - memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare)); - unlock_user_struct(target_stfs, arg2, 1); - } - return ret; - case TARGET_NR_fstatfs: - ret = get_errno(fstatfs(arg1, &stfs)); - goto convert_statfs; -#ifdef TARGET_NR_statfs64 - case TARGET_NR_statfs64: - if (!(p = lock_user_string(arg1))) { - return -TARGET_EFAULT; - } - ret = get_errno(statfs(path(p), &stfs)); - unlock_user(p, arg1, 0); - convert_statfs64: - if (!is_error(ret)) { - struct target_statfs64 *target_stfs; - - if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg3, 0)) - return -TARGET_EFAULT; - __put_user(stfs.f_type, &target_stfs->f_type); - __put_user(stfs.f_bsize, &target_stfs->f_bsize); - __put_user(stfs.f_blocks, &target_stfs->f_blocks); - __put_user(stfs.f_bfree, &target_stfs->f_bfree); - __put_user(stfs.f_bavail, &target_stfs->f_bavail); - __put_user(stfs.f_files, &target_stfs->f_files); - __put_user(stfs.f_ffree, &target_stfs->f_ffree); - __put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]); - __put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]); - __put_user(stfs.f_namelen, &target_stfs->f_namelen); - __put_user(stfs.f_frsize, &target_stfs->f_frsize); - memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare)); - unlock_user_struct(target_stfs, arg3, 1); - } - return ret; - case TARGET_NR_fstatfs64: - ret = get_errno(fstatfs(arg1, &stfs)); - goto convert_statfs64; -#endif #ifdef TARGET_NR_socketcall case TARGET_NR_socketcall: return do_socketcall(arg1, arg2); @@ -12744,6 +12793,10 @@ static impl_fn *syscall_table(unsigned num) #endif #ifdef TARGET_NR_fork SYSCALL(fork); +#endif + SYSCALL(fstatfs); +#ifdef TARGET_NR_fstatfs64 + SYSCALL(fstatfs64); #endif SYSCALL(ftruncate); #ifdef TARGET_NR_futimesat @@ -12874,6 +12927,10 @@ static impl_fn *syscall_table(unsigned num) #endif #ifdef TARGET_NR_ssetmask SYSCALL(ssetmask); +#endif + SYSCALL(statfs); +#ifdef TARGET_NR_statfs64 + SYSCALL(statfs64); #endif #ifdef TARGET_NR_stime SYSCALL(stime);