fsusage.m4 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. # serial 26
  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. # glibc/{Hurd,kFreeBSD}, MacOS X >= 10.4, FreeBSD >= 5.0, NetBSD >= 3.0,
  41. # OpenBSD >= 4.4, AIX, HP-UX, IRIX, Solaris, Cygwin, Interix, BeOS.
  42. AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs],
  43. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
  44. #if defined __GLIBC__ && defined __linux__
  45. Do not use statvfs on systems with GNU libc on Linux, because that function
  46. stats 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 Hurd, BeOS, Haiku operates differently: it only makes
  49. a system 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_RUN_IFELSE([AC_LANG_SOURCE([[
  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. # glibc/Linux, MacOS X < 10.4, FreeBSD < 5.0, NetBSD < 3.0, OpenBSD < 4.4.
  91. # (glibc/{Hurd,kFreeBSD}, MacOS X >= 10.4, FreeBSD >= 5.0, NetBSD >= 3.0,
  92. # OpenBSD >= 4.4, AIX, HP-UX, OSF/1, Cygwin already handled above.)
  93. # (On IRIX you need to include <sys/statfs.h>, not only <sys/mount.h> and
  94. # <sys/vfs.h>.)
  95. # (On Solaris, statfs has 4 arguments.)
  96. AC_MSG_CHECKING([for two-argument statfs with statfs.f_bsize dnl
  97. member (AIX, 4.3BSD)])
  98. AC_CACHE_VAL([fu_cv_sys_stat_statfs2_bsize],
  99. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  100. #ifdef HAVE_SYS_PARAM_H
  101. #include <sys/param.h>
  102. #endif
  103. #ifdef HAVE_SYS_MOUNT_H
  104. #include <sys/mount.h>
  105. #endif
  106. #ifdef HAVE_SYS_VFS_H
  107. #include <sys/vfs.h>
  108. #endif
  109. int
  110. main ()
  111. {
  112. struct statfs fsd;
  113. fsd.f_bsize = 0;
  114. return statfs (".", &fsd) != 0;
  115. }]])],
  116. [fu_cv_sys_stat_statfs2_bsize=yes],
  117. [fu_cv_sys_stat_statfs2_bsize=no],
  118. [fu_cv_sys_stat_statfs2_bsize=no])])
  119. AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_bsize])
  120. if test $fu_cv_sys_stat_statfs2_bsize = yes; then
  121. ac_fsusage_space=yes
  122. AC_DEFINE([STAT_STATFS2_BSIZE], [1],
  123. [ Define if statfs takes 2 args and struct statfs has a field named f_bsize.
  124. (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
  125. fi
  126. fi
  127. if test $ac_fsusage_space = no; then
  128. # SVR3
  129. # (Solaris already handled above.)
  130. AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
  131. AC_CACHE_VAL([fu_cv_sys_stat_statfs4],
  132. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  133. #include <sys/types.h>
  134. #include <sys/statfs.h>
  135. int
  136. main ()
  137. {
  138. struct statfs fsd;
  139. return statfs (".", &fsd, sizeof fsd, 0) != 0;
  140. }]])],
  141. [fu_cv_sys_stat_statfs4=yes],
  142. [fu_cv_sys_stat_statfs4=no],
  143. [fu_cv_sys_stat_statfs4=no])])
  144. AC_MSG_RESULT([$fu_cv_sys_stat_statfs4])
  145. if test $fu_cv_sys_stat_statfs4 = yes; then
  146. ac_fsusage_space=yes
  147. AC_DEFINE([STAT_STATFS4], [1],
  148. [ Define if statfs takes 4 args. (SVR3, Dynix, old Irix, old AIX, Dolphin)])
  149. fi
  150. fi
  151. if test $ac_fsusage_space = no; then
  152. # 4.4BSD and older NetBSD
  153. # (OSF/1 already handled above.)
  154. # (On AIX, you need to include <sys/statfs.h>, not only <sys/mount.h>.)
  155. # (On Solaris, statfs has 4 arguments and 'struct statfs' is not declared in
  156. # <sys/mount.h>.)
  157. AC_MSG_CHECKING([for two-argument statfs with statfs.f_fsize dnl
  158. member (4.4BSD and NetBSD)])
  159. AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize],
  160. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  161. #include <sys/types.h>
  162. #ifdef HAVE_SYS_PARAM_H
  163. #include <sys/param.h>
  164. #endif
  165. #ifdef HAVE_SYS_MOUNT_H
  166. #include <sys/mount.h>
  167. #endif
  168. int
  169. main ()
  170. {
  171. struct statfs fsd;
  172. fsd.f_fsize = 0;
  173. return statfs (".", &fsd) != 0;
  174. }]])],
  175. [fu_cv_sys_stat_statfs2_fsize=yes],
  176. [fu_cv_sys_stat_statfs2_fsize=no],
  177. [fu_cv_sys_stat_statfs2_fsize=no])])
  178. AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_fsize])
  179. if test $fu_cv_sys_stat_statfs2_fsize = yes; then
  180. ac_fsusage_space=yes
  181. AC_DEFINE([STAT_STATFS2_FSIZE], [1],
  182. [ Define if statfs takes 2 args and struct statfs has a field named f_fsize.
  183. (4.4BSD, NetBSD)])
  184. fi
  185. fi
  186. if test $ac_fsusage_space = no; then
  187. # Ultrix
  188. AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
  189. AC_CACHE_VAL([fu_cv_sys_stat_fs_data],
  190. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  191. #include <sys/types.h>
  192. #ifdef HAVE_SYS_PARAM_H
  193. #include <sys/param.h>
  194. #endif
  195. #ifdef HAVE_SYS_MOUNT_H
  196. #include <sys/mount.h>
  197. #endif
  198. #ifdef HAVE_SYS_FS_TYPES_H
  199. #include <sys/fs_types.h>
  200. #endif
  201. int
  202. main ()
  203. {
  204. struct fs_data fsd;
  205. /* Ultrix's statfs returns 1 for success,
  206. 0 for not mounted, -1 for failure. */
  207. return statfs (".", &fsd) != 1;
  208. }]])],
  209. [fu_cv_sys_stat_fs_data=yes],
  210. [fu_cv_sys_stat_fs_data=no],
  211. [fu_cv_sys_stat_fs_data=no])])
  212. AC_MSG_RESULT([$fu_cv_sys_stat_fs_data])
  213. if test $fu_cv_sys_stat_fs_data = yes; then
  214. ac_fsusage_space=yes
  215. AC_DEFINE([STAT_STATFS2_FS_DATA], [1],
  216. [ Define if statfs takes 2 args and the second argument has
  217. type struct fs_data. (Ultrix)])
  218. fi
  219. fi
  220. if test $ac_fsusage_space = no; then
  221. # SVR2
  222. # (AIX, HP-UX, OSF/1 already handled above.)
  223. AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <sys/filsys.h>
  224. ]])],
  225. [AC_DEFINE([STAT_READ_FILSYS], [1],
  226. [Define if there is no specific function for reading file systems usage
  227. information and you have the <sys/filsys.h> header file. (SVR2)])
  228. ac_fsusage_space=yes])
  229. fi
  230. AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
  231. ])
  232. # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
  233. # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
  234. # enable the work-around code in fsusage.c.
  235. AC_DEFUN([gl_STATFS_TRUNCATES],
  236. [
  237. AC_MSG_CHECKING([for statfs that truncates block counts])
  238. AC_CACHE_VAL([fu_cv_sys_truncating_statfs],
  239. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  240. #if !defined(sun) && !defined(__sun)
  241. choke -- this is a workaround for a Sun-specific problem
  242. #endif
  243. #include <sys/types.h>
  244. #include <sys/vfs.h>]],
  245. [[struct statfs t; long c = *(t.f_spare);
  246. if (c) return 0;]])],
  247. [fu_cv_sys_truncating_statfs=yes],
  248. [fu_cv_sys_truncating_statfs=no])])
  249. if test $fu_cv_sys_truncating_statfs = yes; then
  250. AC_DEFINE([STATFS_TRUNCATES_BLOCK_COUNTS], [1],
  251. [Define if the block counts reported by statfs may be truncated to 2GB
  252. and the correct values may be stored in the f_spare array.
  253. (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
  254. SunOS 4.1.1 seems not to be affected.)])
  255. fi
  256. AC_MSG_RESULT([$fu_cv_sys_truncating_statfs])
  257. ])
  258. # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
  259. AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
  260. [
  261. AC_CHECK_HEADERS([dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h])
  262. gl_STATFS_TRUNCATES
  263. ])