fsusage.m4 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. #serial 23
  2. # Obtaining file system usage information.
  3. # Copyright (C) 1997, 1998, 2000, 2001, 2003-2007 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_LIBSOURCES([fsusage.c, fsusage.h])
  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. #ifdef __osf__
  52. "Do not use Tru64's statvfs implementation"
  53. #endif
  54. #include <sys/statvfs.h>],
  55. [struct statvfs fsd; statvfs (0, &fsd);],
  56. fu_cv_sys_stat_statvfs=yes,
  57. fu_cv_sys_stat_statvfs=no)])
  58. if test $fu_cv_sys_stat_statvfs = yes; then
  59. ac_fsusage_space=yes
  60. AC_DEFINE(STAT_STATVFS, 1,
  61. [ Define if there is a function named statvfs. (SVR4)])
  62. fi
  63. fi
  64. if test $ac_fsusage_space = no; then
  65. # DEC Alpha running OSF/1
  66. AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
  67. AC_CACHE_VAL(fu_cv_sys_stat_statfs3_osf1,
  68. [AC_TRY_RUN([
  69. #include <sys/param.h>
  70. #include <sys/types.h>
  71. #include <sys/mount.h>
  72. int
  73. main ()
  74. {
  75. struct statfs fsd;
  76. fsd.f_fsize = 0;
  77. return statfs (".", &fsd, sizeof (struct statfs)) != 0;
  78. }],
  79. fu_cv_sys_stat_statfs3_osf1=yes,
  80. fu_cv_sys_stat_statfs3_osf1=no,
  81. fu_cv_sys_stat_statfs3_osf1=no)])
  82. AC_MSG_RESULT($fu_cv_sys_stat_statfs3_osf1)
  83. if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
  84. ac_fsusage_space=yes
  85. AC_DEFINE(STAT_STATFS3_OSF1, 1,
  86. [ Define if statfs takes 3 args. (DEC Alpha running OSF/1)])
  87. fi
  88. fi
  89. if test $ac_fsusage_space = no; then
  90. # AIX
  91. AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
  92. member (AIX, 4.3BSD)])
  93. AC_CACHE_VAL(fu_cv_sys_stat_statfs2_bsize,
  94. [AC_TRY_RUN([
  95. #ifdef HAVE_SYS_PARAM_H
  96. #include <sys/param.h>
  97. #endif
  98. #ifdef HAVE_SYS_MOUNT_H
  99. #include <sys/mount.h>
  100. #endif
  101. #ifdef HAVE_SYS_VFS_H
  102. #include <sys/vfs.h>
  103. #endif
  104. int
  105. main ()
  106. {
  107. struct statfs fsd;
  108. fsd.f_bsize = 0;
  109. return statfs (".", &fsd) != 0;
  110. }],
  111. fu_cv_sys_stat_statfs2_bsize=yes,
  112. fu_cv_sys_stat_statfs2_bsize=no,
  113. fu_cv_sys_stat_statfs2_bsize=no)])
  114. AC_MSG_RESULT($fu_cv_sys_stat_statfs2_bsize)
  115. if test $fu_cv_sys_stat_statfs2_bsize = yes; then
  116. ac_fsusage_space=yes
  117. AC_DEFINE(STAT_STATFS2_BSIZE, 1,
  118. [ Define if statfs takes 2 args and struct statfs has a field named f_bsize.
  119. (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
  120. fi
  121. fi
  122. if test $ac_fsusage_space = no; then
  123. # SVR3
  124. AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
  125. AC_CACHE_VAL(fu_cv_sys_stat_statfs4,
  126. [AC_TRY_RUN([#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_TRY_RUN([#include <sys/types.h>
  150. #ifdef HAVE_SYS_PARAM_H
  151. #include <sys/param.h>
  152. #endif
  153. #ifdef HAVE_SYS_MOUNT_H
  154. #include <sys/mount.h>
  155. #endif
  156. int
  157. main ()
  158. {
  159. struct statfs fsd;
  160. fsd.f_fsize = 0;
  161. return statfs (".", &fsd) != 0;
  162. }],
  163. fu_cv_sys_stat_statfs2_fsize=yes,
  164. fu_cv_sys_stat_statfs2_fsize=no,
  165. fu_cv_sys_stat_statfs2_fsize=no)])
  166. AC_MSG_RESULT($fu_cv_sys_stat_statfs2_fsize)
  167. if test $fu_cv_sys_stat_statfs2_fsize = yes; then
  168. ac_fsusage_space=yes
  169. AC_DEFINE(STAT_STATFS2_FSIZE, 1,
  170. [ Define if statfs takes 2 args and struct statfs has a field named f_fsize.
  171. (4.4BSD, NetBSD)])
  172. fi
  173. fi
  174. if test $ac_fsusage_space = no; then
  175. # Ultrix
  176. AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
  177. AC_CACHE_VAL(fu_cv_sys_stat_fs_data,
  178. [AC_TRY_RUN([#include <sys/types.h>
  179. #ifdef HAVE_SYS_PARAM_H
  180. #include <sys/param.h>
  181. #endif
  182. #ifdef HAVE_SYS_MOUNT_H
  183. #include <sys/mount.h>
  184. #endif
  185. #ifdef HAVE_SYS_FS_TYPES_H
  186. #include <sys/fs_types.h>
  187. #endif
  188. int
  189. main ()
  190. {
  191. struct fs_data fsd;
  192. /* Ultrix's statfs returns 1 for success,
  193. 0 for not mounted, -1 for failure. */
  194. return statfs (".", &fsd) != 1;
  195. }],
  196. fu_cv_sys_stat_fs_data=yes,
  197. fu_cv_sys_stat_fs_data=no,
  198. fu_cv_sys_stat_fs_data=no)])
  199. AC_MSG_RESULT($fu_cv_sys_stat_fs_data)
  200. if test $fu_cv_sys_stat_fs_data = yes; then
  201. ac_fsusage_space=yes
  202. AC_DEFINE(STAT_STATFS2_FS_DATA, 1,
  203. [ Define if statfs takes 2 args and the second argument has
  204. type struct fs_data. (Ultrix)])
  205. fi
  206. fi
  207. if test $ac_fsusage_space = no; then
  208. # SVR2
  209. AC_TRY_CPP([#include <sys/filsys.h>
  210. ],
  211. AC_DEFINE(STAT_READ_FILSYS, 1,
  212. [Define if there is no specific function for reading file systems usage
  213. information and you have the <sys/filsys.h> header file. (SVR2)])
  214. ac_fsusage_space=yes)
  215. fi
  216. AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
  217. ])
  218. # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
  219. # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
  220. # enable the work-around code in fsusage.c.
  221. AC_DEFUN([gl_STATFS_TRUNCATES],
  222. [
  223. AC_MSG_CHECKING([for statfs that truncates block counts])
  224. AC_CACHE_VAL(fu_cv_sys_truncating_statfs,
  225. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  226. #if !defined(sun) && !defined(__sun)
  227. choke -- this is a workaround for a Sun-specific problem
  228. #endif
  229. #include <sys/types.h>
  230. #include <sys/vfs.h>]],
  231. [[struct statfs t; long c = *(t.f_spare);
  232. if (c) return 0;]])],
  233. [fu_cv_sys_truncating_statfs=yes],
  234. [fu_cv_sys_truncating_statfs=no])])
  235. if test $fu_cv_sys_truncating_statfs = yes; then
  236. AC_DEFINE(STATFS_TRUNCATES_BLOCK_COUNTS, 1,
  237. [Define if the block counts reported by statfs may be truncated to 2GB
  238. and the correct values may be stored in the f_spare array.
  239. (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
  240. SunOS 4.1.1 seems not to be affected.)])
  241. fi
  242. AC_MSG_RESULT($fu_cv_sys_truncating_statfs)
  243. ])
  244. # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
  245. AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
  246. [
  247. AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
  248. AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h)
  249. gl_STATFS_TRUNCATES
  250. ])