From nobody Thu Nov 6 10:29:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154030030612866.37375845646193; Tue, 23 Oct 2018 06:11:46 -0700 (PDT) Received: from localhost ([::1]:41239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gEwTA-0007KJ-CX for importer@patchew.org; Tue, 23 Oct 2018 09:11:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gEwQV-0005ZJ-H5 for qemu-devel@nongnu.org; Tue, 23 Oct 2018 09:08:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gEwQS-0008E2-VB for qemu-devel@nongnu.org; Tue, 23 Oct 2018 09:08:51 -0400 Received: from mx2.rt-rk.com ([89.216.37.149]:51495 helo=mail.rt-rk.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gEwQS-0007N1-IZ for qemu-devel@nongnu.org; Tue, 23 Oct 2018 09:08:48 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.rt-rk.com (Postfix) with ESMTP id 9C9C61A23B1; Tue, 23 Oct 2018 15:07:46 +0200 (CEST) Received: from rtrkw774-lin.mipstec.com (unknown [82.117.201.26]) by mail.rt-rk.com (Postfix) with ESMTPSA id 78CDF1A241B; Tue, 23 Oct 2018 15:07:46 +0200 (CEST) X-Virus-Scanned: amavisd-new at rt-rk.com From: Aleksandar Markovic To: qemu-devel@nongnu.org Date: Tue, 23 Oct 2018 15:07:34 +0200 Message-Id: <1540300056-7935-2-git-send-email-aleksandar.markovic@rt-rk.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1540300056-7935-1-git-send-email-aleksandar.markovic@rt-rk.com> References: <1540300056-7935-1-git-send-email-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 v2 1/3] linux-user: Add support for statx() 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: , Cc: arikalo@wavecomp.com, riku.voipio@iki.fi, ysu@wavecomp.com, laurent@vivier.eu, smarkovic@wavecomp.com, amarkovic@wavecomp.com, pjovanovic@wavecomp.com, aurelien@aurel32.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Aleksandar Rikalo Implement support for translation of system call statx(). The implementation includes invoking other (more mature) syscalls (from the same 'stat' family) on the host side. This way, problems of availability of statx() on the host side are avoided. Signed-off-by: Aleksandar Rikalo Signed-off-by: Stefan Markovic Signed-off-by: Aleksandar Markovic --- linux-user/syscall.c | 129 ++++++++++++++++++++++++++++++++++++++++++= +++- linux-user/syscall_defs.h | 38 ++++++++++++++ 2 files changed, 166 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index d2cc971..8b01ab0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6710,7 +6710,8 @@ static abi_long do_syscall1(void *cpu_env, int num, a= bi_long arg1, abi_long ret; #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) \ || defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64) \ - || defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64) + || defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64) \ + || defined(TARGET_NR_statx) struct stat st; #endif #if defined(TARGET_NR_statfs) || defined(TARGET_NR_statfs64) \ @@ -9635,6 +9636,132 @@ static abi_long do_syscall1(void *cpu_env, int num,= abi_long arg1, ret =3D host_to_target_stat64(cpu_env, arg3, &st); return ret; #endif +#if defined(TARGET_NR_statx) + case TARGET_NR_statx: + { + struct target_statx *target_stx; + int dirfd =3D tswap32(arg1); + int flags =3D tswap32(arg3); + + p =3D lock_user_string(arg2); + if (p =3D=3D NULL) { + return -TARGET_EFAULT; + } +#if defined(__NR_statx) + { + /* + * It is assumed that struct statx is arhitecture independ= ent + */ + struct target_statx host_stx; + int mask =3D tswap32(arg4); + + ret =3D get_errno(syscall(__NR_statx, dirfd, p, flags, mas= k, + &host_stx)); + if (!is_error(ret)) { + unlock_user(p, arg2, 0); + if (!lock_user_struct(VERIFY_WRITE, target_stx, arg5, = 0)) { + return -TARGET_EFAULT; + } + memset(target_stx, 0, sizeof(*target_stx)); + + __put_user(host_stx.stx_mask, &target_stx->stx_mask); + __put_user(host_stx.stx_blksize, &target_stx->stx_blks= ize); + __put_user(host_stx.stx_attributes, + &target_stx->stx_attributes); + __put_user(host_stx.stx_nlink, &target_stx->stx_nlink); + __put_user(host_stx.stx_uid, &target_stx->stx_uid); + __put_user(host_stx.stx_gid, &target_stx->stx_gid); + __put_user(host_stx.stx_mode, &target_stx->stx_mode); + __put_user(host_stx.stx_ino, &target_stx->stx_ino); + __put_user(host_stx.stx_size, &target_stx->stx_size); + __put_user(host_stx.stx_blocks, &target_stx->stx_block= s); + __put_user(host_stx.stx_attributes_mask, + &target_stx->stx_attributes_mask); + __put_user(host_stx.stx_atime.tv_sec, + &target_stx->stx_atime.tv_sec); + __put_user(host_stx.stx_atime.tv_nsec, + &target_stx->stx_atime.tv_nsec); + __put_user(host_stx.stx_btime.tv_sec, + &target_stx->stx_atime.tv_sec); + __put_user(host_stx.stx_btime.tv_nsec, + &target_stx->stx_atime.tv_nsec); + __put_user(host_stx.stx_ctime.tv_sec, + &target_stx->stx_atime.tv_sec); + __put_user(host_stx.stx_ctime.tv_nsec, + &target_stx->stx_atime.tv_nsec); + __put_user(host_stx.stx_mtime.tv_sec, + &target_stx->stx_atime.tv_sec); + __put_user(host_stx.stx_mtime.tv_nsec, + &target_stx->stx_atime.tv_nsec); + __put_user(host_stx.stx_rdev_major, + &target_stx->stx_rdev_major); + __put_user(host_stx.stx_rdev_minor, + &target_stx->stx_rdev_minor); + __put_user(host_stx.stx_dev_major, + &target_stx->stx_dev_major); + __put_user(host_stx.stx_dev_minor, + &target_stx->stx_dev_minor); + } + + if (ret !=3D TARGET_ENOSYS) { + break; + } + } +#endif + if ((p =3D=3D NULL) || (*((char *)p) =3D=3D 0)) { + /* + * By file descriptor + */ + ret =3D get_errno(fstat(dirfd, &st)); + unlock_user(p, arg2, 0); + } else if (*((char *)p) =3D=3D '/') { + /* + * By absolute pathname + */ + ret =3D get_errno(stat(path(p), &st)); + unlock_user(p, arg2, 0); + } else { + if (dirfd =3D=3D AT_FDCWD) { + /* + * By pathname relative to the current working directo= ry + */ + ret =3D get_errno(stat(path(p), &st)); + unlock_user(p, arg2, 0); + } else { + /* + * By pathname relative to the directory referred to by + * the file descriptor 'dirfd' + */ + ret =3D get_errno(fstatat(dirfd, path(p), &st, flags)); + unlock_user(p, arg2, 0); + } + } + + if (!is_error(ret)) { + if (!lock_user_struct(VERIFY_WRITE, target_stx, arg5, 0)) { + return -TARGET_EFAULT; + } + memset(target_stx, 0, sizeof(*target_stx)); + __put_user(major(st.st_dev), &target_stx->stx_dev_major); + __put_user(minor(st.st_dev), &target_stx->stx_dev_minor); + __put_user(st.st_ino, &target_stx->stx_ino); + __put_user(st.st_mode, &target_stx->stx_mode); + __put_user(st.st_uid, &target_stx->stx_uid); + __put_user(st.st_gid, &target_stx->stx_gid); + __put_user(st.st_nlink, &target_stx->stx_nlink); + __put_user(major(st.st_rdev), &target_stx->stx_rdev_major); + __put_user(minor(st.st_rdev), &target_stx->stx_rdev_minor); + __put_user(st.st_size, &target_stx->stx_size); + __put_user(st.st_blksize, &target_stx->stx_blksize); + __put_user(st.st_blocks, &target_stx->stx_blocks); + __put_user(st.st_atime, &target_stx->stx_atime.tv_sec); + __put_user(st.st_mtime, &target_stx->stx_mtime.tv_sec); + __put_user(st.st_ctime, &target_stx->stx_ctime.tv_sec); + unlock_user_struct(target_stx, arg5, 1); + } + } + break; +#endif #ifdef TARGET_NR_lchown case TARGET_NR_lchown: if (!(p =3D lock_user_string(arg1))) diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 18d434d..b6c5c4f 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -2488,4 +2488,42 @@ struct target_user_cap_data { /* Return size of the log buffer */ #define TARGET_SYSLOG_ACTION_SIZE_BUFFER 10 =20 +struct target_statx_timestamp { + int64_t tv_sec; + uint32_t tv_nsec; + int32_t __reserved; +}; + +struct target_statx { + /* 0x00 */ + uint32_t stx_mask; /* What results were written [uncond] */ + uint32_t stx_blksize; /* Preferred general I/O size [uncond] */ + uint64_t stx_attributes; /* Flags conveying information about the file = */ + /* 0x10 */ + uint32_t stx_nlink; /* Number of hard links */ + uint32_t stx_uid; /* User ID of owner */ + uint32_t stx_gid; /* Group ID of owner */ + uint16_t stx_mode; /* File mode */ + uint16_t __spare0[1]; + /* 0x20 */ + uint64_t stx_ino; /* Inode number */ + uint64_t stx_size; /* File size */ + uint64_t stx_blocks; /* Number of 512-byte blocks allocated */ + uint64_t stx_attributes_mask; /* Mask to show what's supported in + stx_attributes */ + /* 0x40 */ + struct target_statx_timestamp stx_atime; /* Last access time */ + struct target_statx_timestamp stx_btime; /* File creation time */ + struct target_statx_timestamp stx_ctime; /* Last attribute change tim= e */ + struct target_statx_timestamp stx_mtime; /* Last data modification ti= me */ + /* 0x80 */ + uint32_t stx_rdev_major; /* Device ID of special file [if bdev/cdev] = */ + uint32_t stx_rdev_minor; + uint32_t stx_dev_major; /* ID of device containing file [uncond] */ + uint32_t stx_dev_minor; + /* 0x90 */ + uint64_t __spare2[14]; /* Spare space for future expansion */ + /* 0x100 */ +}; + #endif --=20 2.7.4