fsusage.m4 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. # serial 24
  2. # Obtaining file system usage information.
  3. # Copyright (C) 1997-1998, 2000-2001, 2003-2009 Free Software Foundation, Inc.
  4. #
  5. # This file is free software; the Free Software Foundation
  6. # gives unlimited permission to copy and/or distribute it,
  7. # with or without modifications, as long as this notice is preserved.
  8. # Written by Jim Meyering.
  9. AC_DEFUN([gl_FSUSAGE],
  10. [
  11. AC_CHECK_HEADERS_ONCE([sys/param.h])
  12. AC_CHECK_HEADERS_ONCE([sys/vfs.h sys/fs_types.h])
  13. AC_CHECK_HEADERS([sys/mount.h], [], [],
  14. [AC_INCLUDES_DEFAULT
  15. [#if HAVE_SYS_PARAM_H
  16. #include <sys/param.h>
  17. #endif]])
  18. gl_FILE_SYSTEM_USAGE([gl_cv_fs_space=yes], [gl_cv_fs_space=no])
  19. if test $gl_cv_fs_space = yes; then
  20. AC_LIBOBJ([fsusage])
  21. gl_PREREQ_FSUSAGE_EXTRA
  22. fi
  23. ])
  24. # Try to determine how a program can obtain file system usage information.
  25. # If successful, define the appropriate symbol (see fsusage.c) and
  26. # execute ACTION-IF-FOUND. Otherwise, execute ACTION-IF-NOT-FOUND.
  27. #
  28. # gl_FILE_SYSTEM_USAGE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
  29. AC_DEFUN([gl_FILE_SYSTEM_USAGE],
  30. [
  31. AC_MSG_NOTICE([checking how to get file system space usage])
  32. ac_fsusage_space=no
  33. # Perform only the link test since it seems there are no variants of the
  34. # statvfs function. This check is more than just AC_CHECK_FUNCS([statvfs])
  35. # because that got a false positive on SCO OSR5. Adding the declaration
  36. # of a `struct statvfs' causes this test to fail (as it should) on such
  37. # systems. That system is reported to work fine with STAT_STATFS4 which
  38. # is what it gets when this test fails.
  39. if test $ac_fsusage_space = no; then
  40. # SVR4
  41. AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs],
  42. [AC_TRY_LINK([#include <sys/types.h>
  43. #if defined __GLIBC__ && defined __linux__
  44. Do not use statvfs on systems with GNU libc on Linux, because that function
  45. stats all preceding entries in /proc/mounts, and that makes df hang if even
  46. one of the corresponding file systems is hard-mounted, but not available.
  47. statvfs in GNU libc on Hurd, BeOS, Haiku operates differently: it only makes
  48. a system call.
  49. #endif
  50. #ifdef __osf__
  51. "Do not use Tru64's statvfs implementation"
  52. #endif
  53. #include <sys/statvfs.h>],
  54. [struct statvfs fsd; statvfs (0, &fsd);],
  55. fu_cv_sys_stat_statvfs=yes,
  56. fu_cv_sys_stat_statvfs=no)])
  57. if test $fu_cv_sys_stat_statvfs = yes; then
  58. ac_fsusage_space=yes
  59. AC_DEFINE([STAT_STATVFS], [1],
  60. [ Define if there is a function named statvfs. (SVR4)])
  61. fi
  62. fi
  63. if test $ac_fsusage_space = no; then
  64. # DEC Alpha running OSF/1
  65. AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
  66. AC_CACHE_VAL([fu_cv_sys_stat_statfs3_osf1],
  67. [AC_TRY_RUN([
  68. #include <sys/param.h>
  69. #include <sys/types.h>
  70. #include <sys/mount.h>
  71. int
  72. main ()
  73. {
  74. struct statfs fsd;
  75. fsd.f_fsize = 0;
  76. return statfs (".", &fsd, sizeof (struct statfs)) != 0;
  77. }],
  78. fu_cv_sys_stat_statfs3_osf1=yes,
  79. fu_cv_sys_stat_statfs3_osf1=no,
  80. fu_cv_sys_stat_statfs3_osf1=no)])
  81. AC_MSG_RESULT([$fu_cv_sys_stat_statfs3_osf1])
  82. if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
  83. ac_fsusage_space=yes
  84. AC_DEFINE([STAT_STATFS3_OSF1], [1],
  85. [ Define if statfs takes 3 args. (DEC Alpha running OSF/1)])
  86. fi
  87. fi
  88. if test $ac_fsusage_space = no; then
  89. # AIX
  90. AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
  91. member (AIX, 4.3BSD)])
  92. AC_CACHE_VAL([fu_cv_sys_stat_statfs2_bsize],
  93. [AC_TRY_RUN([
  94. #ifdef HAVE_SYS_PARAM_H
  95. #include <sys/param.h>
  96. #endif
  97. #ifdef HAVE_SYS_MOUNT_H
  98. #include <sys/mount.h>
  99. #endif
  100. #ifdef HAVE_SYS_VFS_H
  101. #include <sys/vfs.h>
  102. #endif
  103. int
  104. main ()
  105. {
  106. struct statfs fsd;
  107. fsd.f_bsize = 0;
  108. return statfs (".", &fsd) != 0;
  109. }],
  110. fu_cv_sys_stat_statfs2_bsize=yes,
  111. fu_cv_sys_stat_statfs2_bsize=no,
  112. fu_cv_sys_stat_statfs2_bsize=no)])
  113. AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_bsize])
  114. if test $fu_cv_sys_stat_statfs2_bsize = yes; then
  115. ac_fsusage_space=yes
  116. AC_DEFINE([STAT_STATFS2_BSIZE], [1],
  117. [ Define if statfs takes 2 args and struct statfs has a field named f_bsize.
  118. (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
  119. fi
  120. fi
  121. if test $ac_fsusage_space = no; then
  122. # SVR3
  123. AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
  124. AC_CACHE_VAL([fu_cv_sys_stat_statfs4],
  125. [AC_TRY_RUN([#include <sys/types.h>
  126. #include <sys/statfs.h>
  127. int
  128. main ()
  129. {
  130. struct statfs fsd;
  131. return statfs (".", &fsd, sizeof fsd, 0) != 0;
  132. }],
  133. fu_cv_sys_stat_statfs4=yes,
  134. fu_cv_sys_stat_statfs4=no,
  135. fu_cv_sys_stat_statfs4=no)])
  136. AC_MSG_RESULT([$fu_cv_sys_stat_statfs4])
  137. if test $fu_cv_sys_stat_statfs4 = yes; then
  138. ac_fsusage_space=yes
  139. AC_DEFINE([STAT_STATFS4], [1],
  140. [ Define if statfs takes 4 args. (SVR3, Dynix, Irix, Dolphin)])
  141. fi
  142. fi
  143. if test $ac_fsusage_space = no; then
  144. # 4.4BSD and NetBSD
  145. AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
  146. member (4.4BSD and NetBSD)])
  147. AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize],
  148. [AC_TRY_RUN([#include <sys/types.h>
  149. #ifdef HAVE_SYS_PARAM_H
  150. #include <sys/param.h>
  151. #endif
  152. #ifdef HAVE_SYS_MOUNT_H
  153. #include <sys/mount.h>
  154. #endif
  155. int
  156. main ()
  157. {
  158. struct statfs fsd;
  159. fsd.f_fsize = 0;
  160. return statfs (".", &fsd) != 0;
  161. }],
  162. fu_cv_sys_stat_statfs2_fsize=yes,
  163. fu_cv_sys_stat_statfs2_fsize=no,
  164. fu_cv_sys_stat_statfs2_fsize=no)])
  165. AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_fsize])
  166. if test $fu_cv_sys_stat_statfs2_fsize = yes; then
  167. ac_fsusage_space=yes
  168. AC_DEFINE([STAT_STATFS2_FSIZE], [1],
  169. [ Define if statfs takes 2 args and struct statfs has a field named f_fsize.
  170. (4.4BSD, NetBSD)])
  171. fi
  172. fi
  173. if test $ac_fsusage_space = no; then
  174. # Ultrix
  175. AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
  176. AC_CACHE_VAL([fu_cv_sys_stat_fs_data],
  177. [AC_TRY_RUN([#include <sys/types.h>
  178. #ifdef HAVE_SYS_PARAM_H
  179. #include <sys/param.h>
  180. #endif
  181. #ifdef HAVE_SYS_MOUNT_H
  182. #include <sys/mount.h>
  183. #endif
  184. #ifdef HAVE_SYS_FS_TYPES_H
  185. #include <sys/fs_types.h>
  186. #endif
  187. int
  188. main ()
  189. {
  190. struct fs_data fsd;
  191. /* Ultrix's statfs returns 1 for success,
  192. 0 for not mounted, -1 for failure. */
  193. return statfs (".", &fsd) != 1;
  194. }],
  195. fu_cv_sys_stat_fs_data=yes,
  196. fu_cv_sys_stat_fs_data=no,
  197. fu_cv_sys_stat_fs_data=no)])
  198. AC_MSG_RESULT([$fu_cv_sys_stat_fs_data])
  199. if test $fu_cv_sys_stat_fs_data = yes; then
  200. ac_fsusage_space=yes
  201. AC_DEFINE([STAT_STATFS2_FS_DATA], [1],
  202. [ Define if statfs takes 2 args and the second argument has
  203. type struct fs_data. (Ultrix)])
  204. fi
  205. fi
  206. if test $ac_fsusage_space = no; then
  207. # SVR2
  208. AC_TRY_CPP([#include <sys/filsys.h>
  209. ],
  210. AC_DEFINE([STAT_READ_FILSYS], [1],
  211. [Define if there is no specific function for reading file systems usage
  212. information and you have the <sys/filsys.h> header file. (SVR2)])
  213. ac_fsusage_space=yes)
  214. fi
  215. AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
  216. ])
  217. # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
  218. # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
  219. # enable the work-around code in fsusage.c.
  220. AC_DEFUN([gl_STATFS_TRUNCATES],
  221. [
  222. AC_MSG_CHECKING([for statfs that truncates block counts])
  223. AC_CACHE_VAL([fu_cv_sys_truncating_statfs],
  224. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  225. #if !defined(sun) && !defined(__sun)
  226. choke -- this is a workaround for a Sun-specific problem
  227. #endif
  228. #include <sys/types.h>
  229. #include <sys/vfs.h>]],
  230. [[struct statfs t; long c = *(t.f_spare);
  231. if (c) return 0;]])],
  232. [fu_cv_sys_truncating_statfs=yes],
  233. [fu_cv_sys_truncating_statfs=no])])
  234. if test $fu_cv_sys_truncating_statfs = yes; then
  235. AC_DEFINE([STATFS_TRUNCATES_BLOCK_COUNTS], [1],
  236. [Define if the block counts reported by statfs may be truncated to 2GB
  237. and the correct values may be stored in the f_spare array.
  238. (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
  239. SunOS 4.1.1 seems not to be affected.)])
  240. fi
  241. AC_MSG_RESULT([$fu_cv_sys_truncating_statfs])
  242. ])
  243. # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
  244. AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
  245. [
  246. AC_CHECK_HEADERS([dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h])
  247. gl_STATFS_TRUNCATES
  248. ])