2 # Obtaining file system usage information.
4 # Copyright (C) 1997, 1998, 2000, 2001, 2003, 2004 Free Software
7 # This file is free software; the Free Software Foundation
8 # gives unlimited permission to copy and/or distribute it,
9 # with or without modifications, as long as this notice is preserved.
11 # Written by Jim Meyering.
13 AC_DEFUN([gl_FSUSAGE],
15 AC_CHECK_HEADERS_ONCE(sys/param.h)
16 AC_CHECK_HEADERS_ONCE(sys/vfs.h sys/fs_types.h)
17 AC_CHECK_HEADERS(sys/mount.h, [], [],
20 #include <sys/param.h>
22 gl_FILE_SYSTEM_USAGE([gl_cv_fs_space=yes], [gl_cv_fs_space=no])
23 if test $gl_cv_fs_space = yes; then
25 gl_PREREQ_FSUSAGE_EXTRA
29 # Try to determine how a program can obtain file system usage information.
30 # If successful, define the appropriate symbol (see fsusage.c) and
31 # execute ACTION-IF-FOUND. Otherwise, execute ACTION-IF-NOT-FOUND.
33 # gl_FILE_SYSTEM_USAGE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
35 AC_DEFUN([gl_FILE_SYSTEM_USAGE],
38 echo "checking how to get file system space usage..."
41 # Perform only the link test since it seems there are no variants of the
42 # statvfs function. This check is more than just AC_CHECK_FUNCS(statvfs)
43 # because that got a false positive on SCO OSR5. Adding the declaration
44 # of a `struct statvfs' causes this test to fail (as it should) on such
45 # systems. That system is reported to work fine with STAT_STATFS4 which
46 # is what it gets when this test fails.
47 if test $ac_fsusage_space = no; then
49 AC_CACHE_CHECK([for statvfs function (SVR4)], fu_cv_sys_stat_statvfs,
50 [AC_TRY_LINK([#include <sys/types.h>
52 Do not use statvfs on systems with GNU libc, because that function stats
53 all preceding entries in /proc/mounts, and that makes df hang if even
54 one of the corresponding file systems is hard-mounted, but not available.
56 #include <sys/statvfs.h>],
57 [struct statvfs fsd; statvfs (0, &fsd);],
58 fu_cv_sys_stat_statvfs=yes,
59 fu_cv_sys_stat_statvfs=no)])
60 if test $fu_cv_sys_stat_statvfs = yes; then
62 AC_DEFINE(STAT_STATVFS, 1,
63 [ Define if there is a function named statvfs. (SVR4)])
67 if test $ac_fsusage_space = no; then
68 # DEC Alpha running OSF/1
69 AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
70 AC_CACHE_VAL(fu_cv_sys_stat_statfs3_osf1,
72 #include <sys/param.h>
73 #include <sys/types.h>
74 #include <sys/mount.h>
79 exit (statfs (".", &fsd, sizeof (struct statfs)));
81 fu_cv_sys_stat_statfs3_osf1=yes,
82 fu_cv_sys_stat_statfs3_osf1=no,
83 fu_cv_sys_stat_statfs3_osf1=no)])
84 AC_MSG_RESULT($fu_cv_sys_stat_statfs3_osf1)
85 if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
87 AC_DEFINE(STAT_STATFS3_OSF1, 1,
88 [ Define if statfs takes 3 args. (DEC Alpha running OSF/1)])
92 if test $ac_fsusage_space = no; then
94 AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
95 member (AIX, 4.3BSD)])
96 AC_CACHE_VAL(fu_cv_sys_stat_statfs2_bsize,
98 #ifdef HAVE_SYS_PARAM_H
99 #include <sys/param.h>
101 #ifdef HAVE_SYS_MOUNT_H
102 #include <sys/mount.h>
104 #ifdef HAVE_SYS_VFS_H
111 exit (statfs (".", &fsd));
113 fu_cv_sys_stat_statfs2_bsize=yes,
114 fu_cv_sys_stat_statfs2_bsize=no,
115 fu_cv_sys_stat_statfs2_bsize=no)])
116 AC_MSG_RESULT($fu_cv_sys_stat_statfs2_bsize)
117 if test $fu_cv_sys_stat_statfs2_bsize = yes; then
119 AC_DEFINE(STAT_STATFS2_BSIZE, 1,
120 [ Define if statfs takes 2 args and struct statfs has a field named f_bsize.
121 (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
125 if test $ac_fsusage_space = no; then
127 AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
128 AC_CACHE_VAL(fu_cv_sys_stat_statfs4,
129 [AC_TRY_RUN([#include <sys/types.h>
130 #include <sys/statfs.h>
134 exit (statfs (".", &fsd, sizeof fsd, 0));
136 fu_cv_sys_stat_statfs4=yes,
137 fu_cv_sys_stat_statfs4=no,
138 fu_cv_sys_stat_statfs4=no)])
139 AC_MSG_RESULT($fu_cv_sys_stat_statfs4)
140 if test $fu_cv_sys_stat_statfs4 = yes; then
142 AC_DEFINE(STAT_STATFS4, 1,
143 [ Define if statfs takes 4 args. (SVR3, Dynix, Irix, Dolphin)])
147 if test $ac_fsusage_space = no; then
149 AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
150 member (4.4BSD and NetBSD)])
151 AC_CACHE_VAL(fu_cv_sys_stat_statfs2_fsize,
152 [AC_TRY_RUN([#include <sys/types.h>
153 #ifdef HAVE_SYS_PARAM_H
154 #include <sys/param.h>
156 #ifdef HAVE_SYS_MOUNT_H
157 #include <sys/mount.h>
163 exit (statfs (".", &fsd));
165 fu_cv_sys_stat_statfs2_fsize=yes,
166 fu_cv_sys_stat_statfs2_fsize=no,
167 fu_cv_sys_stat_statfs2_fsize=no)])
168 AC_MSG_RESULT($fu_cv_sys_stat_statfs2_fsize)
169 if test $fu_cv_sys_stat_statfs2_fsize = yes; then
171 AC_DEFINE(STAT_STATFS2_FSIZE, 1,
172 [ Define if statfs takes 2 args and struct statfs has a field named f_fsize.
177 if test $ac_fsusage_space = no; then
179 AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
180 AC_CACHE_VAL(fu_cv_sys_stat_fs_data,
181 [AC_TRY_RUN([#include <sys/types.h>
182 #ifdef HAVE_SYS_PARAM_H
183 #include <sys/param.h>
185 #ifdef HAVE_SYS_MOUNT_H
186 #include <sys/mount.h>
188 #ifdef HAVE_SYS_FS_TYPES_H
189 #include <sys/fs_types.h>
194 /* Ultrix's statfs returns 1 for success,
195 0 for not mounted, -1 for failure. */
196 exit (statfs (".", &fsd) != 1);
198 fu_cv_sys_stat_fs_data=yes,
199 fu_cv_sys_stat_fs_data=no,
200 fu_cv_sys_stat_fs_data=no)])
201 AC_MSG_RESULT($fu_cv_sys_stat_fs_data)
202 if test $fu_cv_sys_stat_fs_data = yes; then
204 AC_DEFINE(STAT_STATFS2_FS_DATA, 1,
205 [ Define if statfs takes 2 args and the second argument has
206 type struct fs_data. (Ultrix)])
210 if test $ac_fsusage_space = no; then
212 AC_TRY_CPP([#include <sys/filsys.h>
214 AC_DEFINE(STAT_READ_FILSYS, 1,
215 [Define if there is no specific function for reading file systems usage
216 information and you have the <sys/filsys.h> header file. (SVR2)])
217 ac_fsusage_space=yes)
220 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
225 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
226 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
227 # enable the work-around code in fsusage.c.
228 AC_DEFUN([gl_STATFS_TRUNCATES],
230 AC_MSG_CHECKING([for statfs that truncates block counts])
231 AC_CACHE_VAL(fu_cv_sys_truncating_statfs,
232 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
233 #if !defined(sun) && !defined(__sun)
234 choke -- this is a workaround for a Sun-specific problem
236 #include <sys/types.h>
237 #include <sys/vfs.h>]],
238 [[struct statfs t; long c = *(t.f_spare);]])],
239 [fu_cv_sys_truncating_statfs=yes],
240 [fu_cv_sys_truncating_statfs=no])])
241 if test $fu_cv_sys_truncating_statfs = yes; then
242 AC_DEFINE(STATFS_TRUNCATES_BLOCK_COUNTS, 1,
243 [Define if the block counts reported by statfs may be truncated to 2GB
244 and the correct values may be stored in the f_spare array.
245 (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
246 SunOS 4.1.1 seems not to be affected.)])
248 AC_MSG_RESULT($fu_cv_sys_truncating_statfs)
252 # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
253 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
255 AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
256 AC_CHECK_HEADERS_ONCE(fcntl.h)
257 AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h sys/statvfs.h)