statfs64.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Return information about the filesystem on which FILE resides.
  2. Copyright (C) 1996-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <string.h>
  17. #include <stddef.h>
  18. #include <sysdep.h>
  19. #include <kernel_stat.h>
  20. /* Hide the prototypes for __statfs and statfs so that GCC will not
  21. complain about the different function signatures if they are aliased
  22. to __stat64. If STATFS_IS_STATFS64 is not zero then the statfs and
  23. statfs64 structures have an identical layout but different type names. */
  24. #if STATFS_IS_STATFS64
  25. # define __statfs __statfs_disable
  26. # define statfs statfs_disable
  27. #endif
  28. #include <sys/statfs.h>
  29. #include <kernel-features.h>
  30. # if __ASSUME_STATFS64 == 0
  31. int __no_statfs64 attribute_hidden;
  32. #endif
  33. /* Return information about the filesystem on which FILE resides. */
  34. int
  35. __statfs64 (const char *file, struct statfs64 *buf)
  36. {
  37. #ifdef __NR_statfs64
  38. # if __ASSUME_STATFS64 == 0
  39. if (! __no_statfs64)
  40. # endif
  41. {
  42. int result = INLINE_SYSCALL (statfs64, 3, file, sizeof (*buf), buf);
  43. # if __ASSUME_STATFS64 == 0
  44. if (result == 0 || errno != ENOSYS)
  45. # endif
  46. return result;
  47. # if __ASSUME_STATFS64 == 0
  48. __no_statfs64 = 1;
  49. # endif
  50. }
  51. #endif
  52. #if __ASSUME_STATFS64 == 0
  53. struct statfs buf32;
  54. if (__statfs (file, &buf32) < 0)
  55. return -1;
  56. buf->f_type = buf32.f_type;
  57. buf->f_bsize = buf32.f_bsize;
  58. buf->f_blocks = buf32.f_blocks;
  59. buf->f_bfree = buf32.f_bfree;
  60. buf->f_bavail = buf32.f_bavail;
  61. buf->f_files = buf32.f_files;
  62. buf->f_ffree = buf32.f_ffree;
  63. buf->f_fsid = buf32.f_fsid;
  64. buf->f_namelen = buf32.f_namelen;
  65. buf->f_frsize = buf32.f_frsize;
  66. memcpy (buf->f_spare, buf32.f_spare, sizeof (buf32.f_spare));
  67. return 0;
  68. #endif
  69. }
  70. weak_alias (__statfs64, statfs64)
  71. #undef __statfs
  72. #undef statfs
  73. #if STATFS_IS_STATFS64
  74. weak_alias (__statfs64, __statfs)
  75. weak_alias (__statfs64, statfs)
  76. libc_hidden_ver (__statfs64, __statfs)
  77. #endif