fsusage.m4 9.8 KB

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