2 # Obtaining file system usage information.
4 # Copyright (C) 1997-1998, 2000-2001, 2003-2009 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])
22 if test $gl_cv_fs_space = yes; then
24 gl_PREREQ_FSUSAGE_EXTRA
28 # Try to determine how a program can obtain file system usage information.
29 # If successful, define the appropriate symbol (see fsusage.c) and
30 # execute ACTION-IF-FOUND. Otherwise, execute ACTION-IF-NOT-FOUND.
32 # gl_FILE_SYSTEM_USAGE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
34 AC_DEFUN([gl_FILE_SYSTEM_USAGE],
37 AC_MSG_NOTICE([checking how to get file system space usage])
40 # Perform only the link test since it seems there are no variants of the
41 # statvfs function. This check is more than just AC_CHECK_FUNCS([statvfs])
42 # because that got a false positive on SCO OSR5. Adding the declaration
43 # of a `struct statvfs' causes this test to fail (as it should) on such
44 # systems. That system is reported to work fine with STAT_STATFS4 which
45 # is what it gets when this test fails.
46 if test $ac_fsusage_space = no; then
48 AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs],
49 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
50 #if defined __GLIBC__ && defined __linux__
51 Do not use statvfs on systems with GNU libc on Linux, because that function
52 stats all preceding entries in /proc/mounts, and that makes df hang if even
53 one of the corresponding file systems is hard-mounted, but not available.
54 statvfs in GNU libc on Hurd, BeOS, Haiku operates differently: it only makes
59 "Do not use Tru64's statvfs implementation"
62 #include <sys/statvfs.h>]],
63 [[struct statvfs fsd; statvfs (0, &fsd);]])],
64 [fu_cv_sys_stat_statvfs=yes],
65 [fu_cv_sys_stat_statvfs=no])])
66 if test $fu_cv_sys_stat_statvfs = yes; then
68 AC_DEFINE([STAT_STATVFS], [1],
69 [ Define if there is a function named statvfs. (SVR4)])
73 if test $ac_fsusage_space = no; then
74 # DEC Alpha running OSF/1
75 AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
76 AC_CACHE_VAL([fu_cv_sys_stat_statfs3_osf1],
77 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
78 #include <sys/param.h>
79 #include <sys/types.h>
80 #include <sys/mount.h>
86 return statfs (".", &fsd, sizeof (struct statfs)) != 0;
88 [fu_cv_sys_stat_statfs3_osf1=yes],
89 [fu_cv_sys_stat_statfs3_osf1=no],
90 [fu_cv_sys_stat_statfs3_osf1=no])])
91 AC_MSG_RESULT([$fu_cv_sys_stat_statfs3_osf1])
92 if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
94 AC_DEFINE([STAT_STATFS3_OSF1], [1],
95 [ Define if statfs takes 3 args. (DEC Alpha running OSF/1)])
99 if test $ac_fsusage_space = no; then
101 AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
102 member (AIX, 4.3BSD)])
103 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_bsize],
104 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
105 #ifdef HAVE_SYS_PARAM_H
106 #include <sys/param.h>
108 #ifdef HAVE_SYS_MOUNT_H
109 #include <sys/mount.h>
111 #ifdef HAVE_SYS_VFS_H
119 return statfs (".", &fsd) != 0;
121 [fu_cv_sys_stat_statfs2_bsize=yes],
122 [fu_cv_sys_stat_statfs2_bsize=no],
123 [fu_cv_sys_stat_statfs2_bsize=no])])
124 AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_bsize])
125 if test $fu_cv_sys_stat_statfs2_bsize = yes; then
127 AC_DEFINE([STAT_STATFS2_BSIZE], [1],
128 [ Define if statfs takes 2 args and struct statfs has a field named f_bsize.
129 (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
133 if test $ac_fsusage_space = no; then
135 AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
136 AC_CACHE_VAL([fu_cv_sys_stat_statfs4],
137 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
138 #include <sys/types.h>
139 #include <sys/statfs.h>
144 return statfs (".", &fsd, sizeof fsd, 0) != 0;
146 [fu_cv_sys_stat_statfs4=yes],
147 [fu_cv_sys_stat_statfs4=no],
148 [fu_cv_sys_stat_statfs4=no])])
149 AC_MSG_RESULT([$fu_cv_sys_stat_statfs4])
150 if test $fu_cv_sys_stat_statfs4 = yes; then
152 AC_DEFINE([STAT_STATFS4], [1],
153 [ Define if statfs takes 4 args. (SVR3, Dynix, Irix, Dolphin)])
157 if test $ac_fsusage_space = no; then
159 AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
160 member (4.4BSD and NetBSD)])
161 AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize],
162 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
163 #include <sys/types.h>
164 #ifdef HAVE_SYS_PARAM_H
165 #include <sys/param.h>
167 #ifdef HAVE_SYS_MOUNT_H
168 #include <sys/mount.h>
175 return statfs (".", &fsd) != 0;
177 [fu_cv_sys_stat_statfs2_fsize=yes],
178 [fu_cv_sys_stat_statfs2_fsize=no],
179 [fu_cv_sys_stat_statfs2_fsize=no])])
180 AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_fsize])
181 if test $fu_cv_sys_stat_statfs2_fsize = yes; then
183 AC_DEFINE([STAT_STATFS2_FSIZE], [1],
184 [ Define if statfs takes 2 args and struct statfs has a field named f_fsize.
189 if test $ac_fsusage_space = no; then
191 AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
192 AC_CACHE_VAL([fu_cv_sys_stat_fs_data],
193 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
194 #include <sys/types.h>
195 #ifdef HAVE_SYS_PARAM_H
196 #include <sys/param.h>
198 #ifdef HAVE_SYS_MOUNT_H
199 #include <sys/mount.h>
201 #ifdef HAVE_SYS_FS_TYPES_H
202 #include <sys/fs_types.h>
208 /* Ultrix's statfs returns 1 for success,
209 0 for not mounted, -1 for failure. */
210 return statfs (".", &fsd) != 1;
212 [fu_cv_sys_stat_fs_data=yes],
213 [fu_cv_sys_stat_fs_data=no],
214 [fu_cv_sys_stat_fs_data=no])])
215 AC_MSG_RESULT([$fu_cv_sys_stat_fs_data])
216 if test $fu_cv_sys_stat_fs_data = yes; then
218 AC_DEFINE([STAT_STATFS2_FS_DATA], [1],
219 [ Define if statfs takes 2 args and the second argument has
220 type struct fs_data. (Ultrix)])
224 if test $ac_fsusage_space = no; then
226 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <sys/filsys.h>
228 [AC_DEFINE([STAT_READ_FILSYS], [1],
229 [Define if there is no specific function for reading file systems usage
230 information and you have the <sys/filsys.h> header file. (SVR2)])
231 ac_fsusage_space=yes])
234 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
239 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
240 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
241 # enable the work-around code in fsusage.c.
242 AC_DEFUN([gl_STATFS_TRUNCATES],
244 AC_MSG_CHECKING([for statfs that truncates block counts])
245 AC_CACHE_VAL([fu_cv_sys_truncating_statfs],
246 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
247 #if !defined(sun) && !defined(__sun)
248 choke -- this is a workaround for a Sun-specific problem
250 #include <sys/types.h>
251 #include <sys/vfs.h>]],
252 [[struct statfs t; long c = *(t.f_spare);
253 if (c) return 0;]])],
254 [fu_cv_sys_truncating_statfs=yes],
255 [fu_cv_sys_truncating_statfs=no])])
256 if test $fu_cv_sys_truncating_statfs = yes; then
257 AC_DEFINE([STATFS_TRUNCATES_BLOCK_COUNTS], [1],
258 [Define if the block counts reported by statfs may be truncated to 2GB
259 and the correct values may be stored in the f_spare array.
260 (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
261 SunOS 4.1.1 seems not to be affected.)])
263 AC_MSG_RESULT([$fu_cv_sys_truncating_statfs])
267 # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
268 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
270 AC_CHECK_HEADERS([dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h])