Add and change modules to make it easier for coreutils to use
[gnulib.git] / m4 / fsusage.m4
1 #serial 18
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 #ifdef __GLIBC__
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 #endif
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
61     ac_fsusage_space=yes
62     AC_DEFINE(STAT_STATVFS, 1,
63               [  Define if there is a function named statvfs.  (SVR4)])
64   fi
65 fi
66
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,
71   [AC_TRY_RUN([
72 #include <sys/param.h>
73 #include <sys/types.h>
74 #include <sys/mount.h>
75   int
76   main ()
77   {
78     struct statfs fsd;
79     fsd.f_fsize = 0;
80     return statfs (".", &fsd, sizeof (struct statfs)) != 0;
81   }],
82   fu_cv_sys_stat_statfs3_osf1=yes,
83   fu_cv_sys_stat_statfs3_osf1=no,
84   fu_cv_sys_stat_statfs3_osf1=no)])
85   AC_MSG_RESULT($fu_cv_sys_stat_statfs3_osf1)
86   if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
87     ac_fsusage_space=yes
88     AC_DEFINE(STAT_STATFS3_OSF1, 1,
89               [   Define if  statfs takes 3 args.  (DEC Alpha running OSF/1)])
90   fi
91 fi
92
93 if test $ac_fsusage_space = no; then
94 # AIX
95   AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
96 member (AIX, 4.3BSD)])
97   AC_CACHE_VAL(fu_cv_sys_stat_statfs2_bsize,
98   [AC_TRY_RUN([
99 #ifdef HAVE_SYS_PARAM_H
100 #include <sys/param.h>
101 #endif
102 #ifdef HAVE_SYS_MOUNT_H
103 #include <sys/mount.h>
104 #endif
105 #ifdef HAVE_SYS_VFS_H
106 #include <sys/vfs.h>
107 #endif
108   int
109   main ()
110   {
111   struct statfs fsd;
112   fsd.f_bsize = 0;
113   return statfs (".", &fsd) != 0;
114   }],
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
120     ac_fsusage_space=yes
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)])
124   fi
125 fi
126
127 if test $ac_fsusage_space = no; then
128 # SVR3
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>
133   int
134   main ()
135   {
136   struct statfs fsd;
137   return statfs (".", &fsd, sizeof fsd, 0) != 0;
138   }],
139     fu_cv_sys_stat_statfs4=yes,
140     fu_cv_sys_stat_statfs4=no,
141     fu_cv_sys_stat_statfs4=no)])
142   AC_MSG_RESULT($fu_cv_sys_stat_statfs4)
143   if test $fu_cv_sys_stat_statfs4 = yes; then
144     ac_fsusage_space=yes
145     AC_DEFINE(STAT_STATFS4, 1,
146               [  Define if statfs takes 4 args.  (SVR3, Dynix, Irix, Dolphin)])
147   fi
148 fi
149
150 if test $ac_fsusage_space = no; then
151 # 4.4BSD and NetBSD
152   AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
153 member (4.4BSD and NetBSD)])
154   AC_CACHE_VAL(fu_cv_sys_stat_statfs2_fsize,
155   [AC_TRY_RUN([#include <sys/types.h>
156 #ifdef HAVE_SYS_PARAM_H
157 #include <sys/param.h>
158 #endif
159 #ifdef HAVE_SYS_MOUNT_H
160 #include <sys/mount.h>
161 #endif
162   int
163   main ()
164   {
165   struct statfs fsd;
166   fsd.f_fsize = 0;
167   return statfs (".", &fsd) != 0;
168   }],
169   fu_cv_sys_stat_statfs2_fsize=yes,
170   fu_cv_sys_stat_statfs2_fsize=no,
171   fu_cv_sys_stat_statfs2_fsize=no)])
172   AC_MSG_RESULT($fu_cv_sys_stat_statfs2_fsize)
173   if test $fu_cv_sys_stat_statfs2_fsize = yes; then
174     ac_fsusage_space=yes
175     AC_DEFINE(STAT_STATFS2_FSIZE, 1,
176 [  Define if statfs takes 2 args and struct statfs has a field named f_fsize.
177    (4.4BSD, NetBSD)])
178   fi
179 fi
180
181 if test $ac_fsusage_space = no; then
182   # Ultrix
183   AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
184   AC_CACHE_VAL(fu_cv_sys_stat_fs_data,
185   [AC_TRY_RUN([#include <sys/types.h>
186 #ifdef HAVE_SYS_PARAM_H
187 #include <sys/param.h>
188 #endif
189 #ifdef HAVE_SYS_MOUNT_H
190 #include <sys/mount.h>
191 #endif
192 #ifdef HAVE_SYS_FS_TYPES_H
193 #include <sys/fs_types.h>
194 #endif
195   int
196   main ()
197   {
198   struct fs_data fsd;
199   /* Ultrix's statfs returns 1 for success,
200      0 for not mounted, -1 for failure.  */
201   return statfs (".", &fsd) != 1;
202   }],
203   fu_cv_sys_stat_fs_data=yes,
204   fu_cv_sys_stat_fs_data=no,
205   fu_cv_sys_stat_fs_data=no)])
206   AC_MSG_RESULT($fu_cv_sys_stat_fs_data)
207   if test $fu_cv_sys_stat_fs_data = yes; then
208     ac_fsusage_space=yes
209     AC_DEFINE(STAT_STATFS2_FS_DATA, 1,
210 [  Define if statfs takes 2 args and the second argument has
211    type struct fs_data.  (Ultrix)])
212   fi
213 fi
214
215 if test $ac_fsusage_space = no; then
216   # SVR2
217   AC_TRY_CPP([#include <sys/filsys.h>
218     ],
219     AC_DEFINE(STAT_READ_FILSYS, 1,
220       [Define if there is no specific function for reading file systems usage
221        information and you have the <sys/filsys.h> header file.  (SVR2)])
222     ac_fsusage_space=yes)
223 fi
224
225 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
226
227 ])
228
229
230 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
231 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
232 # enable the work-around code in fsusage.c.
233 AC_DEFUN([gl_STATFS_TRUNCATES],
234 [
235   AC_MSG_CHECKING([for statfs that truncates block counts])
236   AC_CACHE_VAL(fu_cv_sys_truncating_statfs,
237   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
238 #if !defined(sun) && !defined(__sun)
239 choke -- this is a workaround for a Sun-specific problem
240 #endif
241 #include <sys/types.h>
242 #include <sys/vfs.h>]],
243     [[struct statfs t; long c = *(t.f_spare);]])],
244     [fu_cv_sys_truncating_statfs=yes],
245     [fu_cv_sys_truncating_statfs=no])])
246   if test $fu_cv_sys_truncating_statfs = yes; then
247     AC_DEFINE(STATFS_TRUNCATES_BLOCK_COUNTS, 1,
248       [Define if the block counts reported by statfs may be truncated to 2GB
249        and the correct values may be stored in the f_spare array.
250        (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
251        SunOS 4.1.1 seems not to be affected.)])
252   fi
253   AC_MSG_RESULT($fu_cv_sys_truncating_statfs)
254 ])
255
256
257 # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
258 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
259 [
260   AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h sys/statvfs.h)
261   gl_STATFS_TRUNCATES
262 ])