2 # Obtaining file system usage information.
4 # Copyright (C) 1997-1998, 2000-2001, 2003-2012 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_NOTICE([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)], [fu_cv_sys_stat_statvfs],
52 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
54 "Do not use Tru64's statvfs implementation"
57 #include <sys/statvfs.h>
61 #if defined __APPLE__ && defined __MACH__
63 /* On Mac OS X >= 10.5, f_blocks in 'struct statvfs' is a 32-bit quantity;
64 that commonly limits file systems to 4 TiB. Whereas f_blocks in
65 'struct statfs' is a 64-bit type, thanks to the large-file support
66 that was enabled above. In this case, don't use statvfs(); use statfs()
68 int check_f_blocks_size[sizeof fsd.f_blocks * CHAR_BIT <= 32 ? -1 : 1];
71 [[statvfs (0, &fsd);]])],
72 [fu_cv_sys_stat_statvfs=yes],
73 [fu_cv_sys_stat_statvfs=no])])
74 if test $fu_cv_sys_stat_statvfs = yes; then
76 # AIX >= 5.2 has statvfs64 that has a wider f_blocks field than statvfs.
77 # glibc, HP-UX, IRIX, Solaris have statvfs64 as well, but on these systems
78 # statvfs with large-file support is already equivalent to statvfs64.
79 AC_CACHE_CHECK([whether to use statvfs64],
80 [fu_cv_sys_stat_statvfs64],
83 [[#include <sys/types.h>
84 #include <sys/statvfs.h>
86 int check_f_blocks_larger_in_statvfs64
87 [sizeof (((struct statvfs64 *) 0)->f_blocks)
88 > sizeof (((struct statvfs *) 0)->f_blocks)
91 [[statvfs64 (0, &fsd);]])],
92 [fu_cv_sys_stat_statvfs64=yes],
93 [fu_cv_sys_stat_statvfs64=no])
95 if test $fu_cv_sys_stat_statvfs64 = yes; then
96 AC_DEFINE([STAT_STATVFS64], [1],
97 [ Define if statvfs64 should be preferred over statvfs.])
99 AC_DEFINE([STAT_STATVFS], [1],
100 [ Define if there is a function named statvfs. (SVR4)])
105 if test $ac_fsusage_space = no; then
106 # DEC Alpha running OSF/1
107 AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
108 AC_CACHE_VAL([fu_cv_sys_stat_statfs3_osf1],
109 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
110 #include <sys/param.h>
111 #include <sys/types.h>
112 #include <sys/mount.h>
118 return statfs (".", &fsd, sizeof (struct statfs)) != 0;
120 [fu_cv_sys_stat_statfs3_osf1=yes],
121 [fu_cv_sys_stat_statfs3_osf1=no],
122 [fu_cv_sys_stat_statfs3_osf1=no])])
123 AC_MSG_RESULT([$fu_cv_sys_stat_statfs3_osf1])
124 if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
126 AC_DEFINE([STAT_STATFS3_OSF1], [1],
127 [ Define if statfs takes 3 args. (DEC Alpha running OSF/1)])
131 # Check for this unconditionally so we have a
132 # good fallback on glibc/Linux > 2.6 < 2.6.36
133 AC_MSG_CHECKING([for two-argument statfs with statfs.f_frsize member])
134 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_frsize],
135 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
136 #ifdef HAVE_SYS_PARAM_H
137 #include <sys/param.h>
139 #ifdef HAVE_SYS_MOUNT_H
140 #include <sys/mount.h>
142 #ifdef HAVE_SYS_VFS_H
150 return statfs (".", &fsd) != 0;
152 [fu_cv_sys_stat_statfs2_frsize=yes],
153 [fu_cv_sys_stat_statfs2_frsize=no],
154 [fu_cv_sys_stat_statfs2_frsize=no])])
155 AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_frsize])
156 if test $fu_cv_sys_stat_statfs2_frsize = yes; then
157 AC_DEFINE([STAT_STATFS2_FRSIZE], [1],
158 [ Define if statfs takes 2 args and struct statfs has a field named f_frsize.
159 (glibc/Linux > 2.6)])
162 if test $ac_fsusage_space = no; then
163 # glibc/Linux, Mac OS X, FreeBSD < 5.0, NetBSD < 3.0, OpenBSD < 4.4.
164 # (glibc/{Hurd,kFreeBSD}, FreeBSD >= 5.0, NetBSD >= 3.0,
165 # OpenBSD >= 4.4, AIX, HP-UX, OSF/1, Cygwin already handled above.)
166 # (On IRIX you need to include <sys/statfs.h>, not only <sys/mount.h> and
168 # (On Solaris, statfs has 4 arguments.)
169 AC_MSG_CHECKING([for two-argument statfs with statfs.f_bsize dnl
170 member (AIX, 4.3BSD)])
171 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_bsize],
172 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
173 #ifdef HAVE_SYS_PARAM_H
174 #include <sys/param.h>
176 #ifdef HAVE_SYS_MOUNT_H
177 #include <sys/mount.h>
179 #ifdef HAVE_SYS_VFS_H
187 return statfs (".", &fsd) != 0;
189 [fu_cv_sys_stat_statfs2_bsize=yes],
190 [fu_cv_sys_stat_statfs2_bsize=no],
191 [fu_cv_sys_stat_statfs2_bsize=no])])
192 AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_bsize])
193 if test $fu_cv_sys_stat_statfs2_bsize = yes; then
195 AC_DEFINE([STAT_STATFS2_BSIZE], [1],
196 [ Define if statfs takes 2 args and struct statfs has a field named f_bsize.
197 (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
201 if test $ac_fsusage_space = no; then
203 # (Solaris already handled above.)
204 AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
205 AC_CACHE_VAL([fu_cv_sys_stat_statfs4],
206 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
207 #include <sys/types.h>
208 #include <sys/statfs.h>
213 return statfs (".", &fsd, sizeof fsd, 0) != 0;
215 [fu_cv_sys_stat_statfs4=yes],
216 [fu_cv_sys_stat_statfs4=no],
217 [fu_cv_sys_stat_statfs4=no])])
218 AC_MSG_RESULT([$fu_cv_sys_stat_statfs4])
219 if test $fu_cv_sys_stat_statfs4 = yes; then
221 AC_DEFINE([STAT_STATFS4], [1],
222 [ Define if statfs takes 4 args. (SVR3, Dynix, old Irix, old AIX, Dolphin)])
226 if test $ac_fsusage_space = no; then
227 # 4.4BSD and older NetBSD
228 # (OSF/1 already handled above.)
229 # (On AIX, you need to include <sys/statfs.h>, not only <sys/mount.h>.)
230 # (On Solaris, statfs has 4 arguments and 'struct statfs' is not declared in
232 AC_MSG_CHECKING([for two-argument statfs with statfs.f_fsize dnl
233 member (4.4BSD and NetBSD)])
234 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize],
235 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
236 #include <sys/types.h>
237 #ifdef HAVE_SYS_PARAM_H
238 #include <sys/param.h>
240 #ifdef HAVE_SYS_MOUNT_H
241 #include <sys/mount.h>
248 return statfs (".", &fsd) != 0;
250 [fu_cv_sys_stat_statfs2_fsize=yes],
251 [fu_cv_sys_stat_statfs2_fsize=no],
252 [fu_cv_sys_stat_statfs2_fsize=no])])
253 AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_fsize])
254 if test $fu_cv_sys_stat_statfs2_fsize = yes; then
256 AC_DEFINE([STAT_STATFS2_FSIZE], [1],
257 [ Define if statfs takes 2 args and struct statfs has a field named f_fsize.
262 if test $ac_fsusage_space = no; then
264 AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
265 AC_CACHE_VAL([fu_cv_sys_stat_fs_data],
266 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
267 #include <sys/types.h>
268 #ifdef HAVE_SYS_PARAM_H
269 #include <sys/param.h>
271 #ifdef HAVE_SYS_MOUNT_H
272 #include <sys/mount.h>
274 #ifdef HAVE_SYS_FS_TYPES_H
275 #include <sys/fs_types.h>
281 /* Ultrix's statfs returns 1 for success,
282 0 for not mounted, -1 for failure. */
283 return statfs (".", &fsd) != 1;
285 [fu_cv_sys_stat_fs_data=yes],
286 [fu_cv_sys_stat_fs_data=no],
287 [fu_cv_sys_stat_fs_data=no])])
288 AC_MSG_RESULT([$fu_cv_sys_stat_fs_data])
289 if test $fu_cv_sys_stat_fs_data = yes; then
291 AC_DEFINE([STAT_STATFS2_FS_DATA], [1],
292 [ Define if statfs takes 2 args and the second argument has
293 type struct fs_data. (Ultrix)])
297 if test $ac_fsusage_space = no; then
299 # (AIX, HP-UX, OSF/1 already handled above.)
300 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <sys/filsys.h>
302 [AC_DEFINE([STAT_READ_FILSYS], [1],
303 [Define if there is no specific function for reading file systems usage
304 information and you have the <sys/filsys.h> header file. (SVR2)])
305 ac_fsusage_space=yes])
308 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
313 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
314 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
315 # enable the work-around code in fsusage.c.
316 AC_DEFUN([gl_STATFS_TRUNCATES],
318 AC_MSG_CHECKING([for statfs that truncates block counts])
319 AC_CACHE_VAL([fu_cv_sys_truncating_statfs],
320 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
321 #if !defined(sun) && !defined(__sun)
322 choke -- this is a workaround for a Sun-specific problem
324 #include <sys/types.h>
325 #include <sys/vfs.h>]],
326 [[struct statfs t; long c = *(t.f_spare);
327 if (c) return 0;]])],
328 [fu_cv_sys_truncating_statfs=yes],
329 [fu_cv_sys_truncating_statfs=no])])
330 if test $fu_cv_sys_truncating_statfs = yes; then
331 AC_DEFINE([STATFS_TRUNCATES_BLOCK_COUNTS], [1],
332 [Define if the block counts reported by statfs may be truncated to 2GB
333 and the correct values may be stored in the f_spare array.
334 (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
335 SunOS 4.1.1 seems not to be affected.)])
337 AC_MSG_RESULT([$fu_cv_sys_truncating_statfs])
341 # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
342 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
344 AC_CHECK_HEADERS([dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h])