2 # Obtaining file system usage information.
4 # Copyright (C) 1997, 1998, 2000, 2001, 2003-2008 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_TRY_LINK([#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,
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,
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_TRY_RUN([#include <sys/types.h>
138 #include <sys/statfs.h>
143 return statfs (".", &fsd, sizeof fsd, 0) != 0;
145 fu_cv_sys_stat_statfs4=yes,
146 fu_cv_sys_stat_statfs4=no,
147 fu_cv_sys_stat_statfs4=no)])
148 AC_MSG_RESULT($fu_cv_sys_stat_statfs4)
149 if test $fu_cv_sys_stat_statfs4 = yes; then
151 AC_DEFINE(STAT_STATFS4, 1,
152 [ Define if statfs takes 4 args. (SVR3, Dynix, Irix, Dolphin)])
156 if test $ac_fsusage_space = no; then
158 AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
159 member (4.4BSD and NetBSD)])
160 AC_CACHE_VAL(fu_cv_sys_stat_statfs2_fsize,
161 [AC_TRY_RUN([#include <sys/types.h>
162 #ifdef HAVE_SYS_PARAM_H
163 #include <sys/param.h>
165 #ifdef HAVE_SYS_MOUNT_H
166 #include <sys/mount.h>
173 return statfs (".", &fsd) != 0;
175 fu_cv_sys_stat_statfs2_fsize=yes,
176 fu_cv_sys_stat_statfs2_fsize=no,
177 fu_cv_sys_stat_statfs2_fsize=no)])
178 AC_MSG_RESULT($fu_cv_sys_stat_statfs2_fsize)
179 if test $fu_cv_sys_stat_statfs2_fsize = yes; then
181 AC_DEFINE(STAT_STATFS2_FSIZE, 1,
182 [ Define if statfs takes 2 args and struct statfs has a field named f_fsize.
187 if test $ac_fsusage_space = no; then
189 AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
190 AC_CACHE_VAL(fu_cv_sys_stat_fs_data,
191 [AC_TRY_RUN([#include <sys/types.h>
192 #ifdef HAVE_SYS_PARAM_H
193 #include <sys/param.h>
195 #ifdef HAVE_SYS_MOUNT_H
196 #include <sys/mount.h>
198 #ifdef HAVE_SYS_FS_TYPES_H
199 #include <sys/fs_types.h>
205 /* Ultrix's statfs returns 1 for success,
206 0 for not mounted, -1 for failure. */
207 return statfs (".", &fsd) != 1;
209 fu_cv_sys_stat_fs_data=yes,
210 fu_cv_sys_stat_fs_data=no,
211 fu_cv_sys_stat_fs_data=no)])
212 AC_MSG_RESULT($fu_cv_sys_stat_fs_data)
213 if test $fu_cv_sys_stat_fs_data = yes; then
215 AC_DEFINE(STAT_STATFS2_FS_DATA, 1,
216 [ Define if statfs takes 2 args and the second argument has
217 type struct fs_data. (Ultrix)])
221 if test $ac_fsusage_space = no; then
223 AC_TRY_CPP([#include <sys/filsys.h>
225 AC_DEFINE(STAT_READ_FILSYS, 1,
226 [Define if there is no specific function for reading file systems usage
227 information and you have the <sys/filsys.h> header file. (SVR2)])
228 ac_fsusage_space=yes)
231 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
236 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
237 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
238 # enable the work-around code in fsusage.c.
239 AC_DEFUN([gl_STATFS_TRUNCATES],
241 AC_MSG_CHECKING([for statfs that truncates block counts])
242 AC_CACHE_VAL(fu_cv_sys_truncating_statfs,
243 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
244 #if !defined(sun) && !defined(__sun)
245 choke -- this is a workaround for a Sun-specific problem
247 #include <sys/types.h>
248 #include <sys/vfs.h>]],
249 [[struct statfs t; long c = *(t.f_spare);
250 if (c) return 0;]])],
251 [fu_cv_sys_truncating_statfs=yes],
252 [fu_cv_sys_truncating_statfs=no])])
253 if test $fu_cv_sys_truncating_statfs = yes; then
254 AC_DEFINE(STATFS_TRUNCATES_BLOCK_COUNTS, 1,
255 [Define if the block counts reported by statfs may be truncated to 2GB
256 and the correct values may be stored in the f_spare array.
257 (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
258 SunOS 4.1.1 seems not to be affected.)])
260 AC_MSG_RESULT($fu_cv_sys_truncating_statfs)
264 # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
265 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
267 AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h)