posix_fadvise.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * posix_fadvise() for uClibc
  4. * http://www.opengroup.org/onlinepubs/009695399/functions/posix_fadvise.html
  5. *
  6. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  7. *
  8. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  9. */
  10. #include <sys/syscall.h>
  11. #ifdef __NR_arm_fadvise64_64
  12. /* We handle the 64bit alignment issue which is why the arm guys renamed their
  13. * syscall in the first place. So rename it back.
  14. */
  15. # define __NR_fadvise64_64 __NR_arm_fadvise64_64
  16. #endif
  17. #if defined(__NR_fadvise64) || defined(__NR_fadvise64_64)
  18. # include <fcntl.h>
  19. # include <endian.h>
  20. # include <bits/wordsize.h>
  21. # if defined(__NR_fadvise64_64) && defined(__UCLIBC_HAS_LFS__)
  22. #include <_lfs_64.h>
  23. int posix_fadvise64(int fd, off64_t offset, off64_t len, int advice);
  24. int posix_fadvise(int fd, off_t offset, off_t len, int advice)
  25. {
  26. return posix_fadvise64(fd, offset, len, advice);
  27. }
  28. #else
  29. int posix_fadvise(int fd, off_t offset, off_t len, int advice)
  30. {
  31. int ret;
  32. INTERNAL_SYSCALL_DECL(err);
  33. # ifdef __NR_fadvise64_64
  34. # if __WORDSIZE == 64
  35. ret = INTERNAL_SYSCALL(fadvise64_64, err, 4, fd, offset, len, advice);
  36. # else
  37. # if defined (__arm__) || \
  38. (defined(__UCLIBC_SYSCALL_ALIGN_64BIT__) && (defined(__powerpc__) || defined(__xtensa__)))
  39. /* arch with 64-bit data in even reg alignment #1: [powerpc/xtensa]
  40. * custom syscall handler (rearranges @advice to avoid register hole punch) */
  41. ret = INTERNAL_SYSCALL(fadvise64_64, err, 6, fd, advice,
  42. OFF_HI_LO (offset), OFF_HI_LO (len));
  43. # elif defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
  44. /* arch with 64-bit data in even reg alignment #2: [arcv2/others-in-future]
  45. * stock syscall handler in kernel (reg hole punched) */
  46. ret = INTERNAL_SYSCALL(fadvise64_64, err, 7, fd, 0,
  47. OFF_HI_LO (offset), OFF_HI_LO (len), advice);
  48. # else
  49. ret = INTERNAL_SYSCALL(fadvise64_64, err, 6, fd,
  50. OFF_HI_LO (offset), OFF_HI_LO (len), advice);
  51. # endif
  52. # endif
  53. # else /* __NR_fadvise64 */
  54. # if __WORDSIZE == 64
  55. ret = INTERNAL_SYSCALL(fadvise64, err, 4, fd, offset, len, advice);
  56. # else
  57. # if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
  58. ret = INTERNAL_SYSCALL(fadvise64, err, 6, fd, /*unused*/0,
  59. # else
  60. ret = INTERNAL_SYSCALL(fadvise64, err, 5, fd,
  61. # endif
  62. OFF_HI_LO (offset), len, advice);
  63. # endif
  64. # endif
  65. if (INTERNAL_SYSCALL_ERROR_P (ret, err))
  66. return INTERNAL_SYSCALL_ERRNO (ret, err);
  67. return 0;
  68. }
  69. # if defined __UCLIBC_HAS_LFS__ && (!defined __NR_fadvise64_64 || __WORDSIZE == 64)
  70. strong_alias(posix_fadvise,posix_fadvise64)
  71. # endif
  72. #endif
  73. #endif