1# serial 31
2# How to list mounted file systems.
3
4# Copyright (C) 1998-2004, 2006, 2009-2015 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.
9
10dnl From Jim Meyering.
11dnl
12dnl This is not pretty.  I've just taken the autoconf code and wrapped
13dnl it in an AC_DEFUN and made some other fixes.
14dnl
15
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.
19AC_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.
22AC_SEARCH_LIBS([getmntent], [sun seq gen])
23AC_CHECK_FUNCS([getmntent])
24])
25
26# gl_LIST_MOUNTED_FILE_SYSTEMS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
27AC_DEFUN([gl_LIST_MOUNTED_FILE_SYSTEMS],
28  [
29AC_CHECK_FUNCS([listmntent getmntinfo])
30AC_CHECK_HEADERS_ONCE([sys/param.h sys/statvfs.h])
31
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.
34AC_CHECK_HEADERS([sys/ucred.h], [], [], [#include <grp.h>])
35
36AC_CHECK_HEADERS([sys/mount.h], [], [],
37  [AC_INCLUDES_DEFAULT
38   [#if HAVE_SYS_PARAM_H
39     #include <sys/param.h>
40    #endif]])
41
42AC_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
58"
59AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
60
61# Determine how to get the list of mounted file systems.
62ac_list_mounted_fs=
63
64# If the getmntent function is available but not in the standard library,
65# make sure LIBS contains the appropriate -l option.
66AC_FUNC_GETMNTENT
67
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.
71
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.
76
77if 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
84yes
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
98fi
99
100if 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
115fi
116
117if test $ac_cv_func_getmntent = yes; then
118
119  # This system has the getmntent function.
120  # Determine whether it's the one-argument variant or the two-argument one.
121
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>
129
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
142]],
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])
155
156      AC_ARG_WITH([libmount],
157        [AS_HELP_STRING([--with-libmount],
158          [use libmount if available to parse the system mount list.])],
159        [],
160        dnl libmount has the advantage of propagating accurate device IDs for
161        dnl each entry, but the disadvantage of many dependent shared libs
162        dnl with associated runtime startup overhead and virt mem usage.
163        [with_libmount=no])
164
165      # Check for libmount to support /proc/self/mountinfo on Linux
166      if test "x$with_libmount" != xno; then
167        AC_CHECK_LIB([mount], [mnt_new_table_from_file],
168           [AC_DEFINE([MOUNTED_PROC_MOUNTINFO], [1],
169             [Define if want to use /proc/self/mountinfo on Linux.])
170            LIBS="-lmount $LIBS"],
171           [test -f /proc/self/mountinfo &&
172             AC_MSG_WARN([/proc/self/mountinfo present but libmount missing.])])
173      fi
174    fi
175  fi
176
177  if test -z "$ac_list_mounted_fs"; then
178    # SVR4
179    AC_MSG_CHECKING([for two-argument getmntent function])
180    AC_CACHE_VAL([fu_cv_sys_mounted_getmntent2],
181    [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
182      fu_cv_sys_mounted_getmntent2=yes,
183      fu_cv_sys_mounted_getmntent2=no)])
184    AC_MSG_RESULT([$fu_cv_sys_mounted_getmntent2])
185    if test $fu_cv_sys_mounted_getmntent2 = yes; then
186      ac_list_mounted_fs=found
187      AC_DEFINE([MOUNTED_GETMNTENT2], [1],
188        [Define if there is a function named getmntent for reading the list of
189         mounted file systems, and that function takes two arguments.  (SVR4)])
190      AC_CHECK_FUNCS([hasmntopt])
191    fi
192  fi
193
194fi
195
196if test -z "$ac_list_mounted_fs"; then
197  # DEC Alpha running OSF/1, and Apple Darwin 1.3.
198  # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
199
200  AC_MSG_CHECKING([for getfsstat function])
201  AC_CACHE_VAL([fu_cv_sys_mounted_getfsstat],
202  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
203#include <sys/types.h>
204#if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
205# define FS_TYPE(Ent) ((Ent).f_fstypename)
206#else
207# define FS_TYPE(Ent) mnt_names[(Ent).f_type]
208#endif
209$getfsstat_includes]]
210,
211      [[struct statfs *stats;
212        int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
213        char *t = FS_TYPE (*stats); ]])],
214    [fu_cv_sys_mounted_getfsstat=yes],
215    [fu_cv_sys_mounted_getfsstat=no])])
216  AC_MSG_RESULT([$fu_cv_sys_mounted_getfsstat])
217  if test $fu_cv_sys_mounted_getfsstat = yes; then
218    ac_list_mounted_fs=found
219    AC_DEFINE([MOUNTED_GETFSSTAT], [1],
220              [Define if there is a function named getfsstat for reading the
221               list of mounted file systems.  (DEC Alpha running OSF/1)])
222  fi
223fi
224
225if test -z "$ac_list_mounted_fs"; then
226  # SVR3
227  AC_MSG_CHECKING([for FIXME existence of three headers])
228  AC_CACHE_VAL([fu_cv_sys_mounted_fread_fstyp],
229    [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
230#include <sys/statfs.h>
231#include <sys/fstyp.h>
232#include <mnttab.h>]])],
233                       [fu_cv_sys_mounted_fread_fstyp=yes],
234                       [fu_cv_sys_mounted_fread_fstyp=no])])
235  AC_MSG_RESULT([$fu_cv_sys_mounted_fread_fstyp])
236  if test $fu_cv_sys_mounted_fread_fstyp = yes; then
237    ac_list_mounted_fs=found
238    AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
239      [Define if (like SVR2) there is no specific function for reading the
240       list of mounted file systems, and your system has these header files:
241       <sys/fstyp.h> and <sys/statfs.h>.  (SVR3)])
242  fi
243fi
244
245if test -z "$ac_list_mounted_fs"; then
246  # 4.4BSD and DEC OSF/1.
247  AC_MSG_CHECKING([for getmntinfo function])
248  AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo],
249    [
250      test "$ac_cv_func_getmntinfo" = yes \
251          && fu_cv_sys_mounted_getmntinfo=yes \
252          || fu_cv_sys_mounted_getmntinfo=no
253    ])
254  AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo])
255  if test $fu_cv_sys_mounted_getmntinfo = yes; then
256    AC_MSG_CHECKING([whether getmntinfo returns statvfs structures])
257    AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo2],
258      [
259        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
260#if HAVE_SYS_PARAM_H
261# include <sys/param.h>
262#endif
263#include <sys/types.h>
264#if HAVE_SYS_MOUNT_H
265# include <sys/mount.h>
266#endif
267#if HAVE_SYS_STATVFS_H
268# include <sys/statvfs.h>
269#endif
270extern
271#ifdef __cplusplus
272"C"
273#endif
274int getmntinfo (struct statfs **, int);
275            ]], [])],
276          [fu_cv_sys_mounted_getmntinfo2=no],
277          [fu_cv_sys_mounted_getmntinfo2=yes])
278      ])
279    AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo2])
280    if test $fu_cv_sys_mounted_getmntinfo2 = no; then
281      ac_list_mounted_fs=found
282      AC_DEFINE([MOUNTED_GETMNTINFO], [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 statfs'.  (4.4BSD, Darwin)])
286    else
287      ac_list_mounted_fs=found
288      AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
289                [Define if there is a function named getmntinfo for reading the
290                 list of mounted file systems and it returns an array of
291                 'struct statvfs'.  (NetBSD 3.0)])
292    fi
293  fi
294fi
295
296if test -z "$ac_list_mounted_fs"; then
297  # Ultrix
298  AC_MSG_CHECKING([for getmnt function])
299  AC_CACHE_VAL([fu_cv_sys_mounted_getmnt],
300    [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
301#include <sys/fs_types.h>
302#include <sys/mount.h>]])],
303                       [fu_cv_sys_mounted_getmnt=yes],
304                       [fu_cv_sys_mounted_getmnt=no])])
305  AC_MSG_RESULT([$fu_cv_sys_mounted_getmnt])
306  if test $fu_cv_sys_mounted_getmnt = yes; then
307    ac_list_mounted_fs=found
308    AC_DEFINE([MOUNTED_GETMNT], [1],
309      [Define if there is a function named getmnt for reading the list of
310       mounted file systems.  (Ultrix)])
311  fi
312fi
313
314if test -z "$ac_list_mounted_fs"; then
315  # BeOS
316  AC_CHECK_FUNCS([next_dev fs_stat_dev])
317  AC_CHECK_HEADERS([fs_info.h])
318  AC_MSG_CHECKING([for BEOS mounted file system support functions])
319  if test $ac_cv_header_fs_info_h = yes \
320      && test $ac_cv_func_next_dev = yes \
321        && test $ac_cv_func_fs_stat_dev = yes; then
322    fu_result=yes
323  else
324    fu_result=no
325  fi
326  AC_MSG_RESULT([$fu_result])
327  if test $fu_result = yes; then
328    ac_list_mounted_fs=found
329    AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
330      [Define if there are functions named next_dev and fs_stat_dev for
331       reading the list of mounted file systems.  (BeOS)])
332  fi
333fi
334
335if test -z "$ac_list_mounted_fs"; then
336  # SVR2
337  AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
338  AC_CACHE_VAL([fu_cv_sys_mounted_fread],
339    [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <mnttab.h>]])],
340                       [fu_cv_sys_mounted_fread=yes],
341                       [fu_cv_sys_mounted_fread=no])])
342  AC_MSG_RESULT([$fu_cv_sys_mounted_fread])
343  if test $fu_cv_sys_mounted_fread = yes; then
344    ac_list_mounted_fs=found
345    AC_DEFINE([MOUNTED_FREAD], [1],
346              [Define if there is no specific function for reading the list of
347               mounted file systems.  fread will be used to read /etc/mnttab.
348               (SVR2) ])
349  fi
350fi
351
352if test -z "$ac_list_mounted_fs"; then
353  # Interix / BSD alike statvfs
354  # the code is really interix specific, so make sure, we're on it.
355  case "$host" in
356  *-interix*)
357    AC_CHECK_FUNCS([statvfs])
358    if test $ac_cv_func_statvfs = yes; then
359      ac_list_mounted_fs=found
360      AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
361                [Define if we are on interix, and ought to use statvfs plus
362                 some special knowledge on where mounted file systems can be
363                 found. (Interix)])
364    fi
365    ;;
366  esac
367fi
368
369if test -z "$ac_list_mounted_fs"; then
370  AC_MSG_ERROR([could not determine how to read list of mounted file systems])
371  # FIXME -- no need to abort building the whole package
372  # Can't build mountlist.c or anything that needs its functions
373fi
374
375AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])
376
377  ])
378