fsusage.m4 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. # serial 29
  2. # Obtaining file system usage information.
  3. # Copyright (C) 1997-1998, 2000-2001, 2003-2011 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. ])
  20. # Try to determine how a program can obtain file system usage information.
  21. # If successful, define the appropriate symbol (see fsusage.c) and
  22. # execute ACTION-IF-FOUND. Otherwise, execute ACTION-IF-NOT-FOUND.
  23. #
  24. # gl_FILE_SYSTEM_USAGE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
  25. AC_DEFUN([gl_FILE_SYSTEM_USAGE],
  26. [
  27. dnl Enable large-file support. This has the effect of changing the size
  28. dnl of field f_blocks in 'struct statvfs' from 32 bit to 64 bit on
  29. dnl glibc/Hurd, HP-UX 11, Solaris (32-bit mode). It also changes the size
  30. dnl of field f_blocks in 'struct statfs' from 32 bit to 64 bit on
  31. dnl MacOS X >= 10.5 (32-bit mode).
  32. AC_REQUIRE([AC_SYS_LARGEFILE])
  33. AC_MSG_NOTICE([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. # glibc/{Hurd,kFreeBSD}, FreeBSD >= 5.0, NetBSD >= 3.0,
  43. # OpenBSD >= 4.4, AIX, HP-UX, IRIX, Solaris, Cygwin, Interix, BeOS.
  44. AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs],
  45. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
  46. #if (defined __GLIBC__ || defined __UCLIBC__) && defined __linux__
  47. Do not use statvfs on systems with GNU libc on Linux, because that function
  48. stats all preceding entries in /proc/mounts, and that makes df hang if even
  49. one of the corresponding file systems is hard-mounted, but not available.
  50. statvfs in GNU libc on Hurd, BeOS, Haiku operates differently: it only makes
  51. a system call.
  52. #endif
  53. #ifdef __osf__
  54. "Do not use Tru64's statvfs implementation"
  55. #endif
  56. #include <sys/statvfs.h>
  57. struct statvfs fsd;
  58. #if defined __APPLE__ && defined __MACH__
  59. #include <limits.h>
  60. /* On MacOS X >= 10.5, f_blocks in 'struct statvfs' is a 32-bit quantity;
  61. that commonly limits file systems to 4 TiB. Whereas f_blocks in
  62. 'struct statfs' is a 64-bit type, thanks to the large-file support
  63. that was enabled above. In this case, don't use statvfs(); use statfs()
  64. instead. */
  65. int check_f_blocks_size[sizeof fsd.f_blocks * CHAR_BIT <= 32 ? -1 : 1];
  66. #endif
  67. ]],
  68. [[statvfs (0, &fsd);]])],
  69. [fu_cv_sys_stat_statvfs=yes],
  70. [fu_cv_sys_stat_statvfs=no])])
  71. if test $fu_cv_sys_stat_statvfs = yes; then
  72. ac_fsusage_space=yes
  73. # AIX >= 5.2 has statvfs64 that has a wider f_blocks field than statvfs.
  74. # glibc, HP-UX, IRIX, Solaris have statvfs64 as well, but on these systems
  75. # statvfs with large-file support is already equivalent to statvfs64.
  76. AC_CACHE_CHECK([whether to use statvfs64],
  77. [fu_cv_sys_stat_statvfs64],
  78. [AC_LINK_IFELSE(
  79. [AC_LANG_PROGRAM(
  80. [[#include <sys/types.h>
  81. #include <sys/statvfs.h>
  82. struct statvfs64 fsd;
  83. int check_f_blocks_larger_in_statvfs64
  84. [sizeof (((struct statvfs64 *) 0)->f_blocks)
  85. > sizeof (((struct statvfs *) 0)->f_blocks)
  86. ? 1 : -1];
  87. ]],
  88. [[statvfs64 (0, &fsd);]])],
  89. [fu_cv_sys_stat_statvfs64=yes],
  90. [fu_cv_sys_stat_statvfs64=no])
  91. ])
  92. if test $fu_cv_sys_stat_statvfs64 = yes; then
  93. AC_DEFINE([STAT_STATVFS64], [1],
  94. [ Define if statvfs64 should be preferred over statvfs.])
  95. else
  96. AC_DEFINE([STAT_STATVFS], [1],
  97. [ Define if there is a function named statvfs. (SVR4)])
  98. fi
  99. fi
  100. fi
  101. if test $ac_fsusage_space = no; then
  102. # DEC Alpha running OSF/1
  103. AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
  104. AC_CACHE_VAL([fu_cv_sys_stat_statfs3_osf1],
  105. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  106. #include <sys/param.h>
  107. #include <sys/types.h>
  108. #include <sys/mount.h>
  109. int
  110. main ()
  111. {
  112. struct statfs fsd;
  113. fsd.f_fsize = 0;
  114. return statfs (".", &fsd, sizeof (struct statfs)) != 0;
  115. }]])],
  116. [fu_cv_sys_stat_statfs3_osf1=yes],
  117. [fu_cv_sys_stat_statfs3_osf1=no],
  118. [fu_cv_sys_stat_statfs3_osf1=no])])
  119. AC_MSG_RESULT([$fu_cv_sys_stat_statfs3_osf1])
  120. if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
  121. ac_fsusage_space=yes
  122. AC_DEFINE([STAT_STATFS3_OSF1], [1],
  123. [ Define if statfs takes 3 args. (DEC Alpha running OSF/1)])
  124. fi
  125. fi
  126. if test $ac_fsusage_space = no; then
  127. # glibc/Linux, MacOS X, FreeBSD < 5.0, NetBSD < 3.0, OpenBSD < 4.4.
  128. # (glibc/{Hurd,kFreeBSD}, FreeBSD >= 5.0, NetBSD >= 3.0,
  129. # OpenBSD >= 4.4, AIX, HP-UX, OSF/1, Cygwin already handled above.)
  130. # (On IRIX you need to include <sys/statfs.h>, not only <sys/mount.h> and
  131. # <sys/vfs.h>.)
  132. # (On Solaris, statfs has 4 arguments.)
  133. AC_MSG_CHECKING([for two-argument statfs with statfs.f_bsize dnl
  134. member (AIX, 4.3BSD)])
  135. AC_CACHE_VAL([fu_cv_sys_stat_statfs2_bsize],
  136. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  137. #ifdef HAVE_SYS_PARAM_H
  138. #include <sys/param.h>
  139. #endif
  140. #ifdef HAVE_SYS_MOUNT_H
  141. #include <sys/mount.h>
  142. #endif
  143. #ifdef HAVE_SYS_VFS_H
  144. #include <sys/vfs.h>
  145. #endif
  146. int
  147. main ()
  148. {
  149. struct statfs fsd;
  150. fsd.f_bsize = 0;
  151. return statfs (".", &fsd) != 0;
  152. }]])],
  153. [fu_cv_sys_stat_statfs2_bsize=yes],
  154. [fu_cv_sys_stat_statfs2_bsize=no],
  155. [fu_cv_sys_stat_statfs2_bsize=no])])
  156. AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_bsize])
  157. if test $fu_cv_sys_stat_statfs2_bsize = yes; then
  158. ac_fsusage_space=yes
  159. AC_DEFINE([STAT_STATFS2_BSIZE], [1],
  160. [ Define if statfs takes 2 args and struct statfs has a field named f_bsize.
  161. (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
  162. fi
  163. fi
  164. if test $ac_fsusage_space = no; then
  165. # SVR3
  166. # (Solaris already handled above.)
  167. AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
  168. AC_CACHE_VAL([fu_cv_sys_stat_statfs4],
  169. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  170. #include <sys/types.h>
  171. #include <sys/statfs.h>
  172. int
  173. main ()
  174. {
  175. struct statfs fsd;
  176. return statfs (".", &fsd, sizeof fsd, 0) != 0;
  177. }]])],
  178. [fu_cv_sys_stat_statfs4=yes],
  179. [fu_cv_sys_stat_statfs4=no],
  180. [fu_cv_sys_stat_statfs4=no])])
  181. AC_MSG_RESULT([$fu_cv_sys_stat_statfs4])
  182. if test $fu_cv_sys_stat_statfs4 = yes; then
  183. ac_fsusage_space=yes
  184. AC_DEFINE([STAT_STATFS4], [1],
  185. [ Define if statfs takes 4 args. (SVR3, Dynix, old Irix, old AIX, Dolphin)])
  186. fi
  187. fi
  188. if test $ac_fsusage_space = no; then
  189. # 4.4BSD and older NetBSD
  190. # (OSF/1 already handled above.)
  191. # (On AIX, you need to include <sys/statfs.h>, not only <sys/mount.h>.)
  192. # (On Solaris, statfs has 4 arguments and 'struct statfs' is not declared in
  193. # <sys/mount.h>.)
  194. AC_MSG_CHECKING([for two-argument statfs with statfs.f_fsize dnl
  195. member (4.4BSD and NetBSD)])
  196. AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize],
  197. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  198. #include <sys/types.h>
  199. #ifdef HAVE_SYS_PARAM_H
  200. #include <sys/param.h>
  201. #endif
  202. #ifdef HAVE_SYS_MOUNT_H
  203. #include <sys/mount.h>
  204. #endif
  205. int
  206. main ()
  207. {
  208. struct statfs fsd;
  209. fsd.f_fsize = 0;
  210. return statfs (".", &fsd) != 0;
  211. }]])],
  212. [fu_cv_sys_stat_statfs2_fsize=yes],
  213. [fu_cv_sys_stat_statfs2_fsize=no],
  214. [fu_cv_sys_stat_statfs2_fsize=no])])
  215. AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_fsize])
  216. if test $fu_cv_sys_stat_statfs2_fsize = yes; then
  217. ac_fsusage_space=yes
  218. AC_DEFINE([STAT_STATFS2_FSIZE], [1],
  219. [ Define if statfs takes 2 args and struct statfs has a field named f_fsize.
  220. (4.4BSD, NetBSD)])
  221. fi
  222. fi
  223. if test $ac_fsusage_space = no; then
  224. # Ultrix
  225. AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
  226. AC_CACHE_VAL([fu_cv_sys_stat_fs_data],
  227. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  228. #include <sys/types.h>
  229. #ifdef HAVE_SYS_PARAM_H
  230. #include <sys/param.h>
  231. #endif
  232. #ifdef HAVE_SYS_MOUNT_H
  233. #include <sys/mount.h>
  234. #endif
  235. #ifdef HAVE_SYS_FS_TYPES_H
  236. #include <sys/fs_types.h>
  237. #endif
  238. int
  239. main ()
  240. {
  241. struct fs_data fsd;
  242. /* Ultrix's statfs returns 1 for success,
  243. 0 for not mounted, -1 for failure. */
  244. return statfs (".", &fsd) != 1;
  245. }]])],
  246. [fu_cv_sys_stat_fs_data=yes],
  247. [fu_cv_sys_stat_fs_data=no],
  248. [fu_cv_sys_stat_fs_data=no])])
  249. AC_MSG_RESULT([$fu_cv_sys_stat_fs_data])
  250. if test $fu_cv_sys_stat_fs_data = yes; then
  251. ac_fsusage_space=yes
  252. AC_DEFINE([STAT_STATFS2_FS_DATA], [1],
  253. [ Define if statfs takes 2 args and the second argument has
  254. type struct fs_data. (Ultrix)])
  255. fi
  256. fi
  257. if test $ac_fsusage_space = no; then
  258. # SVR2
  259. # (AIX, HP-UX, OSF/1 already handled above.)
  260. AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <sys/filsys.h>
  261. ]])],
  262. [AC_DEFINE([STAT_READ_FILSYS], [1],
  263. [Define if there is no specific function for reading file systems usage
  264. information and you have the <sys/filsys.h> header file. (SVR2)])
  265. ac_fsusage_space=yes])
  266. fi
  267. AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
  268. ])
  269. # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
  270. # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
  271. # enable the work-around code in fsusage.c.
  272. AC_DEFUN([gl_STATFS_TRUNCATES],
  273. [
  274. AC_MSG_CHECKING([for statfs that truncates block counts])
  275. AC_CACHE_VAL([fu_cv_sys_truncating_statfs],
  276. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  277. #if !defined(sun) && !defined(__sun)
  278. choke -- this is a workaround for a Sun-specific problem
  279. #endif
  280. #include <sys/types.h>
  281. #include <sys/vfs.h>]],
  282. [[struct statfs t; long c = *(t.f_spare);
  283. if (c) return 0;]])],
  284. [fu_cv_sys_truncating_statfs=yes],
  285. [fu_cv_sys_truncating_statfs=no])])
  286. if test $fu_cv_sys_truncating_statfs = yes; then
  287. AC_DEFINE([STATFS_TRUNCATES_BLOCK_COUNTS], [1],
  288. [Define if the block counts reported by statfs may be truncated to 2GB
  289. and the correct values may be stored in the f_spare array.
  290. (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
  291. SunOS 4.1.1 seems not to be affected.)])
  292. fi
  293. AC_MSG_RESULT([$fu_cv_sys_truncating_statfs])
  294. ])
  295. # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
  296. AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
  297. [
  298. AC_CHECK_HEADERS([dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h])
  299. gl_STATFS_TRUNCATES
  300. ])