2 # Obtaining file system usage information.
4 # Copyright (C) 1997, 1998, 2000, 2001, 2003, 2004, 2005 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_LIBSOURCES([fsusage.c, fsusage.h])
17 AC_CHECK_HEADERS_ONCE(sys/param.h)
18 AC_CHECK_HEADERS_ONCE(sys/vfs.h sys/fs_types.h)
19 AC_CHECK_HEADERS(sys/mount.h, [], [],
22 #include <sys/param.h>
24 gl_FILE_SYSTEM_USAGE([gl_cv_fs_space=yes], [gl_cv_fs_space=no])
25 if test $gl_cv_fs_space = yes; then
27 gl_PREREQ_FSUSAGE_EXTRA
31 # Try to determine how a program can obtain file system usage information.
32 # If successful, define the appropriate symbol (see fsusage.c) and
33 # execute ACTION-IF-FOUND. Otherwise, execute ACTION-IF-NOT-FOUND.
35 # gl_FILE_SYSTEM_USAGE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
37 AC_DEFUN([gl_FILE_SYSTEM_USAGE],
40 echo "checking how to get file system space usage..."
43 # Perform only the link test since it seems there are no variants of the
44 # statvfs function. This check is more than just AC_CHECK_FUNCS(statvfs)
45 # because that got a false positive on SCO OSR5. Adding the declaration
46 # of a `struct statvfs' causes this test to fail (as it should) on such
47 # systems. That system is reported to work fine with STAT_STATFS4 which
48 # is what it gets when this test fails.
49 if test $ac_fsusage_space = no; then
51 AC_CACHE_CHECK([for statvfs function (SVR4)], fu_cv_sys_stat_statvfs,
52 [AC_TRY_LINK([#include <sys/types.h>
54 Do not use statvfs on systems with GNU libc, because that function stats
55 all preceding entries in /proc/mounts, and that makes df hang if even
56 one of the corresponding file systems is hard-mounted, but not available.
58 #include <sys/statvfs.h>],
59 [struct statvfs fsd; statvfs (0, &fsd);],
60 fu_cv_sys_stat_statvfs=yes,
61 fu_cv_sys_stat_statvfs=no)])
62 if test $fu_cv_sys_stat_statvfs = yes; then
64 AC_DEFINE(STAT_STATVFS, 1,
65 [ Define if there is a function named statvfs. (SVR4)])
69 if test $ac_fsusage_space = no; then
70 # DEC Alpha running OSF/1
71 AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
72 AC_CACHE_VAL(fu_cv_sys_stat_statfs3_osf1,
74 #include <sys/param.h>
75 #include <sys/types.h>
76 #include <sys/mount.h>
81 exit (statfs (".", &fsd, sizeof (struct statfs)));
83 fu_cv_sys_stat_statfs3_osf1=yes,
84 fu_cv_sys_stat_statfs3_osf1=no,
85 fu_cv_sys_stat_statfs3_osf1=no)])
86 AC_MSG_RESULT($fu_cv_sys_stat_statfs3_osf1)
87 if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
89 AC_DEFINE(STAT_STATFS3_OSF1, 1,
90 [ Define if statfs takes 3 args. (DEC Alpha running OSF/1)])
94 if test $ac_fsusage_space = no; then
96 AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
97 member (AIX, 4.3BSD)])
98 AC_CACHE_VAL(fu_cv_sys_stat_statfs2_bsize,
100 #ifdef HAVE_SYS_PARAM_H
101 #include <sys/param.h>
103 #ifdef HAVE_SYS_MOUNT_H
104 #include <sys/mount.h>
106 #ifdef HAVE_SYS_VFS_H
113 exit (statfs (".", &fsd));
115 fu_cv_sys_stat_statfs2_bsize=yes,
116 fu_cv_sys_stat_statfs2_bsize=no,
117 fu_cv_sys_stat_statfs2_bsize=no)])
118 AC_MSG_RESULT($fu_cv_sys_stat_statfs2_bsize)
119 if test $fu_cv_sys_stat_statfs2_bsize = yes; then
121 AC_DEFINE(STAT_STATFS2_BSIZE, 1,
122 [ Define if statfs takes 2 args and struct statfs has a field named f_bsize.
123 (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
127 if test $ac_fsusage_space = no; then
129 AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
130 AC_CACHE_VAL(fu_cv_sys_stat_statfs4,
131 [AC_TRY_RUN([#include <sys/types.h>
132 #include <sys/statfs.h>
136 exit (statfs (".", &fsd, sizeof fsd, 0));
138 fu_cv_sys_stat_statfs4=yes,
139 fu_cv_sys_stat_statfs4=no,
140 fu_cv_sys_stat_statfs4=no)])
141 AC_MSG_RESULT($fu_cv_sys_stat_statfs4)
142 if test $fu_cv_sys_stat_statfs4 = yes; then
144 AC_DEFINE(STAT_STATFS4, 1,
145 [ Define if statfs takes 4 args. (SVR3, Dynix, Irix, Dolphin)])
149 if test $ac_fsusage_space = no; then
151 AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
152 member (4.4BSD and NetBSD)])
153 AC_CACHE_VAL(fu_cv_sys_stat_statfs2_fsize,
154 [AC_TRY_RUN([#include <sys/types.h>
155 #ifdef HAVE_SYS_PARAM_H
156 #include <sys/param.h>
158 #ifdef HAVE_SYS_MOUNT_H
159 #include <sys/mount.h>
165 exit (statfs (".", &fsd));
167 fu_cv_sys_stat_statfs2_fsize=yes,
168 fu_cv_sys_stat_statfs2_fsize=no,
169 fu_cv_sys_stat_statfs2_fsize=no)])
170 AC_MSG_RESULT($fu_cv_sys_stat_statfs2_fsize)
171 if test $fu_cv_sys_stat_statfs2_fsize = yes; then
173 AC_DEFINE(STAT_STATFS2_FSIZE, 1,
174 [ Define if statfs takes 2 args and struct statfs has a field named f_fsize.
179 if test $ac_fsusage_space = no; then
181 AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
182 AC_CACHE_VAL(fu_cv_sys_stat_fs_data,
183 [AC_TRY_RUN([#include <sys/types.h>
184 #ifdef HAVE_SYS_PARAM_H
185 #include <sys/param.h>
187 #ifdef HAVE_SYS_MOUNT_H
188 #include <sys/mount.h>
190 #ifdef HAVE_SYS_FS_TYPES_H
191 #include <sys/fs_types.h>
196 /* Ultrix's statfs returns 1 for success,
197 0 for not mounted, -1 for failure. */
198 exit (statfs (".", &fsd) != 1);
200 fu_cv_sys_stat_fs_data=yes,
201 fu_cv_sys_stat_fs_data=no,
202 fu_cv_sys_stat_fs_data=no)])
203 AC_MSG_RESULT($fu_cv_sys_stat_fs_data)
204 if test $fu_cv_sys_stat_fs_data = yes; then
206 AC_DEFINE(STAT_STATFS2_FS_DATA, 1,
207 [ Define if statfs takes 2 args and the second argument has
208 type struct fs_data. (Ultrix)])
212 if test $ac_fsusage_space = no; then
214 AC_TRY_CPP([#include <sys/filsys.h>
216 AC_DEFINE(STAT_READ_FILSYS, 1,
217 [Define if there is no specific function for reading file systems usage
218 information and you have the <sys/filsys.h> header file. (SVR2)])
219 ac_fsusage_space=yes)
222 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
227 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
228 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
229 # enable the work-around code in fsusage.c.
230 AC_DEFUN([gl_STATFS_TRUNCATES],
232 AC_MSG_CHECKING([for statfs that truncates block counts])
233 AC_CACHE_VAL(fu_cv_sys_truncating_statfs,
234 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
235 #if !defined(sun) && !defined(__sun)
236 choke -- this is a workaround for a Sun-specific problem
238 #include <sys/types.h>
239 #include <sys/vfs.h>]],
240 [[struct statfs t; long c = *(t.f_spare);]])],
241 [fu_cv_sys_truncating_statfs=yes],
242 [fu_cv_sys_truncating_statfs=no])])
243 if test $fu_cv_sys_truncating_statfs = yes; then
244 AC_DEFINE(STATFS_TRUNCATES_BLOCK_COUNTS, 1,
245 [Define if the block counts reported by statfs may be truncated to 2GB
246 and the correct values may be stored in the f_spare array.
247 (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
248 SunOS 4.1.1 seems not to be affected.)])
250 AC_MSG_RESULT($fu_cv_sys_truncating_statfs)
254 # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
255 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
257 AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
258 AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h sys/statvfs.h)