fsusage.m4 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. # serial 25
  2. # Obtaining file system usage information.
  3. # Copyright (C) 1997-1998, 2000-2001, 2003-2010 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_LINK_IFELSE([AC_LANG_PROGRAM([[#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_RUN_IFELSE([AC_LANG_SOURCE([[
  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_RUN_IFELSE([AC_LANG_SOURCE([[
  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_RUN_IFELSE([AC_LANG_SOURCE([[
  126. #include <sys/types.h>
  127. #include <sys/statfs.h>
  128. int
  129. main ()
  130. {
  131. struct statfs fsd;
  132. return statfs (".", &fsd, sizeof fsd, 0) != 0;
  133. }]])],
  134. [fu_cv_sys_stat_statfs4=yes],
  135. [fu_cv_sys_stat_statfs4=no],
  136. [fu_cv_sys_stat_statfs4=no])])
  137. AC_MSG_RESULT([$fu_cv_sys_stat_statfs4])
  138. if test $fu_cv_sys_stat_statfs4 = yes; then
  139. ac_fsusage_space=yes
  140. AC_DEFINE([STAT_STATFS4], [1],
  141. [ Define if statfs takes 4 args. (SVR3, Dynix, Irix, Dolphin)])
  142. fi
  143. fi
  144. if test $ac_fsusage_space = no; then
  145. # 4.4BSD and NetBSD
  146. AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
  147. member (4.4BSD and NetBSD)])
  148. AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize],
  149. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  150. #include <sys/types.h>
  151. #ifdef HAVE_SYS_PARAM_H
  152. #include <sys/param.h>
  153. #endif
  154. #ifdef HAVE_SYS_MOUNT_H
  155. #include <sys/mount.h>
  156. #endif
  157. int
  158. main ()
  159. {
  160. struct statfs fsd;
  161. fsd.f_fsize = 0;
  162. return statfs (".", &fsd) != 0;
  163. }]])],
  164. [fu_cv_sys_stat_statfs2_fsize=yes],
  165. [fu_cv_sys_stat_statfs2_fsize=no],
  166. [fu_cv_sys_stat_statfs2_fsize=no])])
  167. AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_fsize])
  168. if test $fu_cv_sys_stat_statfs2_fsize = yes; then
  169. ac_fsusage_space=yes
  170. AC_DEFINE([STAT_STATFS2_FSIZE], [1],
  171. [ Define if statfs takes 2 args and struct statfs has a field named f_fsize.
  172. (4.4BSD, NetBSD)])
  173. fi
  174. fi
  175. if test $ac_fsusage_space = no; then
  176. # Ultrix
  177. AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
  178. AC_CACHE_VAL([fu_cv_sys_stat_fs_data],
  179. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  180. #include <sys/types.h>
  181. #ifdef HAVE_SYS_PARAM_H
  182. #include <sys/param.h>
  183. #endif
  184. #ifdef HAVE_SYS_MOUNT_H
  185. #include <sys/mount.h>
  186. #endif
  187. #ifdef HAVE_SYS_FS_TYPES_H
  188. #include <sys/fs_types.h>
  189. #endif
  190. int
  191. main ()
  192. {
  193. struct fs_data fsd;
  194. /* Ultrix's statfs returns 1 for success,
  195. 0 for not mounted, -1 for failure. */
  196. return statfs (".", &fsd) != 1;
  197. }]])],
  198. [fu_cv_sys_stat_fs_data=yes],
  199. [fu_cv_sys_stat_fs_data=no],
  200. [fu_cv_sys_stat_fs_data=no])])
  201. AC_MSG_RESULT([$fu_cv_sys_stat_fs_data])
  202. if test $fu_cv_sys_stat_fs_data = yes; then
  203. ac_fsusage_space=yes
  204. AC_DEFINE([STAT_STATFS2_FS_DATA], [1],
  205. [ Define if statfs takes 2 args and the second argument has
  206. type struct fs_data. (Ultrix)])
  207. fi
  208. fi
  209. if test $ac_fsusage_space = no; then
  210. # SVR2
  211. AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <sys/filsys.h>
  212. ]])],
  213. [AC_DEFINE([STAT_READ_FILSYS], [1],
  214. [Define if there is no specific function for reading file systems usage
  215. information and you have the <sys/filsys.h> header file. (SVR2)])
  216. ac_fsusage_space=yes])
  217. fi
  218. AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
  219. ])
  220. # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
  221. # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
  222. # enable the work-around code in fsusage.c.
  223. AC_DEFUN([gl_STATFS_TRUNCATES],
  224. [
  225. AC_MSG_CHECKING([for statfs that truncates block counts])
  226. AC_CACHE_VAL([fu_cv_sys_truncating_statfs],
  227. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  228. #if !defined(sun) && !defined(__sun)
  229. choke -- this is a workaround for a Sun-specific problem
  230. #endif
  231. #include <sys/types.h>
  232. #include <sys/vfs.h>]],
  233. [[struct statfs t; long c = *(t.f_spare);
  234. if (c) return 0;]])],
  235. [fu_cv_sys_truncating_statfs=yes],
  236. [fu_cv_sys_truncating_statfs=no])])
  237. if test $fu_cv_sys_truncating_statfs = yes; then
  238. AC_DEFINE([STATFS_TRUNCATES_BLOCK_COUNTS], [1],
  239. [Define if the block counts reported by statfs may be truncated to 2GB
  240. and the correct values may be stored in the f_spare array.
  241. (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
  242. SunOS 4.1.1 seems not to be affected.)])
  243. fi
  244. AC_MSG_RESULT([$fu_cv_sys_truncating_statfs])
  245. ])
  246. # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
  247. AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
  248. [
  249. AC_CHECK_HEADERS([dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h])
  250. gl_STATFS_TRUNCATES
  251. ])