Code

8b8cbf72c788a70c4fbf7090f9e0f911d5457b6a
[nagiosplug.git] / gl / m4 / fsusage.m4
1 # serial 24
2 # Obtaining file system usage information.
4 # Copyright (C) 1997-1998, 2000-2001, 2003-2009 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_TRY_LINK([#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_TRY_RUN([
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_TRY_RUN([
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_TRY_RUN([#include <sys/types.h>
138 #include <sys/statfs.h>
139   int
140   main ()
141   {
142   struct statfs fsd;
143   return statfs (".", &fsd, sizeof fsd, 0) != 0;
144   }],
145     fu_cv_sys_stat_statfs4=yes,
146     fu_cv_sys_stat_statfs4=no,
147     fu_cv_sys_stat_statfs4=no)])
148   AC_MSG_RESULT([$fu_cv_sys_stat_statfs4])
149   if test $fu_cv_sys_stat_statfs4 = yes; then
150     ac_fsusage_space=yes
151     AC_DEFINE([STAT_STATFS4], [1],
152               [  Define if statfs takes 4 args.  (SVR3, Dynix, Irix, Dolphin)])
153   fi
154 fi
156 if test $ac_fsusage_space = no; then
157 # 4.4BSD and NetBSD
158   AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
159 member (4.4BSD and NetBSD)])
160   AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize],
161   [AC_TRY_RUN([#include <sys/types.h>
162 #ifdef HAVE_SYS_PARAM_H
163 #include <sys/param.h>
164 #endif
165 #ifdef HAVE_SYS_MOUNT_H
166 #include <sys/mount.h>
167 #endif
168   int
169   main ()
170   {
171   struct statfs fsd;
172   fsd.f_fsize = 0;
173   return statfs (".", &fsd) != 0;
174   }],
175   fu_cv_sys_stat_statfs2_fsize=yes,
176   fu_cv_sys_stat_statfs2_fsize=no,
177   fu_cv_sys_stat_statfs2_fsize=no)])
178   AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_fsize])
179   if test $fu_cv_sys_stat_statfs2_fsize = yes; then
180     ac_fsusage_space=yes
181     AC_DEFINE([STAT_STATFS2_FSIZE], [1],
182 [  Define if statfs takes 2 args and struct statfs has a field named f_fsize.
183    (4.4BSD, NetBSD)])
184   fi
185 fi
187 if test $ac_fsusage_space = no; then
188   # Ultrix
189   AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
190   AC_CACHE_VAL([fu_cv_sys_stat_fs_data],
191   [AC_TRY_RUN([#include <sys/types.h>
192 #ifdef HAVE_SYS_PARAM_H
193 #include <sys/param.h>
194 #endif
195 #ifdef HAVE_SYS_MOUNT_H
196 #include <sys/mount.h>
197 #endif
198 #ifdef HAVE_SYS_FS_TYPES_H
199 #include <sys/fs_types.h>
200 #endif
201   int
202   main ()
203   {
204   struct fs_data fsd;
205   /* Ultrix's statfs returns 1 for success,
206      0 for not mounted, -1 for failure.  */
207   return statfs (".", &fsd) != 1;
208   }],
209   fu_cv_sys_stat_fs_data=yes,
210   fu_cv_sys_stat_fs_data=no,
211   fu_cv_sys_stat_fs_data=no)])
212   AC_MSG_RESULT([$fu_cv_sys_stat_fs_data])
213   if test $fu_cv_sys_stat_fs_data = yes; then
214     ac_fsusage_space=yes
215     AC_DEFINE([STAT_STATFS2_FS_DATA], [1],
216 [  Define if statfs takes 2 args and the second argument has
217    type struct fs_data.  (Ultrix)])
218   fi
219 fi
221 if test $ac_fsusage_space = no; then
222   # SVR2
223   AC_TRY_CPP([#include <sys/filsys.h>
224     ],
225     AC_DEFINE([STAT_READ_FILSYS], [1],
226       [Define if there is no specific function for reading file systems usage
227        information and you have the <sys/filsys.h> header file.  (SVR2)])
228     ac_fsusage_space=yes)
229 fi
231 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
233 ])
236 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
237 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
238 # enable the work-around code in fsusage.c.
239 AC_DEFUN([gl_STATFS_TRUNCATES],
241   AC_MSG_CHECKING([for statfs that truncates block counts])
242   AC_CACHE_VAL([fu_cv_sys_truncating_statfs],
243   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
244 #if !defined(sun) && !defined(__sun)
245 choke -- this is a workaround for a Sun-specific problem
246 #endif
247 #include <sys/types.h>
248 #include <sys/vfs.h>]],
249     [[struct statfs t; long c = *(t.f_spare);
250       if (c) return 0;]])],
251     [fu_cv_sys_truncating_statfs=yes],
252     [fu_cv_sys_truncating_statfs=no])])
253   if test $fu_cv_sys_truncating_statfs = yes; then
254     AC_DEFINE([STATFS_TRUNCATES_BLOCK_COUNTS], [1],
255       [Define if the block counts reported by statfs may be truncated to 2GB
256        and the correct values may be stored in the f_spare array.
257        (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
258        SunOS 4.1.1 seems not to be affected.)])
259   fi
260   AC_MSG_RESULT([$fu_cv_sys_truncating_statfs])
261 ])
264 # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
265 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
267   AC_CHECK_HEADERS([dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h])
268   gl_STATFS_TRUNCATES
269 ])