qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Aleksandar Markovic <amarkovic@wavecomp.com>
To: Laurent Vivier <laurent@vivier.eu>,
	Aleksandar Markovic <aleksandar.markovic@rt-rk.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: Aleksandar Rikalo <arikalo@wavecomp.com>, Jim Wilson <jimw@sifive.com>
Subject: Re: [Qemu-devel] [PATCH v12 3/5] linux-user: Add support for translation of statx() syscall
Date: Thu, 27 Jun 2019 13:18:30 +0000	[thread overview]
Message-ID: <BN6PR2201MB12510D08346C1EBF5BACB709C6FD0@BN6PR2201MB1251.namprd22.prod.outlook.com> (raw)
In-Reply-To: <75367706-a29d-605e-a3b4-0aa483b521c4@vivier.eu>

> From: Laurent Vivier <laurent@vivier.eu>
> 
> > @@ -10173,6 +10225,88 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long > arg1,
> >              ret = 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 = arg1;
> > +            int flags = arg3;
> > +
> > +            p = lock_user_string(arg2);
> > +            if (p == NULL) {
> > +                return -TARGET_EFAULT;
> > +            }
> > +#if defined(__NR_statx)
> > +            {
> > +                /*
> > +                 * It is assumed that struct statx is architecture independent.
> > +                 */
> > +                struct target_statx host_stx;
> > +                int mask = arg4;
> > +
> > +                ret = get_errno(statx(dirfd, p, flags, mask, &host_stx));
> > +                if (!is_error(ret)) {
> > +                    if (host_to_target_statx(&host_stx, arg5) != 0) {
> > +                        unlock_user(p, arg2, 0);
> > +                        return -TARGET_EFAULT;
> > +                    }
> > +                }
> > +
> > +                if (ret != -TARGET_ENOSYS) {
> > +                    unlock_user(p, arg2, 0);
> > +                    return ret;
> > +                }
> > +            }
> > +#endif
> > +            if (*((char *)p) == 0) {
> > +                /*
> > +                 * By file descriptor
> > +                 */
> > +                if (flags & AT_EMPTY_PATH) {
> > +                    unlock_user(p, arg2, 0);
> > +                    return -TARGET_ENOENT;
> > +                }
> > +                ret = get_errno(fstat(dirfd, &st));
> > +            } else if (*((char *)p) == '/') {
> > +                /*
> > +                 * By absolute pathname
> > +                 */
> > +                ret = get_errno(stat(path(p), &st));
> > +            } else {
> > +                /*
> > +                 * By pathname relative to the current working directory
> > +                 * (if 'dirfd' is AT_FDCWD) or relative to the directory
> > +                 * referred to by the file descriptor 'dirfd'.
> > +                 */
> > +                 ret = get_errno(fstatat(dirfd, path(p), &st, flags));
> > +            }
> > +            unlock_user(p, arg2, 0);
> 
> Could you explain why we can't use fstatat() for the two previous cases
> "(*((char *)p) == 0)" and "(*((char *)p) == '/')"?
> 

Man page on fstatat (http://man7.org/linux/man-pages/man2/stat.2.html)
says:

   AT_EMPTY_PATH (since Linux 2.6.39)
          If pathname is an empty string, operate on the file referred
          to by dirfd (which may have been obtained using the open(2)
          O_PATH flag).  In this case, dirfd can refer to any type of
          file, not just a directory, and the behavior of fstatat() is
          similar to that of fstat().  If dirfd is AT_FDCWD, the call
          operates on the current working directory.  This flag is
          Linux-specific; define _GNU_SOURCE to obtain its definition.

So it looks the branch "if (*((char *)p) == 0)" can be handled by
fstatat().

Also, the man page says:

   If pathname is absolute, then dirfd is ignored.

So, it looks the case "else if (*((char *)p) == '/')" can also be
handled by fstatat().

Very similar descriptions of the cases above can be found in
the man page for statx
(http://man7.org/linux/man-pages/man2/statx.2.html).

The whole string of if statements after "#endif" above should be now,
in my opinion:

        ret = get_errno(fstatat(dirfd, path(p), &st, flags));
        unlock_user(p, arg2, 0);

... and I will submit the patch with such code, if noone objects.

Yours,
Aleksandar Markovic

> Thanks,
> Laurent



  reply	other threads:[~2019-06-27 13:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-19 14:17 [Qemu-devel] [PATCH v12 0/5] Aleksandar Markovic
2019-06-19 14:17 ` [Qemu-devel] [PATCH v12 1/5] linux-user: Add support for setsockopt() options IPV6_<ADD|DROP>_MEMBERSHIP Aleksandar Markovic
2019-06-19 16:08   ` Laurent Vivier
2019-06-24 21:04   ` Laurent Vivier
2019-06-19 14:17 ` [Qemu-devel] [PATCH v12 2/5] linux-user: Add support for setsockopt() option SOL_ALG Aleksandar Markovic
2019-06-24 21:01   ` Laurent Vivier
2019-06-19 14:17 ` [Qemu-devel] [PATCH v12 3/5] linux-user: Add support for translation of statx() syscall Aleksandar Markovic
2019-06-19 16:11   ` Laurent Vivier
2019-06-27 13:18     ` Aleksandar Markovic [this message]
2019-06-27 14:01       ` Laurent Vivier
2019-06-19 14:17 ` [Qemu-devel] [PATCH v12 4/5] linux-user: Add support for strace for " Aleksandar Markovic
2019-06-19 14:17 ` [Qemu-devel] [PATCH v12 5/5] linux-user: Fix flock structure for MIPS O64 ABI Aleksandar Markovic
2019-06-19 16:21   ` Laurent Vivier
2019-06-26  7:54     ` Aleksandar Markovic
2019-06-26  7:57       ` Laurent Vivier
2019-06-19 14:54 ` [Qemu-devel] [PATCH v12 0/5] no-reply
2019-06-19 15:34 ` no-reply

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=BN6PR2201MB12510D08346C1EBF5BACB709C6FD0@BN6PR2201MB1251.namprd22.prod.outlook.com \
    --to=amarkovic@wavecomp.com \
    --cc=aleksandar.markovic@rt-rk.com \
    --cc=arikalo@wavecomp.com \
    --cc=jimw@sifive.com \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    /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).