From: Peter Maydell <peter.maydell@linaro.org>
To: Aurelien Jarno <aurelien@aurel32.net>, Blue Swirl <blauwirbel@gmail.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
Riku Voipio <riku.voipio@iki.fi>,
Claudio Fontana <claudio.fontana@huawei.com>,
qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 01/13] linux-user: Allow getdents to be provided by getdents64
Date: Wed, 12 Jun 2013 16:57:13 +0100 [thread overview]
Message-ID: <1371052645-9006-2-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1371052645-9006-1-git-send-email-peter.maydell@linaro.org>
Newer architectures may only implement the getdents64 syscall, not
getdents. Provide an implementation of getdents in terms of getdents64
so that we can run getdents-using targets on a getdents64-only host.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Tested-by: Claudio Fontana <claudio.fontana@huawei.com>
Message-id: 1370344377-27445-1-git-send-email-peter.maydell@linaro.org
Message-id: 1370193044-24535-1-git-send-email-peter.maydell@linaro.org
---
linux-user/syscall.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 0099d64..4151c78 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -223,8 +223,11 @@ static int gettid(void) {
return -ENOSYS;
}
#endif
+#ifdef __NR_getdents
_syscall3(int, sys_getdents, uint, fd, struct linux_dirent *, dirp, uint, count);
-#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
+#endif
+#if !defined(__NR_getdents) || \
+ (defined(TARGET_NR_getdents64) && defined(__NR_getdents64))
_syscall3(int, sys_getdents64, uint, fd, struct linux_dirent64 *, dirp, uint, count);
#endif
#if defined(TARGET_NR__llseek) && defined(__NR_llseek)
@@ -7123,6 +7126,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
break;
#endif
case TARGET_NR_getdents:
+#ifdef __NR_getdents
#if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
{
struct target_dirent *target_dirp;
@@ -7195,6 +7199,61 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
unlock_user(dirp, arg2, ret);
}
#endif
+#else
+ /* Implement getdents in terms of getdents64 */
+ {
+ struct linux_dirent64 *dirp;
+ abi_long count = arg3;
+
+ dirp = lock_user(VERIFY_WRITE, arg2, count, 0);
+ if (!dirp) {
+ goto efault;
+ }
+ ret = get_errno(sys_getdents64(arg1, dirp, count));
+ if (!is_error(ret)) {
+ /* Convert the dirent64 structs to target dirent. We do this
+ * in-place, since we can guarantee that a target_dirent is no
+ * larger than a dirent64; however this means we have to be
+ * careful to read everything before writing in the new format.
+ */
+ struct linux_dirent64 *de;
+ struct target_dirent *tde;
+ int len = ret;
+ int tlen = 0;
+
+ de = dirp;
+ tde = (struct target_dirent *)dirp;
+ while (len > 0) {
+ int namelen, treclen;
+ int reclen = de->d_reclen;
+ uint64_t ino = de->d_ino;
+ int64_t off = de->d_off;
+ uint8_t type = de->d_type;
+
+ namelen = strlen(de->d_name);
+ treclen = offsetof(struct target_dirent, d_name)
+ + namelen + 2;
+ treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long));
+
+ memmove(tde->d_name, de->d_name, namelen + 1);
+ tde->d_ino = tswapal(ino);
+ tde->d_off = tswapal(off);
+ tde->d_reclen = tswap16(treclen);
+ /* The target_dirent type is in what was formerly a padding
+ * byte at the end of the structure:
+ */
+ *(((char *)tde) + treclen - 1) = type;
+
+ de = (struct linux_dirent64 *)((char *)de + reclen);
+ tde = (struct target_dirent *)((char *)tde + treclen);
+ len -= reclen;
+ tlen += treclen;
+ }
+ ret = tlen;
+ }
+ unlock_user(dirp, arg2, ret);
+ }
+#endif
break;
#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
case TARGET_NR_getdents64:
--
1.7.9.5
next prev parent reply other threads:[~2013-06-12 16:24 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-12 15:57 [Qemu-devel] [PULL 00/13] tcg-aarch64 queue Peter Maydell
2013-06-12 15:57 ` Peter Maydell [this message]
2013-06-12 15:57 ` [Qemu-devel] [PULL 02/13] linux-user: Drop direct use of openat etc syscalls Peter Maydell
2013-06-12 15:57 ` [Qemu-devel] [PULL 03/13] configure: Drop CONFIG_ATFILE test Peter Maydell
2013-06-12 15:57 ` [Qemu-devel] [PULL 04/13] include/elf.h: add aarch64 ELF machine and relocs Peter Maydell
2013-06-12 15:57 ` [Qemu-devel] [PULL 05/13] tcg/aarch64: implement new TCG target for aarch64 Peter Maydell
2013-06-12 15:57 ` [Qemu-devel] [PULL 06/13] tcg/aarch64: improve arith shifted regs operations Peter Maydell
2013-06-12 15:57 ` [Qemu-devel] [PULL 07/13] tcg/aarch64: implement AND/TEST immediate pattern Peter Maydell
2013-06-12 15:57 ` [Qemu-devel] [PULL 08/13] tcg/aarch64: implement byte swap operations Peter Maydell
2013-06-12 15:57 ` [Qemu-devel] [PULL 09/13] tcg/aarch64: implement sign/zero extend operations Peter Maydell
2013-06-12 15:57 ` [Qemu-devel] [PULL 10/13] user-exec.c: aarch64 initial implementation of cpu_signal_handler Peter Maydell
2013-06-12 15:57 ` [Qemu-devel] [PULL 11/13] tcg/aarch64: implement user mode qemu ld/st Peter Maydell
2013-06-12 15:57 ` [Qemu-devel] [PULL 12/13] configure: permit compilation on arm aarch64 Peter Maydell
2013-06-12 15:57 ` [Qemu-devel] [PULL 13/13] MAINTAINERS: add tcg/aarch64 maintainer Peter Maydell
2013-06-17 21:17 ` [Qemu-devel] [PULL 00/13] tcg-aarch64 queue Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1371052645-9006-2-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=aliguori@us.ibm.com \
--cc=aurelien@aurel32.net \
--cc=blauwirbel@gmail.com \
--cc=claudio.fontana@huawei.com \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).