Patchwork [04/10] linux-user: Sync fcntl.h bits with the kernel

login
register
mail settings
Submitter Richard Henderson
Date July 25, 2012, 10:10 p.m.
Message ID <1343254238-4727-5-git-send-email-rth@twiddle.net>
Download mbox | patch
Permalink /patch/173296/
State New
Headers show

Comments

Richard Henderson - July 25, 2012, 10:10 p.m.
For each target, only define the bits that appear in
arch/target/include/asm/fcntl.h.  Mirror the kernel's
asm-generic layout by handling anything undefined afterward.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 linux-user/syscall_defs.h |  195 +++++++++++++++++++++-----------------------
 1 files changed, 93 insertions(+), 102 deletions(-)
Peter Maydell - Aug. 2, 2012, 2:34 p.m.
On 25 July 2012 23:10, Richard Henderson <rth@twiddle.net> wrote:
> For each target, only define the bits that appear in
> arch/target/include/asm/fcntl.h.  Mirror the kernel's
> asm-generic layout by handling anything undefined afterward.
>
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
>  linux-user/syscall_defs.h |  195 +++++++++++++++++++++-----------------------
>  1 files changed, 93 insertions(+), 102 deletions(-)
>
> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
> index 02fe4f6..974d6f5 100644
> --- a/linux-user/syscall_defs.h
> +++ b/linux-user/syscall_defs.h
> @@ -2012,135 +2012,126 @@ struct target_statfs64 {
>  #define TARGET_F_DUPFD_CLOEXEC (TARGET_F_LINUX_SPECIFIC_BASE + 6)
>  #define TARGET_F_NOTIFY  (TARGET_F_LINUX_SPECIFIC_BASE+2)
>

No entries for TARGET_M68K? I checked and I think that's the
only supported arch which isn't listed here and isn't only using
the asm-generic values. (It's the same 4 defines as TARGET_ARM.)

> -#if defined (TARGET_ARM)
> -#define TARGET_O_ACCMODE          0003
> -#define TARGET_O_RDONLY             00
> -#define TARGET_O_WRONLY             01
> -#define TARGET_O_RDWR               02
> -#define TARGET_O_CREAT            0100 /* not fcntl */
> -#define TARGET_O_EXCL             0200 /* not fcntl */
> -#define TARGET_O_NOCTTY           0400 /* not fcntl */
> -#define TARGET_O_TRUNC           01000 /* not fcntl */
> -#define TARGET_O_APPEND          02000
> -#define TARGET_O_NONBLOCK        04000
> -#define TARGET_O_NDELAY        TARGET_O_NONBLOCK
> -#define TARGET_O_SYNC           010000
> -#define TARGET_FASYNC           020000 /* fcntl, for BSD compatibility */
> +#if defined(TARGET_ALPHA)
> +#define TARGET_O_NONBLOCK          04
> +#define TARGET_O_APPEND            010
> +#define TARGET_O_CREAT           01000 /* not fcntl */
> +#define TARGET_O_TRUNC           02000 /* not fcntl */
> +#define TARGET_O_EXCL            04000 /* not fcntl */
> +#define TARGET_O_NOCTTY         010000 /* not fcntl */
> +#define TARGET_FASYNC          020000 /* fcntl, for BSD compatibility */
> +#define TARGET_O_DSYNC         040000
> +#define TARGET_O_LARGEFILE          0  /* not necessary, always 64-bit */
> +#define TARGET_O_DIRECTORY     0100000 /* must be a directory */
> +#define TARGET_O_NOFOLLOW      0200000 /* don't follow links */
> +#define TARGET_O_DIRECT       02000000 /* direct disk access hint */
> +#define TARGET_O_NOATIME      04000000
> +#define TARGET_O_CLOEXEC     010000000
> +#define TARGET___O_SYNC      020000000
> +#define TARGET_O_PATH        040000000

The other targets were all straightforward to review but I had a
little difficulty with the Alpha bits here.
(1) O_LARGEFILE is 0 here but not in the kernel. Does the "not
necessary" comment here mean "not necessary for QEMU" ?
(ie is the difference because we are taking a different approach to
the kernel's "always set this bit on entry" one ?)

(2) where has the TARGET_FASYNC entry come from?

There are also a couple of hardcoded tabs lurking in some of
these lines which it would be nice to get rid of since we're
changing the code anyway. (checkpatch will tell you where they are.)

> +#elif defined (TARGET_ARM)

Not having the space between 'defined' and '(' would be consistent
with the TARGET_ALPHA one, be consistent with the lion's share of
defined() uses elswhere and also shut checkpatch up :-)

Otherwise good and I've checked all the numbers against the kernel
headers.

-- PMM
Richard Henderson - Aug. 2, 2012, 3:17 p.m.
On 2012-08-02 07:34, Peter Maydell wrote:
> No entries for TARGET_M68K? I checked and I think that's the
> only supported arch which isn't listed here and isn't only using
> the asm-generic values. (It's the same 4 defines as TARGET_ARM.)

I didn't notice because it was missing beforehand.

> The other targets were all straightforward to review but I had a
> little difficulty with the Alpha bits here.
> (1) O_LARGEFILE is 0 here but not in the kernel. Does the "not
> necessary" comment here mean "not necessary for QEMU" ?
> (ie is the difference because we are taking a different approach to
> the kernel's "always set this bit on entry" one ?)

Yes.  The fact that the kernel forces O_LARGEFILE set means that
from an ABI perspective it might as well be zero.  The fact that
it is defined to non-zero in kernel headers is merely historical,
and probably to document that the bit was used once.

> 
> (2) where has the TARGET_FASYNC entry come from?

You mean why isn't it using the default below?  Good question...


r~

Patch

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 02fe4f6..974d6f5 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2012,135 +2012,126 @@  struct target_statfs64 {
 #define TARGET_F_DUPFD_CLOEXEC (TARGET_F_LINUX_SPECIFIC_BASE + 6)
 #define TARGET_F_NOTIFY  (TARGET_F_LINUX_SPECIFIC_BASE+2)
 
-#if defined (TARGET_ARM)
-#define TARGET_O_ACCMODE          0003
-#define TARGET_O_RDONLY             00
-#define TARGET_O_WRONLY             01
-#define TARGET_O_RDWR               02
-#define TARGET_O_CREAT            0100 /* not fcntl */
-#define TARGET_O_EXCL             0200 /* not fcntl */
-#define TARGET_O_NOCTTY           0400 /* not fcntl */
-#define TARGET_O_TRUNC           01000 /* not fcntl */
-#define TARGET_O_APPEND          02000
-#define TARGET_O_NONBLOCK        04000
-#define TARGET_O_NDELAY        TARGET_O_NONBLOCK
-#define TARGET_O_SYNC           010000
-#define TARGET_FASYNC           020000 /* fcntl, for BSD compatibility */
+#if defined(TARGET_ALPHA)
+#define TARGET_O_NONBLOCK	    04
+#define TARGET_O_APPEND            010
+#define TARGET_O_CREAT           01000 /* not fcntl */
+#define TARGET_O_TRUNC           02000 /* not fcntl */
+#define TARGET_O_EXCL            04000 /* not fcntl */
+#define TARGET_O_NOCTTY         010000 /* not fcntl */
+#define TARGET_FASYNC		020000 /* fcntl, for BSD compatibility */
+#define TARGET_O_DSYNC		040000
+#define TARGET_O_LARGEFILE	     0	/* not necessary, always 64-bit */
+#define TARGET_O_DIRECTORY     0100000 /* must be a directory */
+#define TARGET_O_NOFOLLOW      0200000 /* don't follow links */
+#define TARGET_O_DIRECT       02000000 /* direct disk access hint */
+#define TARGET_O_NOATIME      04000000
+#define TARGET_O_CLOEXEC     010000000
+#define TARGET___O_SYNC      020000000
+#define TARGET_O_PATH        040000000
+#elif defined (TARGET_ARM)
 #define TARGET_O_DIRECTORY      040000 /* must be a directory */
 #define TARGET_O_NOFOLLOW      0100000 /* don't follow links */
 #define TARGET_O_DIRECT        0200000 /* direct disk access hint */
 #define TARGET_O_LARGEFILE     0400000
+#elif defined(TARGET_MIPS)
+#define TARGET_O_APPEND         0x0008
+#define TARGET_O_DSYNC          0x0010
+#define TARGET_O_NONBLOCK       0x0080
+#define TARGET_O_CREAT          0x0100  /* not fcntl */
+#define TARGET_O_TRUNC          0x0200  /* not fcntl */
+#define TARGET_O_EXCL           0x0400  /* not fcntl */
+#define TARGET_O_NOCTTY         0x0800  /* not fcntl */
+#define TARGET_FASYNC           0x1000  /* fcntl, for BSD compatibility */
+#define TARGET_O_LARGEFILE      0x2000  /* allow large file opens */
+#define TARGET___O_SYNC         0x4000
+#define TARGET_O_DIRECT         0x8000  /* direct disk access hint */
 #elif defined (TARGET_PPC)
-#define TARGET_O_ACCMODE          0003
-#define TARGET_O_RDONLY             00
-#define TARGET_O_WRONLY             01
-#define TARGET_O_RDWR               02
-#define TARGET_O_CREAT            0100 /* not fcntl */
-#define TARGET_O_EXCL             0200 /* not fcntl */
-#define TARGET_O_NOCTTY           0400 /* not fcntl */
-#define TARGET_O_TRUNC           01000 /* not fcntl */
-#define TARGET_O_APPEND          02000
-#define TARGET_O_NONBLOCK        04000
-#define TARGET_O_NDELAY        TARGET_O_NONBLOCK
-#define TARGET_O_SYNC           010000
-#define TARGET_FASYNC           020000 /* fcntl, for BSD compatibility */
-#define TARGET_O_DIRECTORY      040000 /* must be a directory */
-#define TARGET_O_NOFOLLOW      0100000 /* don't follow links */
-#define TARGET_O_LARGEFILE     0200000
-#define TARGET_O_DIRECT        0400000 /* direct disk access hint */
-#elif defined (TARGET_MICROBLAZE)
-#define TARGET_O_ACCMODE          0003
-#define TARGET_O_RDONLY             00
-#define TARGET_O_WRONLY             01
-#define TARGET_O_RDWR               02
-#define TARGET_O_CREAT            0100 /* not fcntl */
-#define TARGET_O_EXCL             0200 /* not fcntl */
-#define TARGET_O_NOCTTY           0400 /* not fcntl */
-#define TARGET_O_TRUNC           01000 /* not fcntl */
-#define TARGET_O_APPEND          02000
-#define TARGET_O_NONBLOCK        04000
-#define TARGET_O_NDELAY        TARGET_O_NONBLOCK
-#define TARGET_O_SYNC           010000
-#define TARGET_FASYNC           020000 /* fcntl, for BSD compatibility */
 #define TARGET_O_DIRECTORY      040000 /* must be a directory */
 #define TARGET_O_NOFOLLOW      0100000 /* don't follow links */
 #define TARGET_O_LARGEFILE     0200000
 #define TARGET_O_DIRECT        0400000 /* direct disk access hint */
 #elif defined (TARGET_SPARC)
-#define TARGET_O_RDONLY        0x0000
-#define TARGET_O_WRONLY        0x0001
-#define TARGET_O_RDWR          0x0002
-#define TARGET_O_ACCMODE       0x0003
-#define TARGET_O_APPEND        0x0008
-#define TARGET_FASYNC          0x0040  /* fcntl, for BSD compatibility */
-#define TARGET_O_CREAT         0x0200  /* not fcntl */
-#define TARGET_O_TRUNC         0x0400  /* not fcntl */
-#define TARGET_O_EXCL          0x0800  /* not fcntl */
-#define TARGET_O_SYNC          0x2000
-#define TARGET_O_NONBLOCK      0x4000
-#define TARGET_O_NDELAY        (0x0004 | TARGET_O_NONBLOCK)
-#define TARGET_O_NOCTTY        0x8000  /* not fcntl */
-#define TARGET_O_DIRECTORY     0x10000 /* must be a directory */
-#define TARGET_O_NOFOLLOW      0x20000 /* don't follow links */
+#define TARGET_O_APPEND         0x0008
+#define TARGET_FASYNC           0x0040  /* fcntl, for BSD compatibility */
+#define TARGET_O_CREAT          0x0200  /* not fcntl */
+#define TARGET_O_TRUNC          0x0400  /* not fcntl */
+#define TARGET_O_EXCL           0x0800  /* not fcntl */
+#define TARGET_O_DSYNC          0x2000
+#define TARGET_O_NONBLOCK       0x4000
+# ifdef TARGET_SPARC64
+#  define TARGET_O_NDELAY       0x0004
+# else
+#  define TARGET_O_NDELAY       (0x0004 | TARGET_O_NONBLOCK)
+# endif
+#define TARGET_O_NOCTTY         0x8000  /* not fcntl */
 #define TARGET_O_LARGEFILE     0x40000
-#define TARGET_O_DIRECT        0x100000 /* direct disk access hint */
-#elif defined(TARGET_MIPS)
-#define TARGET_O_ACCMODE	0x0003
-#define TARGET_O_RDONLY	0x0000
-#define TARGET_O_WRONLY	0x0001
-#define TARGET_O_RDWR		0x0002
-#define TARGET_O_APPEND	0x0008
-#define TARGET_O_SYNC		0x0010
-#define TARGET_O_NONBLOCK	0x0080
-#define TARGET_O_CREAT         0x0100	/* not fcntl */
-#define TARGET_O_TRUNC		0x0200	/* not fcntl */
-#define TARGET_O_EXCL		0x0400	/* not fcntl */
-#define TARGET_O_NOCTTY	0x0800	/* not fcntl */
-#define TARGET_FASYNC		0x1000	/* fcntl, for BSD compatibility */
-#define TARGET_O_LARGEFILE	0x2000	/* allow large file opens */
-#define TARGET_O_DIRECT	0x8000	/* direct disk access hint */
-#define TARGET_O_DIRECTORY	0x10000	/* must be a directory */
-#define TARGET_O_NOFOLLOW	0x20000	/* don't follow links */
-#define TARGET_O_NOATIME	0x40000
-#define TARGET_O_NDELAY	TARGET_O_NONBLOCK
-#elif defined(TARGET_ALPHA)
-#define TARGET_O_ACCMODE	0x0003
-#define TARGET_O_RDONLY	0x0000
-#define TARGET_O_WRONLY	0x0001
-#define TARGET_O_RDWR		0x0002
-#define TARGET_O_APPEND	0x0008
-#define TARGET_O_SYNC		0x4000
-#define TARGET_O_NONBLOCK	0x0004
-#define TARGET_O_CREAT         0x0200	/* not fcntl */
-#define TARGET_O_TRUNC		0x0400	/* not fcntl */
-#define TARGET_O_EXCL		0x0800	/* not fcntl */
-#define TARGET_O_NOCTTY	0x1000	/* not fcntl */
-#define TARGET_FASYNC		0x2000	/* fcntl, for BSD compatibility */
-#define TARGET_O_LARGEFILE	0x0000	/* not necessary, always 64-bit */
-#define TARGET_O_DIRECT	0x80000	/* direct disk access hint */
-#define TARGET_O_DIRECTORY	0x8000	/* must be a directory */
-#define TARGET_O_NOFOLLOW	0x10000	/* don't follow links */
-#define TARGET_O_NOATIME	0x100000
-#define TARGET_O_NDELAY	TARGET_O_NONBLOCK
-#else
+#define TARGET_O_DIRECT       0x100000  /* direct disk access hint */
+#define TARGET_O_NOATIME      0x200000
+#define TARGET_O_CLOEXEC      0x400000
+#define TARGET___O_SYNC       0x800000
+#define TARGET_O_PATH        0x1000000
+#endif
+
+/* <asm-generic/fcntl.h> values follow.  */
 #define TARGET_O_ACCMODE          0003
 #define TARGET_O_RDONLY             00
 #define TARGET_O_WRONLY             01
 #define TARGET_O_RDWR               02
+#ifndef TARGET_O_CREAT
 #define TARGET_O_CREAT            0100 /* not fcntl */
+#endif
+#ifndef TARGET_O_EXCL
 #define TARGET_O_EXCL             0200 /* not fcntl */
+#endif
+#ifndef TARGET_O_NOCTTY
 #define TARGET_O_NOCTTY           0400 /* not fcntl */
+#endif
+#ifndef TARGET_O_TRUNC
 #define TARGET_O_TRUNC           01000 /* not fcntl */
+#endif
+#ifndef TARGET_O_APPEND
 #define TARGET_O_APPEND          02000
+#endif
+#ifndef TARGET_O_NONBLOCK
 #define TARGET_O_NONBLOCK        04000
-#define TARGET_O_NDELAY        TARGET_O_NONBLOCK
-#define TARGET_O_SYNC           010000
+#endif
+#ifndef TARGET_O_DSYNC
+#define TARGET_O_DSYNC          010000
+#endif
+#ifndef TARGET_FASYNC
 #define TARGET_FASYNC           020000 /* fcntl, for BSD compatibility */
+#endif
+#ifndef TARGET_O_DIRECT
 #define TARGET_O_DIRECT         040000 /* direct disk access hint */
+#endif
+#ifndef TARGET_O_LARGEFILE
 #define TARGET_O_LARGEFILE     0100000
+#endif
+#ifndef TARGET_O_DIRECTORY
 #define TARGET_O_DIRECTORY     0200000 /* must be a directory */
+#endif
+#ifndef TARGET_O_NOFOLLOW
 #define TARGET_O_NOFOLLOW      0400000 /* don't follow links */
 #endif
+#ifndef TARGET_O_NOATIME
+#define TARGET_O_NOATIME      01000000
+#endif
+#ifndef TARGET_O_CLOEXEC
+#define TARGET_O_CLOEXEC      02000000
+#endif
+#ifndef TARGET___O_SYNC
+#define TARGET___O_SYNC       04000000
+#endif
+#ifndef TARGET_O_PATH
+#define TARGET_O_PATH        010000000
+#endif
+#ifndef TARGET_O_NDELAY
+#define TARGET_O_NDELAY  TARGET_O_NONBLOCK
+#endif
+#ifndef TARGET_O_SYNC
+#define TARGET_O_SYNC    (TARGET___O_SYNC | TARGET_O_DSYNC)
+#endif
 
 struct target_flock {
 	short l_type;