[PATCH] fcntl cleanup

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Fri May 4 14:40:11 UTC 2012


On 4 May 2012 14:16, Mark Salter <msalter at redhat.com> wrote:
> This patch aims to clean up the current support for fcntl in the
> following ways:

Mark, this is handled on the future branch. Attaching the relevant
patches for reference.
The full set is at http://uclibc.org/~aldot/uClibc/psm-future.tar.gz
in case you want to help testing, let's say arm.
cheers,
>
>  * replace multiple istances of #ifdef selection between fcntl
>    and fcntl64 syscalls with a single INLINE_SYSCALL_FCNTL macro.
>    The fcntl64 syscall only exists on 32-bit systems and is
>    identical to the fcntl syscall except for the addition of
>    commands to support locking with 64-bit file offsets.
>
>  * only check for unsupported 64-bit locking commands in the
>    case of no LFS support or no fcntl64 syscall. This eliminates
>    unnecessary code for configurations which do support the
>    64-bit locking commands.
>
>  * add check for unsupported 64-bit locking commands which was
>    missing from the native threads case.
>
>  * in the non-native threads case, __libc_fcntl and __fcntl_nocancel
>    are identical, so make __libc_fcntl an alias of __fcntl_nocancel
>    to avoid two functions with the same code.
>
> Signed-off-by: Mark Salter <msalter at redhat.com>
> ---
>  libc/sysdeps/linux/common/__syscall_fcntl.c |   55 ++++++++++++--------------
>  1 files changed, 25 insertions(+), 30 deletions(-)
>
> diff --git a/libc/sysdeps/linux/common/__syscall_fcntl.c b/libc/sysdeps/linux/common/__syscall_fcntl.c
> index 6d4c339..06146b4 100644
> --- a/libc/sysdeps/linux/common/__syscall_fcntl.c
> +++ b/libc/sysdeps/linux/common/__syscall_fcntl.c
> @@ -16,6 +16,17 @@
>  #include <fcntl.h>
>  #include <bits/wordsize.h>
>
> +/*
> + * The fcntl64 syscall only exists on 32-Bit systems. It is identical to
> + * the fcntl syscall except for additial commands providing 32-bit systems
> + * with file locking operations using 64-bit offsets.
> + */
> +#if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
> +#define INLINE_SYSCALL_FCNTL(a,b,c) INLINE_SYSCALL(fcntl64, 3, (a), (b), (c))
> +#else
> +#define INLINE_SYSCALL_FCNTL(a,b,c) INLINE_SYSCALL(fcntl, 3, (a), (b), (c))
> +#endif
> +
>  extern __typeof(fcntl) __libc_fcntl;
>  libc_hidden_proto(__libc_fcntl)
>
> @@ -28,20 +39,17 @@ int __fcntl_nocancel (int fd, int cmd, ...)
>        arg = va_arg (ap, void *);
>        va_end (ap);
>
> -# if __WORDSIZE == 32
> +# if __WORDSIZE == 32 && !(defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64)
>        if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64) {
> -#  if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
> -               return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
> -#  else
>                __set_errno(ENOSYS);
>                return -1;
> -#  endif
>        }
>  # endif
> -       return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
> +       return INLINE_SYSCALL_FCNTL (fd, cmd, arg);
>  }
>  libc_hidden_def(__fcntl_nocancel)
>
> +#ifdef __UCLIBC_HAS_THREADS_NATIVE__
>  int __libc_fcntl (int fd, int cmd, ...)
>  {
>        va_list ap;
> @@ -51,39 +59,26 @@ int __libc_fcntl (int fd, int cmd, ...)
>        arg = va_arg (ap, void *);
>        va_end (ap);
>
> -#ifdef __UCLIBC_HAS_THREADS_NATIVE__
> -       if (SINGLE_THREAD_P || (cmd != F_SETLKW && cmd != F_SETLKW64))
> -# if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
> -               return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
> -# else
> -               return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
> -# endif
> +#if __WORDSIZE == 32 && !(defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64)
> +       if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64) {
> +               __set_errno(ENOSYS);
> +               return -1;
> +       }
> +#endif
>
> +       if (SINGLE_THREAD_P || (cmd != F_SETLKW && cmd != F_SETLKW64))
> +               return INLINE_SYSCALL_FCNTL (fd, cmd, arg);
>        int oldtype = LIBC_CANCEL_ASYNC ();
>
> -# if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
> -       int result = INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
> -# else
> -       int result = INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
> -# endif
> +       int result = INLINE_SYSCALL_FCNTL (fd, cmd, arg);
>
>        LIBC_CANCEL_RESET (oldtype);
>
>        return result;
> +}
>  #else
> -# if __WORDSIZE == 32
> -       if (cmd == F_GETLK64 || cmd == F_SETLK64 || cmd == F_SETLKW64) {
> -#  if defined __UCLIBC_HAS_LFS__ && defined __NR_fcntl64
> -               return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
> -#  else
> -               __set_errno(ENOSYS);
> -               return -1;
> -#  endif
> -       }
> -# endif
> -       return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
> +strong_alias(__fcntl_nocancel,__libc_fcntl)
>  #endif
> -}
>  libc_hidden_def(__libc_fcntl)
>
>  libc_hidden_proto(fcntl)
> --
> 1.7.9.1
>
> _______________________________________________
> uClibc mailing list
> uClibc at uclibc.org
> http://lists.busybox.net/mailman/listinfo/uclibc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0307-fcntl-add-cancellation-to-fcntl64-use-cancel.h.patch
Type: application/octet-stream
Size: 6041 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/uclibc/attachments/20120504/e83387e3/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0322-wrapsyscall.c-add-cancellable-fcntl64.patch
Type: application/octet-stream
Size: 1074 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/uclibc/attachments/20120504/e83387e3/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0257-64.-cS-use-_lfs_64.h-instead-of-features.h-and-remov.patch
Type: application/octet-stream
Size: 18410 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/uclibc/attachments/20120504/e83387e3/attachment-0005.obj>


More information about the uClibc mailing list