fsusage.m4 7.7 KB

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