fsusage.m4 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. # serial 34
  2. # Obtaining file system usage information.
  3. # Copyright (C) 1997-1998, 2000-2001, 2003-2017 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 Mac OS X >= 10.5 (32-bit mode).
  32. AC_REQUIRE([AC_SYS_LARGEFILE])
  33. AC_MSG_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)],
  45. [fu_cv_sys_stat_statvfs],
  46. [AC_LINK_IFELSE(
  47. [AC_LANG_PROGRAM([[
  48. #include <sys/types.h>
  49. #ifdef __osf__
  50. "Do not use Tru64's statvfs implementation"
  51. #endif
  52. #include <sys/statvfs.h>
  53. struct statvfs fsd;
  54. #if defined __APPLE__ && defined __MACH__
  55. #include <limits.h>
  56. /* On Mac OS X >= 10.5, f_blocks in 'struct statvfs' is a 32-bit quantity;
  57. that commonly limits file systems to 4 TiB. Whereas f_blocks in
  58. 'struct statfs' is a 64-bit type, thanks to the large-file support
  59. that was enabled above. In this case, don't use statvfs(); use statfs()
  60. instead. */
  61. int check_f_blocks_size[sizeof fsd.f_blocks * CHAR_BIT <= 32 ? -1 : 1];
  62. #endif
  63. ]],
  64. [[statvfs (0, &fsd);]])],
  65. [fu_cv_sys_stat_statvfs=yes],
  66. [fu_cv_sys_stat_statvfs=no])
  67. ])
  68. if test $fu_cv_sys_stat_statvfs = yes; then
  69. ac_fsusage_space=yes
  70. # AIX >= 5.2 has statvfs64 that has a wider f_blocks field than statvfs.
  71. # glibc, HP-UX, IRIX, Solaris have statvfs64 as well, but on these systems
  72. # statvfs with large-file support is already equivalent to statvfs64.
  73. AC_CACHE_CHECK([whether to use statvfs64],
  74. [fu_cv_sys_stat_statvfs64],
  75. [AC_LINK_IFELSE(
  76. [AC_LANG_PROGRAM(
  77. [[#include <sys/types.h>
  78. #include <sys/statvfs.h>
  79. struct statvfs64 fsd;
  80. int check_f_blocks_larger_in_statvfs64
  81. [sizeof (((struct statvfs64 *) 0)->f_blocks)
  82. > sizeof (((struct statvfs *) 0)->f_blocks)
  83. ? 1 : -1];
  84. ]],
  85. [[statvfs64 (0, &fsd);]])],
  86. [fu_cv_sys_stat_statvfs64=yes],
  87. [fu_cv_sys_stat_statvfs64=no])
  88. ])
  89. if test $fu_cv_sys_stat_statvfs64 = yes; then
  90. AC_DEFINE([STAT_STATVFS64], [1],
  91. [Define if statvfs64 should be preferred over statvfs.])
  92. else
  93. AC_DEFINE([STAT_STATVFS], [1],
  94. [Define if there is a function named statvfs. (SVR4)])
  95. fi
  96. fi
  97. fi
  98. # Check for this unconditionally so we have a
  99. # good fallback on glibc/Linux > 2.6 < 2.6.36
  100. AC_CACHE_CHECK([for two-argument statfs with statfs.f_frsize member],
  101. [fu_cv_sys_stat_statfs2_frsize],
  102. [AC_RUN_IFELSE(
  103. [AC_LANG_SOURCE([[
  104. #ifdef HAVE_SYS_PARAM_H
  105. #include <sys/param.h>
  106. #endif
  107. #ifdef HAVE_SYS_MOUNT_H
  108. #include <sys/mount.h>
  109. #endif
  110. #ifdef HAVE_SYS_VFS_H
  111. #include <sys/vfs.h>
  112. #endif
  113. int
  114. main ()
  115. {
  116. struct statfs fsd;
  117. fsd.f_frsize = 0;
  118. return statfs (".", &fsd) != 0;
  119. }]])],
  120. [fu_cv_sys_stat_statfs2_frsize=yes],
  121. [fu_cv_sys_stat_statfs2_frsize=no],
  122. [fu_cv_sys_stat_statfs2_frsize=no])
  123. ])
  124. if test $fu_cv_sys_stat_statfs2_frsize = yes; then
  125. ac_fsusage_space=yes
  126. AC_DEFINE([STAT_STATFS2_FRSIZE], [1],
  127. [Define if statfs takes 2 args and struct statfs has a field named f_frsize.
  128. (glibc/Linux > 2.6)])
  129. fi
  130. if test $ac_fsusage_space = no; then
  131. # DEC Alpha running OSF/1
  132. AC_CACHE_CHECK([for 3-argument statfs function (DEC OSF/1)],
  133. [fu_cv_sys_stat_statfs3_osf1],
  134. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  135. #include <sys/param.h>
  136. #include <sys/types.h>
  137. #include <sys/mount.h>
  138. int
  139. main ()
  140. {
  141. struct statfs fsd;
  142. fsd.f_fsize = 0;
  143. return statfs (".", &fsd, sizeof (struct statfs)) != 0;
  144. }]])],
  145. [fu_cv_sys_stat_statfs3_osf1=yes],
  146. [fu_cv_sys_stat_statfs3_osf1=no],
  147. [fu_cv_sys_stat_statfs3_osf1=no])
  148. ])
  149. if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
  150. ac_fsusage_space=yes
  151. AC_DEFINE([STAT_STATFS3_OSF1], [1],
  152. [Define if statfs takes 3 args. (DEC Alpha running OSF/1)])
  153. fi
  154. fi
  155. if test $ac_fsusage_space = no; then
  156. # glibc/Linux, Mac OS X, FreeBSD < 5.0, NetBSD < 3.0, OpenBSD < 4.4.
  157. # (glibc/{Hurd,kFreeBSD}, FreeBSD >= 5.0, NetBSD >= 3.0,
  158. # OpenBSD >= 4.4, AIX, HP-UX, OSF/1, Cygwin already handled above.)
  159. # (On IRIX you need to include <sys/statfs.h>, not only <sys/mount.h> and
  160. # <sys/vfs.h>.)
  161. # (On Solaris, statfs has 4 arguments.)
  162. AC_CACHE_CHECK([for two-argument statfs with statfs.f_bsize member (AIX, 4.3BSD)],
  163. [fu_cv_sys_stat_statfs2_bsize],
  164. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  165. #ifdef HAVE_SYS_PARAM_H
  166. #include <sys/param.h>
  167. #endif
  168. #ifdef HAVE_SYS_MOUNT_H
  169. #include <sys/mount.h>
  170. #endif
  171. #ifdef HAVE_SYS_VFS_H
  172. #include <sys/vfs.h>
  173. #endif
  174. int
  175. main ()
  176. {
  177. struct statfs fsd;
  178. fsd.f_bsize = 0;
  179. return statfs (".", &fsd) != 0;
  180. }]])],
  181. [fu_cv_sys_stat_statfs2_bsize=yes],
  182. [fu_cv_sys_stat_statfs2_bsize=no],
  183. [fu_cv_sys_stat_statfs2_bsize=no])
  184. ])
  185. if test $fu_cv_sys_stat_statfs2_bsize = yes; then
  186. ac_fsusage_space=yes
  187. AC_DEFINE([STAT_STATFS2_BSIZE], [1],
  188. [Define if statfs takes 2 args and struct statfs has a field named f_bsize.
  189. (4.3BSD, SunOS 4, HP-UX)])
  190. fi
  191. fi
  192. if test $ac_fsusage_space = no; then
  193. # SVR3
  194. # (Solaris already handled above.)
  195. AC_CACHE_CHECK([for four-argument statfs (SVR3)],
  196. [fu_cv_sys_stat_statfs4],
  197. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  198. #include <sys/types.h>
  199. #include <sys/statfs.h>
  200. int
  201. main ()
  202. {
  203. struct statfs fsd;
  204. return statfs (".", &fsd, sizeof fsd, 0) != 0;
  205. }]])],
  206. [fu_cv_sys_stat_statfs4=yes],
  207. [fu_cv_sys_stat_statfs4=no],
  208. [fu_cv_sys_stat_statfs4=no])
  209. ])
  210. if test $fu_cv_sys_stat_statfs4 = yes; then
  211. ac_fsusage_space=yes
  212. AC_DEFINE([STAT_STATFS4], [1],
  213. [Define if statfs takes 4 args. (SVR3, old Irix)])
  214. fi
  215. fi
  216. if test $ac_fsusage_space = no; then
  217. # 4.4BSD and older NetBSD
  218. # (OSF/1 already handled above.)
  219. # (On AIX, you need to include <sys/statfs.h>, not only <sys/mount.h>.)
  220. # (On Solaris, statfs has 4 arguments and 'struct statfs' is not declared in
  221. # <sys/mount.h>.)
  222. AC_CACHE_CHECK([for two-argument statfs with statfs.f_fsize member (4.4BSD and NetBSD)],
  223. [fu_cv_sys_stat_statfs2_fsize],
  224. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  225. #include <sys/types.h>
  226. #ifdef HAVE_SYS_PARAM_H
  227. #include <sys/param.h>
  228. #endif
  229. #ifdef HAVE_SYS_MOUNT_H
  230. #include <sys/mount.h>
  231. #endif
  232. int
  233. main ()
  234. {
  235. struct statfs fsd;
  236. fsd.f_fsize = 0;
  237. return statfs (".", &fsd) != 0;
  238. }]])],
  239. [fu_cv_sys_stat_statfs2_fsize=yes],
  240. [fu_cv_sys_stat_statfs2_fsize=no],
  241. [fu_cv_sys_stat_statfs2_fsize=no])
  242. ])
  243. if test $fu_cv_sys_stat_statfs2_fsize = yes; then
  244. ac_fsusage_space=yes
  245. AC_DEFINE([STAT_STATFS2_FSIZE], [1],
  246. [Define if statfs takes 2 args and struct statfs has a field named f_fsize.
  247. (4.4BSD, NetBSD)])
  248. fi
  249. fi
  250. AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
  251. ])
  252. # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
  253. # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
  254. # enable the work-around code in fsusage.c.
  255. AC_DEFUN([gl_STATFS_TRUNCATES],
  256. [
  257. AC_CACHE_CHECK([for statfs that truncates block counts],
  258. [fu_cv_sys_truncating_statfs],
  259. [AC_COMPILE_IFELSE(
  260. [AC_LANG_PROGRAM([[
  261. #if !defined(sun) && !defined(__sun)
  262. choke -- this is a workaround for a Sun-specific problem
  263. #endif
  264. #include <sys/types.h>
  265. #include <sys/vfs.h>
  266. ]],
  267. [[struct statfs t; long c = *(t.f_spare);
  268. if (c) return 0;
  269. ]])],
  270. [fu_cv_sys_truncating_statfs=yes],
  271. [fu_cv_sys_truncating_statfs=no])
  272. ])
  273. if test $fu_cv_sys_truncating_statfs = yes; then
  274. AC_DEFINE([STATFS_TRUNCATES_BLOCK_COUNTS], [1],
  275. [Define if the block counts reported by statfs may be truncated to 2GB
  276. and the correct values may be stored in the f_spare array.
  277. (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
  278. SunOS 4.1.1 seems not to be affected.)])
  279. fi
  280. ])
  281. # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
  282. AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
  283. [
  284. AC_CHECK_HEADERS([sys/fs/s5param.h sys/statfs.h])
  285. gl_STATFS_TRUNCATES
  286. ])