* m4/fsusage.m4 (gl_FILE_SYSTEM_USAGE): Don't consider BeOS statvfs
[gnulib.git] / m4 / fsusage.m4
1 #serial 19
2 # Obtaining file system usage information.
3
4 # Copyright (C) 1997, 1998, 2000, 2001, 2003, 2004, 2005, 2006 Free Software
5 # Foundation, Inc.
6 #
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.
10
11 # Written by Jim Meyering.
12
13 AC_DEFUN([gl_FSUSAGE],
14 [
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, [], [],
18     [AC_INCLUDES_DEFAULT
19      [#if HAVE_SYS_PARAM_H
20        #include <sys/param.h>
21       #endif]])
22   gl_FILE_SYSTEM_USAGE([gl_cv_fs_space=yes], [gl_cv_fs_space=no])
23   if test $gl_cv_fs_space = yes; then
24     AC_LIBOBJ(fsusage)
25     gl_PREREQ_FSUSAGE_EXTRA
26   fi
27 ])
28
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.
32 #
33 # gl_FILE_SYSTEM_USAGE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
34
35 AC_DEFUN([gl_FILE_SYSTEM_USAGE],
36 [
37
38 echo "checking how to get file system space usage..."
39 ac_fsusage_space=no
40
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
48   # SVR4
49   AC_CACHE_CHECK([for statvfs function (SVR4)], fu_cv_sys_stat_statvfs,
50                  [AC_TRY_LINK([#include <sys/types.h>
51 #if defined __GLIBC__ && !defined __BEOS__
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.
55 statvfs in GNU libc on BeOS operates differently: it only makes a system
56 call.
57 #endif
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
63     ac_fsusage_space=yes
64     AC_DEFINE(STAT_STATVFS, 1,
65               [  Define if there is a function named statvfs.  (SVR4)])
66   fi
67 fi
68
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,
73   [AC_TRY_RUN([
74 #include <sys/param.h>
75 #include <sys/types.h>
76 #include <sys/mount.h>
77   int
78   main ()
79   {
80     struct statfs fsd;
81     fsd.f_fsize = 0;
82     return statfs (".", &fsd, sizeof (struct statfs)) != 0;
83   }],
84   fu_cv_sys_stat_statfs3_osf1=yes,
85   fu_cv_sys_stat_statfs3_osf1=no,
86   fu_cv_sys_stat_statfs3_osf1=no)])
87   AC_MSG_RESULT($fu_cv_sys_stat_statfs3_osf1)
88   if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
89     ac_fsusage_space=yes
90     AC_DEFINE(STAT_STATFS3_OSF1, 1,
91               [   Define if  statfs takes 3 args.  (DEC Alpha running OSF/1)])
92   fi
93 fi
94
95 if test $ac_fsusage_space = no; then
96 # AIX
97   AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
98 member (AIX, 4.3BSD)])
99   AC_CACHE_VAL(fu_cv_sys_stat_statfs2_bsize,
100   [AC_TRY_RUN([
101 #ifdef HAVE_SYS_PARAM_H
102 #include <sys/param.h>
103 #endif
104 #ifdef HAVE_SYS_MOUNT_H
105 #include <sys/mount.h>
106 #endif
107 #ifdef HAVE_SYS_VFS_H
108 #include <sys/vfs.h>
109 #endif
110   int
111   main ()
112   {
113   struct statfs fsd;
114   fsd.f_bsize = 0;
115   return statfs (".", &fsd) != 0;
116   }],
117   fu_cv_sys_stat_statfs2_bsize=yes,
118   fu_cv_sys_stat_statfs2_bsize=no,
119   fu_cv_sys_stat_statfs2_bsize=no)])
120   AC_MSG_RESULT($fu_cv_sys_stat_statfs2_bsize)
121   if test $fu_cv_sys_stat_statfs2_bsize = yes; then
122     ac_fsusage_space=yes
123     AC_DEFINE(STAT_STATFS2_BSIZE, 1,
124 [  Define if statfs takes 2 args and struct statfs has a field named f_bsize.
125    (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
126   fi
127 fi
128
129 if test $ac_fsusage_space = no; then
130 # SVR3
131   AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
132   AC_CACHE_VAL(fu_cv_sys_stat_statfs4,
133   [AC_TRY_RUN([#include <sys/types.h>
134 #include <sys/statfs.h>
135   int
136   main ()
137   {
138   struct statfs fsd;
139   return statfs (".", &fsd, sizeof fsd, 0) != 0;
140   }],
141     fu_cv_sys_stat_statfs4=yes,
142     fu_cv_sys_stat_statfs4=no,
143     fu_cv_sys_stat_statfs4=no)])
144   AC_MSG_RESULT($fu_cv_sys_stat_statfs4)
145   if test $fu_cv_sys_stat_statfs4 = yes; then
146     ac_fsusage_space=yes
147     AC_DEFINE(STAT_STATFS4, 1,
148               [  Define if statfs takes 4 args.  (SVR3, Dynix, Irix, Dolphin)])
149   fi
150 fi
151
152 if test $ac_fsusage_space = no; then
153 # 4.4BSD and NetBSD
154   AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
155 member (4.4BSD and NetBSD)])
156   AC_CACHE_VAL(fu_cv_sys_stat_statfs2_fsize,
157   [AC_TRY_RUN([#include <sys/types.h>
158 #ifdef HAVE_SYS_PARAM_H
159 #include <sys/param.h>
160 #endif
161 #ifdef HAVE_SYS_MOUNT_H
162 #include <sys/mount.h>
163 #endif
164   int
165   main ()
166   {
167   struct statfs fsd;
168   fsd.f_fsize = 0;
169   return statfs (".", &fsd) != 0;
170   }],
171   fu_cv_sys_stat_statfs2_fsize=yes,
172   fu_cv_sys_stat_statfs2_fsize=no,
173   fu_cv_sys_stat_statfs2_fsize=no)])
174   AC_MSG_RESULT($fu_cv_sys_stat_statfs2_fsize)
175   if test $fu_cv_sys_stat_statfs2_fsize = yes; then
176     ac_fsusage_space=yes
177     AC_DEFINE(STAT_STATFS2_FSIZE, 1,
178 [  Define if statfs takes 2 args and struct statfs has a field named f_fsize.
179    (4.4BSD, NetBSD)])
180   fi
181 fi
182
183 if test $ac_fsusage_space = no; then
184   # Ultrix
185   AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
186   AC_CACHE_VAL(fu_cv_sys_stat_fs_data,
187   [AC_TRY_RUN([#include <sys/types.h>
188 #ifdef HAVE_SYS_PARAM_H
189 #include <sys/param.h>
190 #endif
191 #ifdef HAVE_SYS_MOUNT_H
192 #include <sys/mount.h>
193 #endif
194 #ifdef HAVE_SYS_FS_TYPES_H
195 #include <sys/fs_types.h>
196 #endif
197   int
198   main ()
199   {
200   struct fs_data fsd;
201   /* Ultrix's statfs returns 1 for success,
202      0 for not mounted, -1 for failure.  */
203   return statfs (".", &fsd) != 1;
204   }],
205   fu_cv_sys_stat_fs_data=yes,
206   fu_cv_sys_stat_fs_data=no,
207   fu_cv_sys_stat_fs_data=no)])
208   AC_MSG_RESULT($fu_cv_sys_stat_fs_data)
209   if test $fu_cv_sys_stat_fs_data = yes; then
210     ac_fsusage_space=yes
211     AC_DEFINE(STAT_STATFS2_FS_DATA, 1,
212 [  Define if statfs takes 2 args and the second argument has
213    type struct fs_data.  (Ultrix)])
214   fi
215 fi
216
217 if test $ac_fsusage_space = no; then
218   # SVR2
219   AC_TRY_CPP([#include <sys/filsys.h>
220     ],
221     AC_DEFINE(STAT_READ_FILSYS, 1,
222       [Define if there is no specific function for reading file systems usage
223        information and you have the <sys/filsys.h> header file.  (SVR2)])
224     ac_fsusage_space=yes)
225 fi
226
227 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
228
229 ])
230
231
232 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
233 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
234 # enable the work-around code in fsusage.c.
235 AC_DEFUN([gl_STATFS_TRUNCATES],
236 [
237   AC_MSG_CHECKING([for statfs that truncates block counts])
238   AC_CACHE_VAL(fu_cv_sys_truncating_statfs,
239   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
240 #if !defined(sun) && !defined(__sun)
241 choke -- this is a workaround for a Sun-specific problem
242 #endif
243 #include <sys/types.h>
244 #include <sys/vfs.h>]],
245     [[struct statfs t; long c = *(t.f_spare);]])],
246     [fu_cv_sys_truncating_statfs=yes],
247     [fu_cv_sys_truncating_statfs=no])])
248   if test $fu_cv_sys_truncating_statfs = yes; then
249     AC_DEFINE(STATFS_TRUNCATES_BLOCK_COUNTS, 1,
250       [Define if the block counts reported by statfs may be truncated to 2GB
251        and the correct values may be stored in the f_spare array.
252        (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
253        SunOS 4.1.1 seems not to be affected.)])
254   fi
255   AC_MSG_RESULT($fu_cv_sys_truncating_statfs)
256 ])
257
258
259 # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
260 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
261 [
262   AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h sys/statvfs.h)
263   gl_STATFS_TRUNCATES
264 ])