fsusage.m4 7.8 KB

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