Merge branch '3259_hexedit_utf8'
[midnight-commander.git] / m4.include / ls-mntd-fs.m4
blobc29f0aa23db963ce2cc688a6bff76d34483f605b
1 # serial 29
2 # How to list mounted file systems.
4 # Copyright (C) 1998-2004, 2006, 2009-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 dnl From Jim Meyering.
11 dnl
12 dnl This is not pretty.  I've just taken the autoconf code and wrapped
13 dnl it in an AC_DEFUN and made some other fixes.
14 dnl
16 # Replace Autoconf's AC_FUNC_GETMNTENT to work around a bug in Autoconf
17 # through Autoconf 2.59.  We can remove this once we assume Autoconf 2.60
18 # or later.
19 AC_DEFUN([AC_FUNC_GETMNTENT],
20 [# getmntent is in the standard C library on UNICOS, in -lsun on Irix 4,
21 # -lseq on Dynix/PTX, -lgen on Unixware.
22 AC_SEARCH_LIBS([getmntent], [sun seq gen])
23 AC_CHECK_FUNCS([getmntent])
26 # gl_LIST_MOUNTED_FILE_SYSTEMS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
27 AC_DEFUN([gl_LIST_MOUNTED_FILE_SYSTEMS],
28   [
29 AC_CHECK_FUNCS([listmntent getmntinfo])
30 AC_CHECK_HEADERS_ONCE([sys/param.h sys/statvfs.h])
32 # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses
33 # NGROUPS (as the array dimension for a struct member) without a definition.
34 AC_CHECK_HEADERS([sys/ucred.h], [], [], [#include <grp.h>])
36 AC_CHECK_HEADERS([sys/mount.h], [], [],
37   [AC_INCLUDES_DEFAULT
38    [#if HAVE_SYS_PARAM_H
39      #include <sys/param.h>
40     #endif]])
42 AC_CHECK_HEADERS([mntent.h sys/fs_types.h])
43     getfsstat_includes="\
44 $ac_includes_default
45 #if HAVE_SYS_PARAM_H
46 # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
47 #endif
48 #if HAVE_SYS_UCRED_H
49 # include <grp.h> /* needed for definition of NGROUPS */
50 # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
51 #endif
52 #if HAVE_SYS_MOUNT_H
53 # include <sys/mount.h>
54 #endif
55 #if HAVE_SYS_FS_TYPES_H
56 # include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
57 #endif
59 AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
61 # Determine how to get the list of mounted file systems.
62 ac_list_mounted_fs=
64 # If the getmntent function is available but not in the standard library,
65 # make sure LIBS contains the appropriate -l option.
66 AC_FUNC_GETMNTENT
68 # This test must precede the ones for getmntent because Unicos-9 is
69 # reported to have the getmntent function, but its support is incompatible
70 # with other getmntent implementations.
72 # NOTE: Normally, I wouldn't use a check for system type as I've done for
73 # 'CRAY' below since that goes against the whole autoconf philosophy.  But
74 # I think there is too great a chance that some non-Cray system has a
75 # function named listmntent to risk the false positive.
77 if test -z "$ac_list_mounted_fs"; then
78   # Cray UNICOS 9
79   AC_MSG_CHECKING([for listmntent of Cray/Unicos-9])
80   AC_CACHE_VAL([fu_cv_sys_mounted_cray_listmntent],
81     [fu_cv_sys_mounted_cray_listmntent=no
82       AC_EGREP_CPP([yes],
83         [#ifdef _CRAY
84 yes
85 #endif
86         ], [test $ac_cv_func_listmntent = yes \
87             && fu_cv_sys_mounted_cray_listmntent=yes]
88       )
89     ]
90   )
91   AC_MSG_RESULT([$fu_cv_sys_mounted_cray_listmntent])
92   if test $fu_cv_sys_mounted_cray_listmntent = yes; then
93     ac_list_mounted_fs=found
94     AC_DEFINE([MOUNTED_LISTMNTENT], [1],
95       [Define if there is a function named listmntent that can be used to
96        list all mounted file systems.  (UNICOS)])
97   fi
100 if test -z "$ac_list_mounted_fs"; then
101   # AIX.
102   AC_MSG_CHECKING([for mntctl function and struct vmount])
103   AC_CACHE_VAL([fu_cv_sys_mounted_vmount],
104   [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <fshelp.h>]])],
105     [fu_cv_sys_mounted_vmount=yes],
106     [fu_cv_sys_mounted_vmount=no])])
107   AC_MSG_RESULT([$fu_cv_sys_mounted_vmount])
108   if test $fu_cv_sys_mounted_vmount = yes; then
109     ac_list_mounted_fs=found
110     AC_DEFINE([MOUNTED_VMOUNT], [1],
111         [Define if there is a function named mntctl that can be used to read
112          the list of mounted file systems, and there is a system header file
113          that declares 'struct vmount.'  (AIX)])
114   fi
117 if test $ac_cv_func_getmntent = yes; then
119   # This system has the getmntent function.
120   # Determine whether it's the one-argument variant or the two-argument one.
122   if test -z "$ac_list_mounted_fs"; then
123     # 4.3BSD, SunOS, HP-UX, Dynix, Irix
124     AC_MSG_CHECKING([for one-argument getmntent function])
125     AC_CACHE_VAL([fu_cv_sys_mounted_getmntent1],
126                  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
127 /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
128 #include <stdio.h>
130 #include <mntent.h>
131 #if !defined MOUNTED
132 # if defined _PATH_MOUNTED      /* GNU libc  */
133 #  define MOUNTED _PATH_MOUNTED
134 # endif
135 # if defined MNT_MNTTAB /* HP-UX.  */
136 #  define MOUNTED MNT_MNTTAB
137 # endif
138 # if defined MNTTABNAME /* Dynix.  */
139 #  define MOUNTED MNTTABNAME
140 # endif
141 #endif
143                       [[ struct mntent *mnt = 0; char *table = MOUNTED;
144                          if (sizeof mnt && sizeof table) return 0;]])],
145                     [fu_cv_sys_mounted_getmntent1=yes],
146                     [fu_cv_sys_mounted_getmntent1=no])])
147     AC_MSG_RESULT([$fu_cv_sys_mounted_getmntent1])
148     if test $fu_cv_sys_mounted_getmntent1 = yes; then
149       ac_list_mounted_fs=found
150       AC_DEFINE([MOUNTED_GETMNTENT1], [1],
151         [Define if there is a function named getmntent for reading the list
152          of mounted file systems, and that function takes a single argument.
153          (4.3BSD, SunOS, HP-UX, Dynix, Irix)])
154       AC_CHECK_FUNCS([hasmntopt])
156       # Check for libmount to support /proc/self/mountinfo on Linux
157       AC_CACHE_VAL([ac_cv_lib_libmount_mnt_table_parse_stream],
158         [AC_CHECK_LIB([mount], [mnt_new_table_from_file],
159           ac_cv_lib_mount_mnt_table_parse_stream=yes,
160           ac_cv_lib_mount_mnt_table_parse_stream=no)])
161       if test $ac_cv_lib_mount_mnt_table_parse_stream = yes; then
162          AC_DEFINE([MOUNTED_PROC_MOUNTINFO], [1],
163            [Define if want to use /proc/self/mountinfo on Linux.])
164          LIBS="-lmount $LIBS"
165       elif test -f /proc/self/mountinfo; then
166          AC_MSG_WARN([/proc/self/mountinfo present but libmount is missing.])
167       fi
168     fi
169   fi
171   if test -z "$ac_list_mounted_fs"; then
172     # SVR4
173     AC_MSG_CHECKING([for two-argument getmntent function])
174     AC_CACHE_VAL([fu_cv_sys_mounted_getmntent2],
175     [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
176       fu_cv_sys_mounted_getmntent2=yes,
177       fu_cv_sys_mounted_getmntent2=no)])
178     AC_MSG_RESULT([$fu_cv_sys_mounted_getmntent2])
179     if test $fu_cv_sys_mounted_getmntent2 = yes; then
180       ac_list_mounted_fs=found
181       AC_DEFINE([MOUNTED_GETMNTENT2], [1],
182         [Define if there is a function named getmntent for reading the list of
183          mounted file systems, and that function takes two arguments.  (SVR4)])
184       AC_CHECK_FUNCS([hasmntopt])
185     fi
186   fi
190 if test -z "$ac_list_mounted_fs"; then
191   # DEC Alpha running OSF/1, and Apple Darwin 1.3.
192   # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
194   AC_MSG_CHECKING([for getfsstat function])
195   AC_CACHE_VAL([fu_cv_sys_mounted_getfsstat],
196   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
197 #include <sys/types.h>
198 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
199 # define FS_TYPE(Ent) ((Ent).f_fstypename)
200 #else
201 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
202 #endif
203 $getfsstat_includes]]
205       [[struct statfs *stats;
206         int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
207         char *t = FS_TYPE (*stats); ]])],
208     [fu_cv_sys_mounted_getfsstat=yes],
209     [fu_cv_sys_mounted_getfsstat=no])])
210   AC_MSG_RESULT([$fu_cv_sys_mounted_getfsstat])
211   if test $fu_cv_sys_mounted_getfsstat = yes; then
212     ac_list_mounted_fs=found
213     AC_DEFINE([MOUNTED_GETFSSTAT], [1],
214               [Define if there is a function named getfsstat for reading the
215                list of mounted file systems.  (DEC Alpha running OSF/1)])
216   fi
219 if test -z "$ac_list_mounted_fs"; then
220   # SVR3
221   AC_MSG_CHECKING([for FIXME existence of three headers])
222   AC_CACHE_VAL([fu_cv_sys_mounted_fread_fstyp],
223     [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
224 #include <sys/statfs.h>
225 #include <sys/fstyp.h>
226 #include <mnttab.h>]])],
227                        [fu_cv_sys_mounted_fread_fstyp=yes],
228                        [fu_cv_sys_mounted_fread_fstyp=no])])
229   AC_MSG_RESULT([$fu_cv_sys_mounted_fread_fstyp])
230   if test $fu_cv_sys_mounted_fread_fstyp = yes; then
231     ac_list_mounted_fs=found
232     AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
233       [Define if (like SVR2) there is no specific function for reading the
234        list of mounted file systems, and your system has these header files:
235        <sys/fstyp.h> and <sys/statfs.h>.  (SVR3)])
236   fi
239 if test -z "$ac_list_mounted_fs"; then
240   # 4.4BSD and DEC OSF/1.
241   AC_MSG_CHECKING([for getmntinfo function])
242   AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo],
243     [
244       test "$ac_cv_func_getmntinfo" = yes \
245           && fu_cv_sys_mounted_getmntinfo=yes \
246           || fu_cv_sys_mounted_getmntinfo=no
247     ])
248   AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo])
249   if test $fu_cv_sys_mounted_getmntinfo = yes; then
250     AC_MSG_CHECKING([whether getmntinfo returns statvfs structures])
251     AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo2],
252       [
253         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
254 #if HAVE_SYS_PARAM_H
255 # include <sys/param.h>
256 #endif
257 #include <sys/types.h>
258 #if HAVE_SYS_MOUNT_H
259 # include <sys/mount.h>
260 #endif
261 #if HAVE_SYS_STATVFS_H
262 # include <sys/statvfs.h>
263 #endif
264 extern
265 #ifdef __cplusplus
267 #endif
268 int getmntinfo (struct statfs **, int);
269             ]], [])],
270           [fu_cv_sys_mounted_getmntinfo2=no],
271           [fu_cv_sys_mounted_getmntinfo2=yes])
272       ])
273     AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo2])
274     if test $fu_cv_sys_mounted_getmntinfo2 = no; then
275       ac_list_mounted_fs=found
276       AC_DEFINE([MOUNTED_GETMNTINFO], [1],
277                 [Define if there is a function named getmntinfo for reading the
278                  list of mounted file systems and it returns an array of
279                  'struct statfs'.  (4.4BSD, Darwin)])
280     else
281       ac_list_mounted_fs=found
282       AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
283                 [Define if there is a function named getmntinfo for reading the
284                  list of mounted file systems and it returns an array of
285                  'struct statvfs'.  (NetBSD 3.0)])
286     fi
287   fi
290 if test -z "$ac_list_mounted_fs"; then
291   # Ultrix
292   AC_MSG_CHECKING([for getmnt function])
293   AC_CACHE_VAL([fu_cv_sys_mounted_getmnt],
294     [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
295 #include <sys/fs_types.h>
296 #include <sys/mount.h>]])],
297                        [fu_cv_sys_mounted_getmnt=yes],
298                        [fu_cv_sys_mounted_getmnt=no])])
299   AC_MSG_RESULT([$fu_cv_sys_mounted_getmnt])
300   if test $fu_cv_sys_mounted_getmnt = yes; then
301     ac_list_mounted_fs=found
302     AC_DEFINE([MOUNTED_GETMNT], [1],
303       [Define if there is a function named getmnt for reading the list of
304        mounted file systems.  (Ultrix)])
305   fi
308 if test -z "$ac_list_mounted_fs"; then
309   # BeOS
310   AC_CHECK_FUNCS([next_dev fs_stat_dev])
311   AC_CHECK_HEADERS([fs_info.h])
312   AC_MSG_CHECKING([for BEOS mounted file system support functions])
313   if test $ac_cv_header_fs_info_h = yes \
314       && test $ac_cv_func_next_dev = yes \
315         && test $ac_cv_func_fs_stat_dev = yes; then
316     fu_result=yes
317   else
318     fu_result=no
319   fi
320   AC_MSG_RESULT([$fu_result])
321   if test $fu_result = yes; then
322     ac_list_mounted_fs=found
323     AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
324       [Define if there are functions named next_dev and fs_stat_dev for
325        reading the list of mounted file systems.  (BeOS)])
326   fi
329 if test -z "$ac_list_mounted_fs"; then
330   # SVR2
331   AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
332   AC_CACHE_VAL([fu_cv_sys_mounted_fread],
333     [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <mnttab.h>]])],
334                        [fu_cv_sys_mounted_fread=yes],
335                        [fu_cv_sys_mounted_fread=no])])
336   AC_MSG_RESULT([$fu_cv_sys_mounted_fread])
337   if test $fu_cv_sys_mounted_fread = yes; then
338     ac_list_mounted_fs=found
339     AC_DEFINE([MOUNTED_FREAD], [1],
340               [Define if there is no specific function for reading the list of
341                mounted file systems.  fread will be used to read /etc/mnttab.
342                (SVR2) ])
343   fi
346 if test -z "$ac_list_mounted_fs"; then
347   # Interix / BSD alike statvfs
348   # the code is really interix specific, so make sure, we're on it.
349   case "$host" in
350   *-interix*)
351     AC_CHECK_FUNCS([statvfs])
352     if test $ac_cv_func_statvfs = yes; then
353       ac_list_mounted_fs=found
354       AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
355                 [Define if we are on interix, and ought to use statvfs plus
356                  some special knowledge on where mounted filesystems can be
357                  found. (Interix)])
358     fi
359     ;;
360   esac
363 if test -z "$ac_list_mounted_fs"; then
364   AC_MSG_ERROR([could not determine how to read list of mounted file systems])
365   # FIXME -- no need to abort building the whole package
366   # Can't build mountlist.c or anything that needs its functions
369 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])
371   ])