Code

Sync with the latest Gnulib code (177f525)
[nagiosplug.git] / gl / m4 / fsusage.m4
1 # serial 25
2 # Obtaining file system usage information.
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.
10 # Written by Jim Meyering.
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 ])
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]])
34 AC_DEFUN([gl_FILE_SYSTEM_USAGE],
35 [
37 AC_MSG_NOTICE([checking how to get file system space usage])
38 ac_fsusage_space=no
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   # SVR4
48   AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs],
49                  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
50 #if defined __GLIBC__ && defined __linux__
51 Do not use statvfs on systems with GNU libc on Linux, because that function
52 stats all preceding entries in /proc/mounts, and that makes df hang if even
53 one of the corresponding file systems is hard-mounted, but not available.
54 statvfs in GNU libc on Hurd, BeOS, Haiku operates differently: it only makes
55 a system call.
56 #endif
58 #ifdef __osf__
59 "Do not use Tru64's statvfs implementation"
60 #endif
62 #include <sys/statvfs.h>]],
63                                     [[struct statvfs fsd; statvfs (0, &fsd);]])],
64                                  [fu_cv_sys_stat_statvfs=yes],
65                                  [fu_cv_sys_stat_statvfs=no])])
66   if test $fu_cv_sys_stat_statvfs = yes; then
67     ac_fsusage_space=yes
68     AC_DEFINE([STAT_STATVFS], [1],
69               [  Define if there is a function named statvfs.  (SVR4)])
70   fi
71 fi
73 if test $ac_fsusage_space = no; then
74   # DEC Alpha running OSF/1
75   AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
76   AC_CACHE_VAL([fu_cv_sys_stat_statfs3_osf1],
77   [AC_RUN_IFELSE([AC_LANG_SOURCE([[
78 #include <sys/param.h>
79 #include <sys/types.h>
80 #include <sys/mount.h>
81   int
82   main ()
83   {
84     struct statfs fsd;
85     fsd.f_fsize = 0;
86     return statfs (".", &fsd, sizeof (struct statfs)) != 0;
87   }]])],
88     [fu_cv_sys_stat_statfs3_osf1=yes],
89     [fu_cv_sys_stat_statfs3_osf1=no],
90     [fu_cv_sys_stat_statfs3_osf1=no])])
91   AC_MSG_RESULT([$fu_cv_sys_stat_statfs3_osf1])
92   if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
93     ac_fsusage_space=yes
94     AC_DEFINE([STAT_STATFS3_OSF1], [1],
95               [   Define if  statfs takes 3 args.  (DEC Alpha running OSF/1)])
96   fi
97 fi
99 if test $ac_fsusage_space = no; then
100 # AIX
101   AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
102 member (AIX, 4.3BSD)])
103   AC_CACHE_VAL([fu_cv_sys_stat_statfs2_bsize],
104   [AC_RUN_IFELSE([AC_LANG_SOURCE([[
105 #ifdef HAVE_SYS_PARAM_H
106 #include <sys/param.h>
107 #endif
108 #ifdef HAVE_SYS_MOUNT_H
109 #include <sys/mount.h>
110 #endif
111 #ifdef HAVE_SYS_VFS_H
112 #include <sys/vfs.h>
113 #endif
114   int
115   main ()
116   {
117   struct statfs fsd;
118   fsd.f_bsize = 0;
119   return statfs (".", &fsd) != 0;
120   }]])],
121     [fu_cv_sys_stat_statfs2_bsize=yes],
122     [fu_cv_sys_stat_statfs2_bsize=no],
123     [fu_cv_sys_stat_statfs2_bsize=no])])
124   AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_bsize])
125   if test $fu_cv_sys_stat_statfs2_bsize = yes; then
126     ac_fsusage_space=yes
127     AC_DEFINE([STAT_STATFS2_BSIZE], [1],
128 [  Define if statfs takes 2 args and struct statfs has a field named f_bsize.
129    (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
130   fi
131 fi
133 if test $ac_fsusage_space = no; then
134 # SVR3
135   AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
136   AC_CACHE_VAL([fu_cv_sys_stat_statfs4],
137   [AC_RUN_IFELSE([AC_LANG_SOURCE([[
138 #include <sys/types.h>
139 #include <sys/statfs.h>
140   int
141   main ()
142   {
143   struct statfs fsd;
144   return statfs (".", &fsd, sizeof fsd, 0) != 0;
145   }]])],
146     [fu_cv_sys_stat_statfs4=yes],
147     [fu_cv_sys_stat_statfs4=no],
148     [fu_cv_sys_stat_statfs4=no])])
149   AC_MSG_RESULT([$fu_cv_sys_stat_statfs4])
150   if test $fu_cv_sys_stat_statfs4 = yes; then
151     ac_fsusage_space=yes
152     AC_DEFINE([STAT_STATFS4], [1],
153               [  Define if statfs takes 4 args.  (SVR3, Dynix, Irix, Dolphin)])
154   fi
155 fi
157 if test $ac_fsusage_space = no; then
158 # 4.4BSD and NetBSD
159   AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
160 member (4.4BSD and NetBSD)])
161   AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize],
162   [AC_RUN_IFELSE([AC_LANG_SOURCE([[
163 #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   int
171   main ()
172   {
173   struct statfs fsd;
174   fsd.f_fsize = 0;
175   return statfs (".", &fsd) != 0;
176   }]])],
177     [fu_cv_sys_stat_statfs2_fsize=yes],
178     [fu_cv_sys_stat_statfs2_fsize=no],
179     [fu_cv_sys_stat_statfs2_fsize=no])])
180   AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_fsize])
181   if test $fu_cv_sys_stat_statfs2_fsize = yes; then
182     ac_fsusage_space=yes
183     AC_DEFINE([STAT_STATFS2_FSIZE], [1],
184 [  Define if statfs takes 2 args and struct statfs has a field named f_fsize.
185    (4.4BSD, NetBSD)])
186   fi
187 fi
189 if test $ac_fsusage_space = no; then
190   # Ultrix
191   AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
192   AC_CACHE_VAL([fu_cv_sys_stat_fs_data],
193   [AC_RUN_IFELSE([AC_LANG_SOURCE([[
194 #include <sys/types.h>
195 #ifdef HAVE_SYS_PARAM_H
196 #include <sys/param.h>
197 #endif
198 #ifdef HAVE_SYS_MOUNT_H
199 #include <sys/mount.h>
200 #endif
201 #ifdef HAVE_SYS_FS_TYPES_H
202 #include <sys/fs_types.h>
203 #endif
204   int
205   main ()
206   {
207   struct fs_data fsd;
208   /* Ultrix's statfs returns 1 for success,
209      0 for not mounted, -1 for failure.  */
210   return statfs (".", &fsd) != 1;
211   }]])],
212     [fu_cv_sys_stat_fs_data=yes],
213     [fu_cv_sys_stat_fs_data=no],
214     [fu_cv_sys_stat_fs_data=no])])
215   AC_MSG_RESULT([$fu_cv_sys_stat_fs_data])
216   if test $fu_cv_sys_stat_fs_data = yes; then
217     ac_fsusage_space=yes
218     AC_DEFINE([STAT_STATFS2_FS_DATA], [1],
219 [  Define if statfs takes 2 args and the second argument has
220    type struct fs_data.  (Ultrix)])
221   fi
222 fi
224 if test $ac_fsusage_space = no; then
225   # SVR2
226   AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <sys/filsys.h>
227         ]])],
228     [AC_DEFINE([STAT_READ_FILSYS], [1],
229       [Define if there is no specific function for reading file systems usage
230        information and you have the <sys/filsys.h> header file.  (SVR2)])
231      ac_fsusage_space=yes])
232 fi
234 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
236 ])
239 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
240 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
241 # enable the work-around code in fsusage.c.
242 AC_DEFUN([gl_STATFS_TRUNCATES],
244   AC_MSG_CHECKING([for statfs that truncates block counts])
245   AC_CACHE_VAL([fu_cv_sys_truncating_statfs],
246   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
247 #if !defined(sun) && !defined(__sun)
248 choke -- this is a workaround for a Sun-specific problem
249 #endif
250 #include <sys/types.h>
251 #include <sys/vfs.h>]],
252       [[struct statfs t; long c = *(t.f_spare);
253         if (c) return 0;]])],
254     [fu_cv_sys_truncating_statfs=yes],
255     [fu_cv_sys_truncating_statfs=no])])
256   if test $fu_cv_sys_truncating_statfs = yes; then
257     AC_DEFINE([STATFS_TRUNCATES_BLOCK_COUNTS], [1],
258       [Define if the block counts reported by statfs may be truncated to 2GB
259        and the correct values may be stored in the f_spare array.
260        (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
261        SunOS 4.1.1 seems not to be affected.)])
262   fi
263   AC_MSG_RESULT([$fu_cv_sys_truncating_statfs])
264 ])
267 # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
268 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
270   AC_CHECK_HEADERS([dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h])
271   gl_STATFS_TRUNCATES
272 ])