2 # Obtaining file system usage information.
4 # Copyright (C) 1997, 1998, 2000, 2001, 2003, 2004 Free Software
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software Foundation,
19 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 # Written by Jim Meyering.
23 AC_DEFUN([gl_FSUSAGE],
25 AC_CHECK_HEADERS_ONCE(sys/param.h)
26 AC_CHECK_HEADERS_ONCE(sys/vfs.h sys/fs_types.h)
27 AC_CHECK_HEADERS(sys/mount.h, [], [],
30 #include <sys/param.h>
32 gl_FILE_SYSTEM_USAGE([gl_cv_fs_space=yes], [gl_cv_fs_space=no])
33 if test $gl_cv_fs_space = yes; then
35 gl_PREREQ_FSUSAGE_EXTRA
39 # Try to determine how a program can obtain file system usage information.
40 # If successful, define the appropriate symbol (see fsusage.c) and
41 # execute ACTION-IF-FOUND. Otherwise, execute ACTION-IF-NOT-FOUND.
43 # gl_FILE_SYSTEM_USAGE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
45 AC_DEFUN([gl_FILE_SYSTEM_USAGE],
48 echo "checking how to get file system space usage..."
51 # Perform only the link test since it seems there are no variants of the
52 # statvfs function. This check is more than just AC_CHECK_FUNCS(statvfs)
53 # because that got a false positive on SCO OSR5. Adding the declaration
54 # of a `struct statvfs' causes this test to fail (as it should) on such
55 # systems. That system is reported to work fine with STAT_STATFS4 which
56 # is what it gets when this test fails.
57 if test $ac_fsusage_space = no; then
59 AC_CACHE_CHECK([for statvfs function (SVR4)], fu_cv_sys_stat_statvfs,
60 [AC_TRY_LINK([#include <sys/types.h>
62 Do not use statvfs on systems with GNU libc, because that function stats
63 all preceding entries in /proc/mounts, and that makes df hang if even
64 one of the corresponding file systems is hard-mounted, but not available.
66 #include <sys/statvfs.h>],
67 [struct statvfs fsd; statvfs (0, &fsd);],
68 fu_cv_sys_stat_statvfs=yes,
69 fu_cv_sys_stat_statvfs=no)])
70 if test $fu_cv_sys_stat_statvfs = yes; then
72 AC_DEFINE(STAT_STATVFS, 1,
73 [ Define if there is a function named statvfs. (SVR4)])
77 if test $ac_fsusage_space = no; then
78 # DEC Alpha running OSF/1
79 AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
80 AC_CACHE_VAL(fu_cv_sys_stat_statfs3_osf1,
82 #include <sys/param.h>
83 #include <sys/types.h>
84 #include <sys/mount.h>
89 exit (statfs (".", &fsd, sizeof (struct statfs)));
91 fu_cv_sys_stat_statfs3_osf1=yes,
92 fu_cv_sys_stat_statfs3_osf1=no,
93 fu_cv_sys_stat_statfs3_osf1=no)])
94 AC_MSG_RESULT($fu_cv_sys_stat_statfs3_osf1)
95 if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
97 AC_DEFINE(STAT_STATFS3_OSF1, 1,
98 [ Define if statfs takes 3 args. (DEC Alpha running OSF/1)])
102 if test $ac_fsusage_space = no; then
104 AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
105 member (AIX, 4.3BSD)])
106 AC_CACHE_VAL(fu_cv_sys_stat_statfs2_bsize,
108 #ifdef HAVE_SYS_PARAM_H
109 #include <sys/param.h>
111 #ifdef HAVE_SYS_MOUNT_H
112 #include <sys/mount.h>
114 #ifdef HAVE_SYS_VFS_H
121 exit (statfs (".", &fsd));
123 fu_cv_sys_stat_statfs2_bsize=yes,
124 fu_cv_sys_stat_statfs2_bsize=no,
125 fu_cv_sys_stat_statfs2_bsize=no)])
126 AC_MSG_RESULT($fu_cv_sys_stat_statfs2_bsize)
127 if test $fu_cv_sys_stat_statfs2_bsize = yes; then
129 AC_DEFINE(STAT_STATFS2_BSIZE, 1,
130 [ Define if statfs takes 2 args and struct statfs has a field named f_bsize.
131 (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
135 if test $ac_fsusage_space = no; then
137 AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
138 AC_CACHE_VAL(fu_cv_sys_stat_statfs4,
139 [AC_TRY_RUN([#include <sys/types.h>
140 #include <sys/statfs.h>
144 exit (statfs (".", &fsd, sizeof fsd, 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_TRY_RUN([#include <sys/types.h>
163 #ifdef HAVE_SYS_PARAM_H
164 #include <sys/param.h>
166 #ifdef HAVE_SYS_MOUNT_H
167 #include <sys/mount.h>
173 exit (statfs (".", &fsd));
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>
204 /* Ultrix's statfs returns 1 for success,
205 0 for not mounted, -1 for failure. */
206 exit (statfs (".", &fsd) != 1);
208 fu_cv_sys_stat_fs_data=yes,
209 fu_cv_sys_stat_fs_data=no,
210 fu_cv_sys_stat_fs_data=no)])
211 AC_MSG_RESULT($fu_cv_sys_stat_fs_data)
212 if test $fu_cv_sys_stat_fs_data = yes; then
214 AC_DEFINE(STAT_STATFS2_FS_DATA, 1,
215 [ Define if statfs takes 2 args and the second argument has
216 type struct fs_data. (Ultrix)])
220 if test $ac_fsusage_space = no; then
222 AC_TRY_CPP([#include <sys/filsys.h>
224 AC_DEFINE(STAT_READ_FILSYS, 1,
225 [Define if there is no specific function for reading file systems usage
226 information and you have the <sys/filsys.h> header file. (SVR2)])
227 ac_fsusage_space=yes)
230 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
235 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
236 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
237 # enable the work-around code in fsusage.c.
238 AC_DEFUN([gl_STATFS_TRUNCATES],
240 AC_MSG_CHECKING([for statfs that truncates block counts])
241 AC_CACHE_VAL(fu_cv_sys_truncating_statfs,
242 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
243 #if !defined(sun) && !defined(__sun)
244 choke -- this is a workaround for a Sun-specific problem
246 #include <sys/types.h>
247 #include <sys/vfs.h>]],
248 [[struct statfs t; long c = *(t.f_spare);]])],
249 [fu_cv_sys_truncating_statfs=yes],
250 [fu_cv_sys_truncating_statfs=no])])
251 if test $fu_cv_sys_truncating_statfs = yes; then
252 AC_DEFINE(STATFS_TRUNCATES_BLOCK_COUNTS, 1,
253 [Define if the block counts reported by statfs may be truncated to 2GB
254 and the correct values may be stored in the f_spare array.
255 (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
256 SunOS 4.1.1 seems not to be affected.)])
258 AC_MSG_RESULT($fu_cv_sys_truncating_statfs)
262 # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
263 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
265 AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
266 AC_CHECK_HEADERS_ONCE(fcntl.h)
267 AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h sys/statvfs.h)