chmod: some optimization.
[midnight-commander.git] / m4.include / ls-mntd-fs.m4
blob4c8b4ac77e310fa25e9a822120713ad311dc3c52
1 # serial 33
2 # How to list mounted file systems.
4 # Copyright (C) 1998-2004, 2006, 2009-2017 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_REQUIRE([AC_CANONICAL_HOST])
30 AC_CHECK_FUNCS([listmntent getmntinfo])
31 AC_CHECK_HEADERS_ONCE([sys/param.h sys/statvfs.h])
33 # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses
34 # NGROUPS (as the array dimension for a struct member) without a definition.
35 AC_CHECK_HEADERS([sys/ucred.h], [], [], [#include <grp.h>])
37 AC_CHECK_HEADERS([sys/mount.h], [], [],
38   [AC_INCLUDES_DEFAULT
39    [#if HAVE_SYS_PARAM_H
40      #include <sys/param.h>
41     #endif]])
43 AC_CHECK_HEADERS([mntent.h sys/fs_types.h])
44     getfsstat_includes="\
45 $ac_includes_default
46 #if HAVE_SYS_PARAM_H
47 # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
48 #endif
49 #if HAVE_SYS_UCRED_H
50 # include <grp.h> /* needed for definition of NGROUPS */
51 # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
52 #endif
53 #if HAVE_SYS_MOUNT_H
54 # include <sys/mount.h>
55 #endif
56 #if HAVE_SYS_FS_TYPES_H
57 # include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
58 #endif
60 AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
62 # Determine how to get the list of mounted file systems.
63 ac_list_mounted_fs=
65 # If the getmntent function is available but not in the standard library,
66 # make sure LIBS contains the appropriate -l option.
67 AC_FUNC_GETMNTENT
69 # This test must precede the ones for getmntent because Unicos-9 is
70 # reported to have the getmntent function, but its support is incompatible
71 # with other getmntent implementations.
73 # NOTE: Normally, I wouldn't use a check for system type as I've done for
74 # 'CRAY' below since that goes against the whole autoconf philosophy.  But
75 # I think there is too great a chance that some non-Cray system has a
76 # function named listmntent to risk the false positive.
78 if test -z "$ac_list_mounted_fs"; then
79   # Cray UNICOS 9
80   AC_MSG_CHECKING([for listmntent of Cray/Unicos-9])
81   AC_CACHE_VAL([fu_cv_sys_mounted_cray_listmntent],
82     [fu_cv_sys_mounted_cray_listmntent=no
83       AC_EGREP_CPP([yes],
84         [#ifdef _CRAY
85 yes
86 #endif
87         ], [test $ac_cv_func_listmntent = yes \
88             && fu_cv_sys_mounted_cray_listmntent=yes]
89       )
90     ]
91   )
92   AC_MSG_RESULT([$fu_cv_sys_mounted_cray_listmntent])
93   if test $fu_cv_sys_mounted_cray_listmntent = yes; then
94     ac_list_mounted_fs=found
95     AC_DEFINE([MOUNTED_LISTMNTENT], [1],
96       [Define if there is a function named listmntent that can be used to
97        list all mounted file systems.  (UNICOS)])
98   fi
101 if test -z "$ac_list_mounted_fs"; then
102   # AIX.
103   AC_MSG_CHECKING([for mntctl function and struct vmount])
104   AC_CACHE_VAL([fu_cv_sys_mounted_vmount],
105   [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <fshelp.h>]])],
106     [fu_cv_sys_mounted_vmount=yes],
107     [fu_cv_sys_mounted_vmount=no])])
108   AC_MSG_RESULT([$fu_cv_sys_mounted_vmount])
109   if test $fu_cv_sys_mounted_vmount = yes; then
110     ac_list_mounted_fs=found
111     AC_DEFINE([MOUNTED_VMOUNT], [1],
112         [Define if there is a function named mntctl that can be used to read
113          the list of mounted file systems, and there is a system header file
114          that declares 'struct vmount'.  (AIX)])
115   fi
118 if test $ac_cv_func_getmntent = yes; then
120   # This system has the getmntent function.
121   # Determine whether it's the one-argument variant or the two-argument one.
123   if test -z "$ac_list_mounted_fs"; then
124     # GNU/Linux, 4.3BSD, SunOS, HP-UX, Dynix, Irix
125     AC_MSG_CHECKING([for one-argument getmntent function])
126     AC_CACHE_VAL([fu_cv_sys_mounted_getmntent1],
127                  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
128 /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
129 #include <stdio.h>
131 #include <mntent.h>
132 #if !defined MOUNTED
133 # if defined _PATH_MOUNTED      /* GNU libc  */
134 #  define MOUNTED _PATH_MOUNTED
135 # endif
136 # if defined MNT_MNTTAB /* HP-UX.  */
137 #  define MOUNTED MNT_MNTTAB
138 # endif
139 # if defined MNTTABNAME /* Dynix.  */
140 #  define MOUNTED MNTTABNAME
141 # endif
142 #endif
144                       [[ struct mntent *mnt = 0; char *table = MOUNTED;
145                          if (sizeof mnt && sizeof table) return 0;]])],
146                     [fu_cv_sys_mounted_getmntent1=yes],
147                     [fu_cv_sys_mounted_getmntent1=no])])
148     AC_MSG_RESULT([$fu_cv_sys_mounted_getmntent1])
149     if test $fu_cv_sys_mounted_getmntent1 = yes; then
150       ac_list_mounted_fs=found
151       AC_DEFINE([MOUNTED_GETMNTENT1], [1],
152         [Define if there is a function named getmntent for reading the list
153          of mounted file systems, and that function takes a single argument.
154          (4.3BSD, SunOS, HP-UX, Dynix, Irix)])
155       AC_CHECK_FUNCS([hasmntopt])
156     fi
157   fi
159   if test -z "$ac_list_mounted_fs"; then
160     # SVR4
161     AC_MSG_CHECKING([for two-argument getmntent function])
162     AC_CACHE_VAL([fu_cv_sys_mounted_getmntent2],
163     [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
164       fu_cv_sys_mounted_getmntent2=yes,
165       fu_cv_sys_mounted_getmntent2=no)])
166     AC_MSG_RESULT([$fu_cv_sys_mounted_getmntent2])
167     if test $fu_cv_sys_mounted_getmntent2 = yes; then
168       ac_list_mounted_fs=found
169       AC_DEFINE([MOUNTED_GETMNTENT2], [1],
170         [Define if there is a function named getmntent for reading the list of
171          mounted file systems, and that function takes two arguments.  (SVR4)])
172       AC_CHECK_FUNCS([hasmntopt])
173     fi
174   fi
178 if test -z "$ac_list_mounted_fs"; then
179   # DEC Alpha running OSF/1, and Apple Darwin 1.3.
180   # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
182   AC_MSG_CHECKING([for getfsstat function])
183   AC_CACHE_VAL([fu_cv_sys_mounted_getfsstat],
184   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
185 #include <sys/types.h>
186 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
187 # define FS_TYPE(Ent) ((Ent).f_fstypename)
188 #else
189 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
190 #endif
191 $getfsstat_includes]]
193       [[struct statfs *stats;
194         int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
195         char *t = FS_TYPE (*stats); ]])],
196     [fu_cv_sys_mounted_getfsstat=yes],
197     [fu_cv_sys_mounted_getfsstat=no])])
198   AC_MSG_RESULT([$fu_cv_sys_mounted_getfsstat])
199   if test $fu_cv_sys_mounted_getfsstat = yes; then
200     ac_list_mounted_fs=found
201     AC_DEFINE([MOUNTED_GETFSSTAT], [1],
202               [Define if there is a function named getfsstat for reading the
203                list of mounted file systems.  (DEC Alpha running OSF/1)])
204   fi
207 if test -z "$ac_list_mounted_fs"; then
208   # SVR3
209   AC_MSG_CHECKING([for FIXME existence of three headers])
210   AC_CACHE_VAL([fu_cv_sys_mounted_fread_fstyp],
211     [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
212 #include <sys/statfs.h>
213 #include <sys/fstyp.h>
214 #include <mnttab.h>]])],
215                        [fu_cv_sys_mounted_fread_fstyp=yes],
216                        [fu_cv_sys_mounted_fread_fstyp=no])])
217   AC_MSG_RESULT([$fu_cv_sys_mounted_fread_fstyp])
218   if test $fu_cv_sys_mounted_fread_fstyp = yes; then
219     ac_list_mounted_fs=found
220     AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
221       [Define if (like SVR2) there is no specific function for reading the
222        list of mounted file systems, and your system has these header files:
223        <sys/fstyp.h> and <sys/statfs.h>.  (SVR3)])
224   fi
227 if test -z "$ac_list_mounted_fs"; then
228   # 4.4BSD and DEC OSF/1.
229   AC_MSG_CHECKING([for getmntinfo function])
230   AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo],
231     [
232       test "$ac_cv_func_getmntinfo" = yes \
233           && fu_cv_sys_mounted_getmntinfo=yes \
234           || fu_cv_sys_mounted_getmntinfo=no
235     ])
236   AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo])
237   if test $fu_cv_sys_mounted_getmntinfo = yes; then
238     AC_MSG_CHECKING([whether getmntinfo returns statvfs structures])
239     AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo2],
240       [
241         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
242 #if HAVE_SYS_PARAM_H
243 # include <sys/param.h>
244 #endif
245 #include <sys/types.h>
246 #if HAVE_SYS_MOUNT_H
247 # include <sys/mount.h>
248 #endif
249 #if HAVE_SYS_STATVFS_H
250 # include <sys/statvfs.h>
251 #endif
252 extern
253 #ifdef __cplusplus
255 #endif
256 int getmntinfo (struct statfs **, int);
257             ]], [])],
258           [fu_cv_sys_mounted_getmntinfo2=no],
259           [fu_cv_sys_mounted_getmntinfo2=yes])
260       ])
261     AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo2])
262     if test $fu_cv_sys_mounted_getmntinfo2 = no; then
263       ac_list_mounted_fs=found
264       AC_DEFINE([MOUNTED_GETMNTINFO], [1],
265                 [Define if there is a function named getmntinfo for reading the
266                  list of mounted file systems and it returns an array of
267                  'struct statfs'.  (4.4BSD, Darwin)])
268     else
269       ac_list_mounted_fs=found
270       AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
271                 [Define if there is a function named getmntinfo for reading the
272                  list of mounted file systems and it returns an array of
273                  'struct statvfs'.  (NetBSD 3.0)])
274     fi
275   fi
278 if test -z "$ac_list_mounted_fs"; then
279   # Ultrix
280   AC_MSG_CHECKING([for getmnt function])
281   AC_CACHE_VAL([fu_cv_sys_mounted_getmnt],
282     [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
283 #include <sys/fs_types.h>
284 #include <sys/mount.h>]])],
285                        [fu_cv_sys_mounted_getmnt=yes],
286                        [fu_cv_sys_mounted_getmnt=no])])
287   AC_MSG_RESULT([$fu_cv_sys_mounted_getmnt])
288   if test $fu_cv_sys_mounted_getmnt = yes; then
289     ac_list_mounted_fs=found
290     AC_DEFINE([MOUNTED_GETMNT], [1],
291       [Define if there is a function named getmnt for reading the list of
292        mounted file systems.  (Ultrix)])
293   fi
296 if test -z "$ac_list_mounted_fs"; then
297   # BeOS
298   AC_CHECK_FUNCS([next_dev fs_stat_dev])
299   AC_CHECK_HEADERS([fs_info.h])
300   AC_MSG_CHECKING([for BEOS mounted file system support functions])
301   if test $ac_cv_header_fs_info_h = yes \
302       && test $ac_cv_func_next_dev = yes \
303         && test $ac_cv_func_fs_stat_dev = yes; then
304     fu_result=yes
305   else
306     fu_result=no
307   fi
308   AC_MSG_RESULT([$fu_result])
309   if test $fu_result = yes; then
310     ac_list_mounted_fs=found
311     AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
312       [Define if there are functions named next_dev and fs_stat_dev for
313        reading the list of mounted file systems.  (BeOS)])
314   fi
317 if test -z "$ac_list_mounted_fs"; then
318   # SVR2
319   AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
320   AC_CACHE_VAL([fu_cv_sys_mounted_fread],
321     [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <mnttab.h>]])],
322                        [fu_cv_sys_mounted_fread=yes],
323                        [fu_cv_sys_mounted_fread=no])])
324   AC_MSG_RESULT([$fu_cv_sys_mounted_fread])
325   if test $fu_cv_sys_mounted_fread = yes; then
326     ac_list_mounted_fs=found
327     AC_DEFINE([MOUNTED_FREAD], [1],
328               [Define if there is no specific function for reading the list of
329                mounted file systems.  fread will be used to read /etc/mnttab.
330                (SVR2) ])
331   fi
334 if test -z "$ac_list_mounted_fs"; then
335   # Interix / BSD alike statvfs
336   # the code is really interix specific, so make sure, we're on it.
337   case "$host" in
338   *-interix*)
339     AC_CHECK_FUNCS([statvfs])
340     if test $ac_cv_func_statvfs = yes; then
341       ac_list_mounted_fs=found
342       AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
343                 [Define if we are on interix, and ought to use statvfs plus
344                  some special knowledge on where mounted file systems can be
345                  found. (Interix)])
346     fi
347     ;;
348   esac
351 if test -z "$ac_list_mounted_fs"; then
352   AC_MSG_ERROR([could not determine how to read list of mounted file systems])
353   # FIXME -- no need to abort building the whole package
354   # Can't build mountlist.c or anything that needs its functions
357 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])
359   ])