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