2 # Obtaining file system usage information.
4 # Copyright (C) 1997-1998, 2000-2001, 2003-2018 Free Software Foundation, Inc.
6 # This file is free software; the Free Software Foundation
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
10 # Written by Jim Meyering.
12 AC_DEFUN([gl_FSUSAGE],
14 AC_CHECK_HEADERS_ONCE([sys/param.h])
15 AC_CHECK_HEADERS_ONCE([sys/vfs.h sys/fs_types.h])
16 AC_CHECK_HEADERS([sys/mount.h], [], [],
19 #include <sys/param.h>
21 gl_FILE_SYSTEM_USAGE([gl_cv_fs_space=yes], [gl_cv_fs_space=no])
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.
28 # gl_FILE_SYSTEM_USAGE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
30 AC_DEFUN([gl_FILE_SYSTEM_USAGE],
32 dnl Enable large-file support. This has the effect of changing the size
33 dnl of field f_blocks in 'struct statvfs' from 32 bit to 64 bit on
34 dnl glibc/Hurd, HP-UX 11, Solaris (32-bit mode). It also changes the size
35 dnl of field f_blocks in 'struct statfs' from 32 bit to 64 bit on
36 dnl Mac OS X >= 10.5 (32-bit mode).
37 AC_REQUIRE([AC_SYS_LARGEFILE])
39 AC_MSG_CHECKING([how to get file system space usage])
42 # Perform only the link test since it seems there are no variants of the
43 # statvfs function. This check is more than just AC_CHECK_FUNCS([statvfs])
44 # because that got a false positive on SCO OSR5. Adding the declaration
45 # of a 'struct statvfs' causes this test to fail (as it should) on such
46 # systems. That system is reported to work fine with STAT_STATFS4 which
47 # is what it gets when this test fails.
48 if test $ac_fsusage_space = no; then
49 # glibc/{Hurd,kFreeBSD}, FreeBSD >= 5.0, NetBSD >= 3.0,
50 # OpenBSD >= 4.4, AIX, HP-UX, IRIX, Solaris, Cygwin, Interix, BeOS.
51 AC_CACHE_CHECK([for statvfs function (SVR4)],
52 [fu_cv_sys_stat_statvfs],
55 #include <sys/types.h>
57 "Do not use Tru64's statvfs implementation"
60 #include <sys/statvfs.h>
64 #if defined __APPLE__ && defined __MACH__
66 /* On Mac OS X >= 10.5, f_blocks in 'struct statvfs' is a 32-bit quantity;
67 that commonly limits file systems to 4 TiB. Whereas f_blocks in
68 'struct statfs' is a 64-bit type, thanks to the large-file support
69 that was enabled above. In this case, don't use statvfs(); use statfs()
71 int check_f_blocks_size[sizeof fsd.f_blocks * CHAR_BIT <= 32 ? -1 : 1];
74 [[statvfs (0, &fsd);]])],
75 [fu_cv_sys_stat_statvfs=yes],
76 [fu_cv_sys_stat_statvfs=no])
78 if test $fu_cv_sys_stat_statvfs = yes; then
80 # AIX >= 5.2 has statvfs64 that has a wider f_blocks field than statvfs.
81 # glibc, HP-UX, IRIX, Solaris have statvfs64 as well, but on these systems
82 # statvfs with large-file support is already equivalent to statvfs64.
83 AC_CACHE_CHECK([whether to use statvfs64],
84 [fu_cv_sys_stat_statvfs64],
87 [[#include <sys/types.h>
88 #include <sys/statvfs.h>
90 int check_f_blocks_larger_in_statvfs64
91 [sizeof (((struct statvfs64 *) 0)->f_blocks)
92 > sizeof (((struct statvfs *) 0)->f_blocks)
95 [[statvfs64 (0, &fsd);]])],
96 [fu_cv_sys_stat_statvfs64=yes],
97 [fu_cv_sys_stat_statvfs64=no])
99 if test $fu_cv_sys_stat_statvfs64 = yes; then
100 AC_DEFINE([STAT_STATVFS64], [1],
101 [Define if statvfs64 should be preferred over statvfs.])
103 AC_DEFINE([STAT_STATVFS], [1],
104 [Define if there is a function named statvfs. (SVR4)])
109 # Check for this unconditionally so we have a
110 # good fallback on glibc/Linux > 2.6 < 2.6.36
111 AC_CACHE_CHECK([for two-argument statfs with statfs.f_frsize member],
112 [fu_cv_sys_stat_statfs2_frsize],
115 #ifdef HAVE_SYS_PARAM_H
116 #include <sys/param.h>
118 #ifdef HAVE_SYS_MOUNT_H
119 #include <sys/mount.h>
121 #ifdef HAVE_SYS_VFS_H
129 return statfs (".", &fsd) != 0;
131 [fu_cv_sys_stat_statfs2_frsize=yes],
132 [fu_cv_sys_stat_statfs2_frsize=no],
133 [fu_cv_sys_stat_statfs2_frsize=no])
135 if test $fu_cv_sys_stat_statfs2_frsize = yes; then
137 AC_DEFINE([STAT_STATFS2_FRSIZE], [1],
138 [Define if statfs takes 2 args and struct statfs has a field named f_frsize.
139 (glibc/Linux > 2.6)])
142 if test $ac_fsusage_space = no; then
143 # DEC Alpha running OSF/1
144 AC_CACHE_CHECK([for 3-argument statfs function (DEC OSF/1)],
145 [fu_cv_sys_stat_statfs3_osf1],
146 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
147 #include <sys/param.h>
148 #include <sys/types.h>
149 #include <sys/mount.h>
155 return statfs (".", &fsd, sizeof (struct statfs)) != 0;
157 [fu_cv_sys_stat_statfs3_osf1=yes],
158 [fu_cv_sys_stat_statfs3_osf1=no],
159 [fu_cv_sys_stat_statfs3_osf1=no])
161 if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
163 AC_DEFINE([STAT_STATFS3_OSF1], [1],
164 [Define if statfs takes 3 args. (DEC Alpha running OSF/1)])
168 if test $ac_fsusage_space = no; then
169 # glibc/Linux, Mac OS X, FreeBSD < 5.0, NetBSD < 3.0, OpenBSD < 4.4.
170 # (glibc/{Hurd,kFreeBSD}, FreeBSD >= 5.0, NetBSD >= 3.0,
171 # OpenBSD >= 4.4, AIX, HP-UX, OSF/1, Cygwin already handled above.)
172 # (On IRIX you need to include <sys/statfs.h>, not only <sys/mount.h> and
174 # (On Solaris, statfs has 4 arguments.)
175 AC_CACHE_CHECK([for two-argument statfs with statfs.f_bsize member (AIX, 4.3BSD)],
176 [fu_cv_sys_stat_statfs2_bsize],
177 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
178 #ifdef HAVE_SYS_PARAM_H
179 #include <sys/param.h>
181 #ifdef HAVE_SYS_MOUNT_H
182 #include <sys/mount.h>
184 #ifdef HAVE_SYS_VFS_H
192 return statfs (".", &fsd) != 0;
194 [fu_cv_sys_stat_statfs2_bsize=yes],
195 [fu_cv_sys_stat_statfs2_bsize=no],
196 [fu_cv_sys_stat_statfs2_bsize=no])
198 if test $fu_cv_sys_stat_statfs2_bsize = yes; then
200 AC_DEFINE([STAT_STATFS2_BSIZE], [1],
201 [Define if statfs takes 2 args and struct statfs has a field named f_bsize.
202 (4.3BSD, SunOS 4, HP-UX)])
206 if test $ac_fsusage_space = no; then
208 # (Solaris already handled above.)
209 AC_CACHE_CHECK([for four-argument statfs (SVR3)],
210 [fu_cv_sys_stat_statfs4],
211 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
212 #include <sys/types.h>
213 #include <sys/statfs.h>
218 return statfs (".", &fsd, sizeof fsd, 0) != 0;
220 [fu_cv_sys_stat_statfs4=yes],
221 [fu_cv_sys_stat_statfs4=no],
222 [fu_cv_sys_stat_statfs4=no])
224 if test $fu_cv_sys_stat_statfs4 = yes; then
226 AC_DEFINE([STAT_STATFS4], [1],
227 [Define if statfs takes 4 args. (SVR3, old Irix)])
231 if test $ac_fsusage_space = no; then
232 # 4.4BSD and older NetBSD
233 # (OSF/1 already handled above.)
234 # (On AIX, you need to include <sys/statfs.h>, not only <sys/mount.h>.)
235 # (On Solaris, statfs has 4 arguments and 'struct statfs' is not declared in
237 AC_CACHE_CHECK([for two-argument statfs with statfs.f_fsize member (4.4BSD and NetBSD)],
238 [fu_cv_sys_stat_statfs2_fsize],
239 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
240 #include <sys/types.h>
241 #ifdef HAVE_SYS_PARAM_H
242 #include <sys/param.h>
244 #ifdef HAVE_SYS_MOUNT_H
245 #include <sys/mount.h>
252 return statfs (".", &fsd) != 0;
254 [fu_cv_sys_stat_statfs2_fsize=yes],
255 [fu_cv_sys_stat_statfs2_fsize=no],
256 [fu_cv_sys_stat_statfs2_fsize=no])
258 if test $fu_cv_sys_stat_statfs2_fsize = yes; then
260 AC_DEFINE([STAT_STATFS2_FSIZE], [1],
261 [Define if statfs takes 2 args and struct statfs has a field named f_fsize.
266 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
271 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
272 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
273 # enable the work-around code in fsusage.c.
274 AC_DEFUN([gl_STATFS_TRUNCATES],
276 AC_CACHE_CHECK([for statfs that truncates block counts],
277 [fu_cv_sys_truncating_statfs],
280 #if !defined(sun) && !defined(__sun)
281 choke -- this is a workaround for a Sun-specific problem
283 #include <sys/types.h>
286 [[struct statfs t; long c = *(t.f_spare);
289 [fu_cv_sys_truncating_statfs=yes],
290 [fu_cv_sys_truncating_statfs=no])
292 if test $fu_cv_sys_truncating_statfs = yes; then
293 AC_DEFINE([STATFS_TRUNCATES_BLOCK_COUNTS], [1],
294 [Define if the block counts reported by statfs may be truncated to 2GB
295 and the correct values may be stored in the f_spare array.
296 (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
297 SunOS 4.1.1 seems not to be affected.)])
302 # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
303 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
305 AC_CHECK_HEADERS([sys/fs/s5param.h sys/statfs.h])