Ticket #2762: mc ignores second directory argument.
[midnight-commander.git] / m4.include / fsusage.m4
blob8e9e2cb5be21c1bfd701ba2bf8fe0af9df14eaf9
1 # serial 29
2 # Obtaining file system usage information.
4 # Copyright (C) 1997-1998, 2000-2001, 2003-2011 Free Software Foundation, Inc.
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],
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])
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.
28 # gl_FILE_SYSTEM_USAGE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
30 AC_DEFUN([gl_FILE_SYSTEM_USAGE],
32 dnl Enable large-file support. This has the effect of changing the size
33 dnl of field f_blocks in 'struct statvfs' from 32 bit to 64 bit on
34 dnl glibc/Hurd, HP-UX 11, Solaris (32-bit mode). It also changes the size
35 dnl of field f_blocks in 'struct statfs' from 32 bit to 64 bit on
36 dnl MacOS X >= 10.5 (32-bit mode).
37 AC_REQUIRE([AC_SYS_LARGEFILE])
39 AC_MSG_NOTICE([checking how to get file system space usage])
40 ac_fsusage_space=no
42 # Perform only the link test since it seems there are no variants of the
43 # statvfs function.  This check is more than just AC_CHECK_FUNCS([statvfs])
44 # because that got a false positive on SCO OSR5.  Adding the declaration
45 # of a `struct statvfs' causes this test to fail (as it should) on such
46 # systems.  That system is reported to work fine with STAT_STATFS4 which
47 # is what it gets when this test fails.
48 if test $ac_fsusage_space = no; then
49   # glibc/{Hurd,kFreeBSD}, FreeBSD >= 5.0, NetBSD >= 3.0,
50   # OpenBSD >= 4.4, AIX, HP-UX, IRIX, Solaris, Cygwin, Interix, BeOS.
51   AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs],
52                  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
53 #if (defined __GLIBC__ || defined __UCLIBC__) && defined __linux__
54 Do not use statvfs on systems with GNU libc on Linux, because that function
55 stats all preceding entries in /proc/mounts, and that makes df hang if even
56 one of the corresponding file systems is hard-mounted, but not available.
57 statvfs in GNU libc on Hurd, BeOS, Haiku operates differently: it only makes
58 a system call.
59 #endif
61 #ifdef __osf__
62 "Do not use Tru64's statvfs implementation"
63 #endif
65 #include <sys/statvfs.h>
67 struct statvfs fsd;
69 #if defined __APPLE__ && defined __MACH__
70 #include <limits.h>
71 /* On MacOS X >= 10.5, f_blocks in 'struct statvfs' is a 32-bit quantity;
72    that commonly limits file systems to 4 TiB.  Whereas f_blocks in
73    'struct statfs' is a 64-bit type, thanks to the large-file support
74    that was enabled above.  In this case, don't use statvfs(); use statfs()
75    instead.  */
76 int check_f_blocks_size[sizeof fsd.f_blocks * CHAR_BIT <= 32 ? -1 : 1];
77 #endif
78 ]],
79                                     [[statvfs (0, &fsd);]])],
80                                  [fu_cv_sys_stat_statvfs=yes],
81                                  [fu_cv_sys_stat_statvfs=no])])
82   if test $fu_cv_sys_stat_statvfs = yes; then
83     ac_fsusage_space=yes
84     # AIX >= 5.2 has statvfs64 that has a wider f_blocks field than statvfs.
85     # glibc, HP-UX, IRIX, Solaris have statvfs64 as well, but on these systems
86     # statvfs with large-file support is already equivalent to statvfs64.
87     AC_CACHE_CHECK([whether to use statvfs64],
88       [fu_cv_sys_stat_statvfs64],
89       [AC_LINK_IFELSE(
90          [AC_LANG_PROGRAM(
91             [[#include <sys/types.h>
92               #include <sys/statvfs.h>
93               struct statvfs64 fsd;
94               int check_f_blocks_larger_in_statvfs64
95                 [sizeof (((struct statvfs64 *) 0)->f_blocks)
96                  > sizeof (((struct statvfs *) 0)->f_blocks)
97                  ? 1 : -1];
98             ]],
99             [[statvfs64 (0, &fsd);]])],
100          [fu_cv_sys_stat_statvfs64=yes],
101          [fu_cv_sys_stat_statvfs64=no])
102       ])
103     if test $fu_cv_sys_stat_statvfs64 = yes; then
104       AC_DEFINE([STAT_STATVFS64], [1],
105                 [  Define if statvfs64 should be preferred over statvfs.])
106     else
107       AC_DEFINE([STAT_STATVFS], [1],
108                 [  Define if there is a function named statvfs.  (SVR4)])
109     fi
110   fi
113 if test $ac_fsusage_space = no; then
114   # DEC Alpha running OSF/1
115   AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
116   AC_CACHE_VAL([fu_cv_sys_stat_statfs3_osf1],
117   [AC_RUN_IFELSE([AC_LANG_SOURCE([[
118 #include <sys/param.h>
119 #include <sys/types.h>
120 #include <sys/mount.h>
121   int
122   main ()
123   {
124     struct statfs fsd;
125     fsd.f_fsize = 0;
126     return statfs (".", &fsd, sizeof (struct statfs)) != 0;
127   }]])],
128     [fu_cv_sys_stat_statfs3_osf1=yes],
129     [fu_cv_sys_stat_statfs3_osf1=no],
130     [fu_cv_sys_stat_statfs3_osf1=no])])
131   AC_MSG_RESULT([$fu_cv_sys_stat_statfs3_osf1])
132   if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
133     ac_fsusage_space=yes
134     AC_DEFINE([STAT_STATFS3_OSF1], [1],
135               [   Define if  statfs takes 3 args.  (DEC Alpha running OSF/1)])
136   fi
139 if test $ac_fsusage_space = no; then
140   # glibc/Linux, MacOS X, FreeBSD < 5.0, NetBSD < 3.0, OpenBSD < 4.4.
141   # (glibc/{Hurd,kFreeBSD}, FreeBSD >= 5.0, NetBSD >= 3.0,
142   # OpenBSD >= 4.4, AIX, HP-UX, OSF/1, Cygwin already handled above.)
143   # (On IRIX you need to include <sys/statfs.h>, not only <sys/mount.h> and
144   # <sys/vfs.h>.)
145   # (On Solaris, statfs has 4 arguments.)
146   AC_MSG_CHECKING([for two-argument statfs with statfs.f_bsize dnl
147 member (AIX, 4.3BSD)])
148   AC_CACHE_VAL([fu_cv_sys_stat_statfs2_bsize],
149   [AC_RUN_IFELSE([AC_LANG_SOURCE([[
150 #ifdef HAVE_SYS_PARAM_H
151 #include <sys/param.h>
152 #endif
153 #ifdef HAVE_SYS_MOUNT_H
154 #include <sys/mount.h>
155 #endif
156 #ifdef HAVE_SYS_VFS_H
157 #include <sys/vfs.h>
158 #endif
159   int
160   main ()
161   {
162   struct statfs fsd;
163   fsd.f_bsize = 0;
164   return statfs (".", &fsd) != 0;
165   }]])],
166     [fu_cv_sys_stat_statfs2_bsize=yes],
167     [fu_cv_sys_stat_statfs2_bsize=no],
168     [fu_cv_sys_stat_statfs2_bsize=no])])
169   AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_bsize])
170   if test $fu_cv_sys_stat_statfs2_bsize = yes; then
171     ac_fsusage_space=yes
172     AC_DEFINE([STAT_STATFS2_BSIZE], [1],
173 [  Define if statfs takes 2 args and struct statfs has a field named f_bsize.
174    (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
175   fi
178 if test $ac_fsusage_space = no; then
179   # SVR3
180   # (Solaris already handled above.)
181   AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
182   AC_CACHE_VAL([fu_cv_sys_stat_statfs4],
183   [AC_RUN_IFELSE([AC_LANG_SOURCE([[
184 #include <sys/types.h>
185 #include <sys/statfs.h>
186   int
187   main ()
188   {
189   struct statfs fsd;
190   return statfs (".", &fsd, sizeof fsd, 0) != 0;
191   }]])],
192     [fu_cv_sys_stat_statfs4=yes],
193     [fu_cv_sys_stat_statfs4=no],
194     [fu_cv_sys_stat_statfs4=no])])
195   AC_MSG_RESULT([$fu_cv_sys_stat_statfs4])
196   if test $fu_cv_sys_stat_statfs4 = yes; then
197     ac_fsusage_space=yes
198     AC_DEFINE([STAT_STATFS4], [1],
199       [  Define if statfs takes 4 args.  (SVR3, Dynix, old Irix, old AIX, Dolphin)])
200   fi
203 if test $ac_fsusage_space = no; then
204   # 4.4BSD and older NetBSD
205   # (OSF/1 already handled above.)
206   # (On AIX, you need to include <sys/statfs.h>, not only <sys/mount.h>.)
207   # (On Solaris, statfs has 4 arguments and 'struct statfs' is not declared in
208   # <sys/mount.h>.)
209   AC_MSG_CHECKING([for two-argument statfs with statfs.f_fsize dnl
210 member (4.4BSD and NetBSD)])
211   AC_CACHE_VAL([fu_cv_sys_stat_statfs2_fsize],
212   [AC_RUN_IFELSE([AC_LANG_SOURCE([[
213 #include <sys/types.h>
214 #ifdef HAVE_SYS_PARAM_H
215 #include <sys/param.h>
216 #endif
217 #ifdef HAVE_SYS_MOUNT_H
218 #include <sys/mount.h>
219 #endif
220   int
221   main ()
222   {
223   struct statfs fsd;
224   fsd.f_fsize = 0;
225   return statfs (".", &fsd) != 0;
226   }]])],
227     [fu_cv_sys_stat_statfs2_fsize=yes],
228     [fu_cv_sys_stat_statfs2_fsize=no],
229     [fu_cv_sys_stat_statfs2_fsize=no])])
230   AC_MSG_RESULT([$fu_cv_sys_stat_statfs2_fsize])
231   if test $fu_cv_sys_stat_statfs2_fsize = yes; then
232     ac_fsusage_space=yes
233     AC_DEFINE([STAT_STATFS2_FSIZE], [1],
234 [  Define if statfs takes 2 args and struct statfs has a field named f_fsize.
235    (4.4BSD, NetBSD)])
236   fi
239 if test $ac_fsusage_space = no; then
240   # Ultrix
241   AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
242   AC_CACHE_VAL([fu_cv_sys_stat_fs_data],
243   [AC_RUN_IFELSE([AC_LANG_SOURCE([[
244 #include <sys/types.h>
245 #ifdef HAVE_SYS_PARAM_H
246 #include <sys/param.h>
247 #endif
248 #ifdef HAVE_SYS_MOUNT_H
249 #include <sys/mount.h>
250 #endif
251 #ifdef HAVE_SYS_FS_TYPES_H
252 #include <sys/fs_types.h>
253 #endif
254   int
255   main ()
256   {
257   struct fs_data fsd;
258   /* Ultrix's statfs returns 1 for success,
259      0 for not mounted, -1 for failure.  */
260   return statfs (".", &fsd) != 1;
261   }]])],
262     [fu_cv_sys_stat_fs_data=yes],
263     [fu_cv_sys_stat_fs_data=no],
264     [fu_cv_sys_stat_fs_data=no])])
265   AC_MSG_RESULT([$fu_cv_sys_stat_fs_data])
266   if test $fu_cv_sys_stat_fs_data = yes; then
267     ac_fsusage_space=yes
268     AC_DEFINE([STAT_STATFS2_FS_DATA], [1],
269 [  Define if statfs takes 2 args and the second argument has
270    type struct fs_data.  (Ultrix)])
271   fi
274 if test $ac_fsusage_space = no; then
275   # SVR2
276   # (AIX, HP-UX, OSF/1 already handled above.)
277   AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <sys/filsys.h>
278         ]])],
279     [AC_DEFINE([STAT_READ_FILSYS], [1],
280       [Define if there is no specific function for reading file systems usage
281        information and you have the <sys/filsys.h> header file.  (SVR2)])
282      ac_fsusage_space=yes])
285 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
290 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
291 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
292 # enable the work-around code in fsusage.c.
293 AC_DEFUN([gl_STATFS_TRUNCATES],
295   AC_MSG_CHECKING([for statfs that truncates block counts])
296   AC_CACHE_VAL([fu_cv_sys_truncating_statfs],
297   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
298 #if !defined(sun) && !defined(__sun)
299 choke -- this is a workaround for a Sun-specific problem
300 #endif
301 #include <sys/types.h>
302 #include <sys/vfs.h>]],
303       [[struct statfs t; long c = *(t.f_spare);
304         if (c) return 0;]])],
305     [fu_cv_sys_truncating_statfs=yes],
306     [fu_cv_sys_truncating_statfs=no])])
307   if test $fu_cv_sys_truncating_statfs = yes; then
308     AC_DEFINE([STATFS_TRUNCATES_BLOCK_COUNTS], [1],
309       [Define if the block counts reported by statfs may be truncated to 2GB
310        and the correct values may be stored in the f_spare array.
311        (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
312        SunOS 4.1.1 seems not to be affected.)])
313   fi
314   AC_MSG_RESULT([$fu_cv_sys_truncating_statfs])
318 # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
319 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
321   AC_CHECK_HEADERS([dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h])
322   gl_STATFS_TRUNCATES