statvfs64.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Return information about the filesystem on which FILE resides.
  2. Copyright (C) 1998-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 <stddef.h>
  17. #include <string.h>
  18. #include <sys/stat.h>
  19. #include <sys/statfs.h>
  20. #include "internal_statvfs.h"
  21. #include <kernel-features.h>
  22. /* Return information about the filesystem on which FILE resides. */
  23. int
  24. __statvfs64 (const char *file, struct statvfs64 *buf)
  25. {
  26. struct statfs64 fsbuf;
  27. int res = __statfs64 (file, &fsbuf);
  28. #ifndef __ASSUME_STATFS64
  29. if (res < 0 && errno == ENOSYS)
  30. {
  31. struct statvfs buf32;
  32. res = statvfs (file, &buf32);
  33. if (res == 0)
  34. {
  35. buf->f_bsize = buf32.f_bsize;
  36. buf->f_frsize = buf32.f_frsize;
  37. buf->f_blocks = buf32.f_blocks;
  38. buf->f_bfree = buf32.f_bfree;
  39. buf->f_bavail = buf32.f_bavail;
  40. buf->f_files = buf32.f_files;
  41. buf->f_ffree = buf32.f_ffree;
  42. buf->f_favail = buf32.f_favail;
  43. buf->f_fsid = buf32.f_fsid;
  44. buf->f_flag = buf32.f_flag;
  45. buf->f_namemax = buf32.f_namemax;
  46. memcpy (buf->__f_spare, buf32.__f_spare, sizeof (buf32.__f_spare));
  47. }
  48. }
  49. #endif
  50. if (res == 0)
  51. /* Convert the result. */
  52. __internal_statvfs64 (file, buf, &fsbuf, -1);
  53. return res;
  54. }
  55. weak_alias (__statvfs64, statvfs64)