fsusage.m4 11 KB

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