statvfs.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * statvfs function
  3. *
  4. * Copyright 2004 Alexandre Julliard
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #include "config.h"
  21. #include "wine/port.h"
  22. #ifndef HAVE_STATVFS
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25. #include <errno.h>
  26. #ifdef HAVE_SYS_PARAM_H
  27. # include <sys/param.h>
  28. #endif
  29. #ifdef HAVE_SYS_VFS_H
  30. # include <sys/vfs.h>
  31. #endif
  32. #ifdef HAVE_SYS_MOUNT_H
  33. # include <sys/mount.h>
  34. #endif
  35. #ifdef HAVE_SYS_STATFS_H
  36. # include <sys/statfs.h>
  37. #endif
  38. int statvfs( const char *path, struct statvfs *buf )
  39. {
  40. int ret;
  41. #ifdef HAVE_STATFS
  42. struct statfs info;
  43. /* FIXME: add autoconf check for this */
  44. #if defined(__svr4__) || defined(_SCO_DS) || defined(__sun)
  45. ret = statfs( path, &info, 0, 0 );
  46. #else
  47. ret = statfs( path, &info );
  48. #endif
  49. if (ret >= 0)
  50. {
  51. memset( buf, 0, sizeof(*buf) );
  52. buf->f_bsize = info.f_bsize;
  53. buf->f_blocks = info.f_blocks;
  54. buf->f_files = info.f_files;
  55. #ifdef HAVE_STRUCT_STATFS_F_NAMELEN
  56. buf->f_namemax = info.f_namelen;
  57. #endif
  58. #ifdef HAVE_STRUCT_STATFS_F_FRSIZE
  59. buf->f_frsize = info.f_frsize;
  60. #else
  61. buf->f_frsize = info.f_bsize;
  62. #endif
  63. #ifdef HAVE_STRUCT_STATFS_F_BFREE
  64. buf->f_bfree = info.f_bfree;
  65. #else
  66. buf->f_bfree = info.f_bavail;
  67. #endif
  68. #ifdef HAVE_STRUCT_STATFS_F_BAVAIL
  69. buf->f_bavail = info.f_bavail;
  70. #else
  71. buf->f_bavail = info.f_bfree;
  72. #endif
  73. #ifdef HAVE_STRUCT_STATFS_F_FFREE
  74. buf->f_ffree = info.f_ffree;
  75. #else
  76. buf->f_ffree = info.f_favail;
  77. #endif
  78. #ifdef HAVE_STRUCT_STATFS_F_FAVAIL
  79. buf->f_favail = info.f_favail;
  80. #else
  81. buf->f_favail = info.f_ffree;
  82. #endif
  83. }
  84. #else /* HAVE_STATFS */
  85. ret = -1;
  86. errno = ENOSYS;
  87. #endif /* HAVE_STATFS */
  88. return ret;
  89. }
  90. #endif /* HAVE_STATVFS */