in lib:
[gnulib.git] / m4 / fsusage.m4
1 #serial 10
2
3 # From fileutils/configure.in
4
5 AC_DEFUN([gl_FSUSAGE],
6 [
7   AC_CHECK_HEADERS_ONCE(sys/param.h)
8   AC_CHECK_HEADERS(sys/mount.h sys/vfs.h sys/fs_types.h)
9   jm_FILE_SYSTEM_USAGE([gl_cv_fs_space=yes], [gl_cv_fs_space=no])
10   if test $gl_cv_fs_space = yes; then
11     AC_LIBOBJ(fsusage)
12     gl_PREREQ_FSUSAGE_EXTRA
13   fi
14 ])
15
16 # Try to determine how a program can obtain filesystem usage information.
17 # If successful, define the appropriate symbol (see fsusage.c) and
18 # execute ACTION-IF-FOUND.  Otherwise, execute ACTION-IF-NOT-FOUND.
19 #
20 # jm_FILE_SYSTEM_USAGE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
21
22 AC_DEFUN([jm_FILE_SYSTEM_USAGE],
23 [
24
25 echo "checking how to get filesystem space usage..."
26 ac_fsusage_space=no
27
28 # Perform only the link test since it seems there are no variants of the
29 # statvfs function.  This check is more than just AC_CHECK_FUNCS(statvfs)
30 # because that got a false positive on SCO OSR5.  Adding the declaration
31 # of a `struct statvfs' causes this test to fail (as it should) on such
32 # systems.  That system is reported to work fine with STAT_STATFS4 which
33 # is what it gets when this test fails.
34 if test $ac_fsusage_space = no; then
35   # SVR4
36   AC_CACHE_CHECK([for statvfs function (SVR4)], fu_cv_sys_stat_statvfs,
37                  [AC_TRY_LINK([#include <sys/types.h>
38 #include <sys/statvfs.h>],
39                               [struct statvfs fsd; statvfs (0, &fsd);],
40                               fu_cv_sys_stat_statvfs=yes,
41                               fu_cv_sys_stat_statvfs=no)])
42   if test $fu_cv_sys_stat_statvfs = yes; then
43     ac_fsusage_space=yes
44     AC_DEFINE(STAT_STATVFS, 1,
45               [  Define if there is a function named statvfs.  (SVR4)])
46   fi
47 fi
48
49 if test $ac_fsusage_space = no; then
50   # DEC Alpha running OSF/1
51   AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
52   AC_CACHE_VAL(fu_cv_sys_stat_statfs3_osf1,
53   [AC_TRY_RUN([
54 #include <sys/param.h>
55 #include <sys/types.h>
56 #include <sys/mount.h>
57   main ()
58   {
59     struct statfs fsd;
60     fsd.f_fsize = 0;
61     exit (statfs (".", &fsd, sizeof (struct statfs)));
62   }],
63   fu_cv_sys_stat_statfs3_osf1=yes,
64   fu_cv_sys_stat_statfs3_osf1=no,
65   fu_cv_sys_stat_statfs3_osf1=no)])
66   AC_MSG_RESULT($fu_cv_sys_stat_statfs3_osf1)
67   if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
68     ac_fsusage_space=yes
69     AC_DEFINE(STAT_STATFS3_OSF1, 1,
70               [   Define if  statfs takes 3 args.  (DEC Alpha running OSF/1)])
71   fi
72 fi
73
74 if test $ac_fsusage_space = no; then
75 # AIX
76   AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
77 member (AIX, 4.3BSD)])
78   AC_CACHE_VAL(fu_cv_sys_stat_statfs2_bsize,
79   [AC_TRY_RUN([
80 #ifdef HAVE_SYS_PARAM_H
81 #include <sys/param.h>
82 #endif
83 #ifdef HAVE_SYS_MOUNT_H
84 #include <sys/mount.h>
85 #endif
86 #ifdef HAVE_SYS_VFS_H
87 #include <sys/vfs.h>
88 #endif
89   main ()
90   {
91   struct statfs fsd;
92   fsd.f_bsize = 0;
93   exit (statfs (".", &fsd));
94   }],
95   fu_cv_sys_stat_statfs2_bsize=yes,
96   fu_cv_sys_stat_statfs2_bsize=no,
97   fu_cv_sys_stat_statfs2_bsize=no)])
98   AC_MSG_RESULT($fu_cv_sys_stat_statfs2_bsize)
99   if test $fu_cv_sys_stat_statfs2_bsize = yes; then
100     ac_fsusage_space=yes
101     AC_DEFINE(STAT_STATFS2_BSIZE, 1,
102 [  Define if statfs takes 2 args and struct statfs has a field named f_bsize.
103    (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
104   fi
105 fi
106
107 if test $ac_fsusage_space = no; then
108 # SVR3
109   AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
110   AC_CACHE_VAL(fu_cv_sys_stat_statfs4,
111   [AC_TRY_RUN([#include <sys/types.h>
112 #include <sys/statfs.h>
113   main ()
114   {
115   struct statfs fsd;
116   exit (statfs (".", &fsd, sizeof fsd, 0));
117   }],
118     fu_cv_sys_stat_statfs4=yes,
119     fu_cv_sys_stat_statfs4=no,
120     fu_cv_sys_stat_statfs4=no)])
121   AC_MSG_RESULT($fu_cv_sys_stat_statfs4)
122   if test $fu_cv_sys_stat_statfs4 = yes; then
123     ac_fsusage_space=yes
124     AC_DEFINE(STAT_STATFS4, 1,
125               [  Define if statfs takes 4 args.  (SVR3, Dynix, Irix, Dolphin)])
126   fi
127 fi
128
129 if test $ac_fsusage_space = no; then
130 # 4.4BSD and NetBSD
131   AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
132 member (4.4BSD and NetBSD)])
133   AC_CACHE_VAL(fu_cv_sys_stat_statfs2_fsize,
134   [AC_TRY_RUN([#include <sys/types.h>
135 #ifdef HAVE_SYS_PARAM_H
136 #include <sys/param.h>
137 #endif
138 #ifdef HAVE_SYS_MOUNT_H
139 #include <sys/mount.h>
140 #endif
141   main ()
142   {
143   struct statfs fsd;
144   fsd.f_fsize = 0;
145   exit (statfs (".", &fsd));
146   }],
147   fu_cv_sys_stat_statfs2_fsize=yes,
148   fu_cv_sys_stat_statfs2_fsize=no,
149   fu_cv_sys_stat_statfs2_fsize=no)])
150   AC_MSG_RESULT($fu_cv_sys_stat_statfs2_fsize)
151   if test $fu_cv_sys_stat_statfs2_fsize = yes; then
152     ac_fsusage_space=yes
153     AC_DEFINE(STAT_STATFS2_FSIZE, 1,
154 [  Define if statfs takes 2 args and struct statfs has a field named f_fsize.
155    (4.4BSD, NetBSD)])
156   fi
157 fi
158
159 if test $ac_fsusage_space = no; then
160   # Ultrix
161   AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
162   AC_CACHE_VAL(fu_cv_sys_stat_fs_data,
163   [AC_TRY_RUN([#include <sys/types.h>
164 #ifdef HAVE_SYS_PARAM_H
165 #include <sys/param.h>
166 #endif
167 #ifdef HAVE_SYS_MOUNT_H
168 #include <sys/mount.h>
169 #endif
170 #ifdef HAVE_SYS_FS_TYPES_H
171 #include <sys/fs_types.h>
172 #endif
173   main ()
174   {
175   struct fs_data fsd;
176   /* Ultrix's statfs returns 1 for success,
177      0 for not mounted, -1 for failure.  */
178   exit (statfs (".", &fsd) != 1);
179   }],
180   fu_cv_sys_stat_fs_data=yes,
181   fu_cv_sys_stat_fs_data=no,
182   fu_cv_sys_stat_fs_data=no)])
183   AC_MSG_RESULT($fu_cv_sys_stat_fs_data)
184   if test $fu_cv_sys_stat_fs_data = yes; then
185     ac_fsusage_space=yes
186     AC_DEFINE(STAT_STATFS2_FS_DATA, 1,
187 [  Define if statfs takes 2 args and the second argument has
188    type struct fs_data.  (Ultrix)])
189   fi
190 fi
191
192 if test $ac_fsusage_space = no; then
193   # SVR2
194   AC_TRY_CPP([#include <sys/filsys.h>
195     ],
196     AC_DEFINE(STAT_READ_FILSYS, 1,
197       [Define if there is no specific function for reading filesystems usage
198        information and you have the <sys/filsys.h> header file.  (SVR2)])
199     ac_fsusage_space=yes)
200 fi
201
202 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
203
204 ])
205
206
207 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
208 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
209 # enable the work-around code in fsusage.c.
210 AC_DEFUN([jm_STATFS_TRUNCATES],
211 [
212   AC_MSG_CHECKING([for statfs that truncates block counts])
213   AC_CACHE_VAL(fu_cv_sys_truncating_statfs,
214   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
215 #if !defined(sun) && !defined(__sun)
216 choke -- this is a workaround for a Sun-specific problem
217 #endif
218 #include <sys/types.h>
219 #include <sys/vfs.h>]],
220     [[struct statfs t; long c = *(t.f_spare);]])],
221     [fu_cv_sys_truncating_statfs=yes],
222     [fu_cv_sys_truncating_statfs=no])])
223   if test $fu_cv_sys_truncating_statfs = yes; then
224     AC_DEFINE(STATFS_TRUNCATES_BLOCK_COUNTS, 1,
225       [Define if the block counts reported by statfs may be truncated to 2GB
226        and the correct values may be stored in the f_spare array.
227        (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
228        SunOS 4.1.1 seems not to be affected.)])
229   fi
230   AC_MSG_RESULT($fu_cv_sys_truncating_statfs)
231 ])
232
233
234 # Prerequisites of lib/fsusage.c not done by jm_FILE_SYSTEM_USAGE.
235 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
236 [
237   AC_REQUIRE([jm_AC_TYPE_UINTMAX_T])
238   AC_CHECK_HEADERS_ONCE(fcntl.h)
239   AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h sys/statvfs.h)
240   jm_STATFS_TRUNCATES
241 ])