[PATCH] Fix posix_fadvise for x86 and arm

Atsushi Nemoto anemo at mba.ocn.ne.jp
Wed Mar 7 02:28:26 UTC 2007


On Tue, 06 Mar 2007 00:09:41 -0800, Khem Raj <kraj at mvista.com> wrote:
> Here is the patch I committed. There were few changes made to the patch 
> I posted earlier.
> Tested on arm x86 and mips. mips needed a kernel patch from Atsushi
> http://www.nabble.com/fadvise-on-MIPS-t3240150.html
> to verify.

Thank you for patch and testing.

> --- uclibc-0.9.29.orig/libc/sysdeps/linux/common/posix_fadvise.c
> +++ uclibc-0.9.29/libc/sysdeps/linux/common/posix_fadvise.c
> @@ -19,9 +19,25 @@
>  
>  #ifdef __NR_fadvise64
>  #define __NR_posix_fadvise __NR_fadvise64
> +/* get rid of following conditional when
> +   all supported arches are having INTERNAL_SYSCALL defined
> +*/
> +#ifdef INTERNAL_SYSCALL
> +int posix_fadvise(int fd, off_t offset, off_t len, int advice)
> +{
> +	INTERNAL_SYSCALL_DECL(err);
> +	int ret = (int) (INTERNAL_SYSCALL(posix_fadvise, err, 5, fd,
> +	 __LONG_LONG_PAIR (offset >> 31, offset), len, advice));
> +    if (INTERNAL_SYSCALL_ERROR_P (ret, err))
> +      return INTERNAL_SYSCALL_ERRNO (ret, err);
> +    return 0;
> +}
> +#else
>  _syscall4(int, posix_fadvise, int, fd, off_t, offset,
>            off_t, len, int, advice);
>  
> +#endif

This would break 64-bit (i.e. WORDSIZE==64) platforms.  The kernel
expect that the 'offset' is passed in a single argument.  glibc does
so in sysdeps/unix/sysv/linux/wordsize-64/posix_fadvise.c.

> --- uclibc-0.9.29.orig/libc/sysdeps/linux/common/posix_fadvise64.c
> +++ uclibc-0.9.29/libc/sysdeps/linux/common/posix_fadvise64.c
> @@ -24,8 +24,25 @@
>  #if __WORDSIZE == 64
>  
>  #define __NR_posix_fadvise64 __NR_fadvise64_64
> +
> +#ifdef INTERNAL_SYSCALL
> +int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
> +{
> +  if (len != (off_t) len)
> +    return EOVERFLOW;
> +  INTERNAL_SYSCALL_DECL (err);
> +    int ret = INTERNAL_SYSCALL (posix_fadvise64, err, 6, fd,
> +                               __LONG_LONG_PAIR ((long) (offset >> 32),
> +                                                 (long) offset),
> +                               (off_t) len, advise);
> +  if (!INTERNAL_SYSCALL_ERROR_P (ret, err))
> +    return 0;
> +  return INTERNAL_SYSCALL_ERRNO (ret, err);
> +}
> +#else
>  _syscall4(int, posix_fadvise64, int, fd, __off64_t, offset,
>            __off64_t, len, int, advice);
> +#endif

Ditto.  But I wonder any 64-bit platform need posix_fadvise64.
glibc's sysdeps/unix/sysv/linux/wordsize-64/posix_fadvise64.c is empty
and posix_fadvise64 is an (strong) alias of posix_fadvise.

---
Atsushi Nemoto



More information about the uClibc mailing list