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