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.
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.
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
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],
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], [], [],
39 #include <sys/param.h>
42 AC_CHECK_HEADERS([mntent.h sys/fs_types.h])
46 # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
49 # include <grp.h> /* needed for definition of NGROUPS */
50 # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
53 # include <sys/mount.h>
55 #if HAVE_SYS_FS_TYPES_H
56 # include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
59 AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
61 # Determine how to get the list of mounted file systems.
64 # If the getmntent function is available but not in the standard library,
65 # make sure LIBS contains the appropriate -l option.
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
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
86 ], [test $ac_cv_func_listmntent = yes \
87 && fu_cv_sys_mounted_cray_listmntent=yes]
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)])
100 if test -z "$ac_list_mounted_fs"; then
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)])
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 */
132 # if defined _PATH_MOUNTED /* GNU libc */
133 # define MOUNTED _PATH_MOUNTED
135 # if defined MNT_MNTTAB /* HP-UX. */
136 # define MOUNTED MNT_MNTTAB
138 # if defined MNTTABNAME /* Dynix. */
139 # define MOUNTED MNTTABNAME
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)])
157 if test -z "$ac_list_mounted_fs"; then
159 AC_MSG_CHECKING([for two-argument getmntent function])
160 AC_CACHE_VAL([fu_cv_sys_mounted_getmntent2],
161 [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
162 fu_cv_sys_mounted_getmntent2=yes,
163 fu_cv_sys_mounted_getmntent2=no)])
164 AC_MSG_RESULT([$fu_cv_sys_mounted_getmntent2])
165 if test $fu_cv_sys_mounted_getmntent2 = yes; then
166 ac_list_mounted_fs=found
167 AC_DEFINE([MOUNTED_GETMNTENT2], [1],
168 [Define if there is a function named getmntent for reading the list of
169 mounted file systems, and that function takes two arguments. (SVR4)])
170 AC_CHECK_FUNCS([hasmntopt])
176 if test -z "$ac_list_mounted_fs"; then
177 # DEC Alpha running OSF/1, and Apple Darwin 1.3.
178 # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
180 AC_MSG_CHECKING([for getfsstat function])
181 AC_CACHE_VAL([fu_cv_sys_mounted_getfsstat],
182 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
183 #include <sys/types.h>
184 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
185 # define FS_TYPE(Ent) ((Ent).f_fstypename)
187 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
189 $getfsstat_includes]]
191 [[struct statfs *stats;
192 int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
193 char *t = FS_TYPE (*stats); ]])],
194 [fu_cv_sys_mounted_getfsstat=yes],
195 [fu_cv_sys_mounted_getfsstat=no])])
196 AC_MSG_RESULT([$fu_cv_sys_mounted_getfsstat])
197 if test $fu_cv_sys_mounted_getfsstat = yes; then
198 ac_list_mounted_fs=found
199 AC_DEFINE([MOUNTED_GETFSSTAT], [1],
200 [Define if there is a function named getfsstat for reading the
201 list of mounted file systems. (DEC Alpha running OSF/1)])
205 if test -z "$ac_list_mounted_fs"; then
207 AC_MSG_CHECKING([for FIXME existence of three headers])
208 AC_CACHE_VAL([fu_cv_sys_mounted_fread_fstyp],
209 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
210 #include <sys/statfs.h>
211 #include <sys/fstyp.h>
212 #include <mnttab.h>]])],
213 [fu_cv_sys_mounted_fread_fstyp=yes],
214 [fu_cv_sys_mounted_fread_fstyp=no])])
215 AC_MSG_RESULT([$fu_cv_sys_mounted_fread_fstyp])
216 if test $fu_cv_sys_mounted_fread_fstyp = yes; then
217 ac_list_mounted_fs=found
218 AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
219 [Define if (like SVR2) there is no specific function for reading the
220 list of mounted file systems, and your system has these header files:
221 <sys/fstyp.h> and <sys/statfs.h>. (SVR3)])
225 if test -z "$ac_list_mounted_fs"; then
226 # 4.4BSD and DEC OSF/1.
227 AC_MSG_CHECKING([for getmntinfo function])
228 AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo],
230 test "$ac_cv_func_getmntinfo" = yes \
231 && fu_cv_sys_mounted_getmntinfo=yes \
232 || fu_cv_sys_mounted_getmntinfo=no
234 AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo])
235 if test $fu_cv_sys_mounted_getmntinfo = yes; then
236 AC_MSG_CHECKING([whether getmntinfo returns statvfs structures])
237 AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo2],
239 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
241 # include <sys/param.h>
243 #include <sys/types.h>
245 # include <sys/mount.h>
247 #if HAVE_SYS_STATVFS_H
248 # include <sys/statvfs.h>
254 int getmntinfo (struct statfs **, int);
256 [fu_cv_sys_mounted_getmntinfo2=no],
257 [fu_cv_sys_mounted_getmntinfo2=yes])
259 AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo2])
260 if test $fu_cv_sys_mounted_getmntinfo2 = no; then
261 ac_list_mounted_fs=found
262 AC_DEFINE([MOUNTED_GETMNTINFO], [1],
263 [Define if there is a function named getmntinfo for reading the
264 list of mounted file systems and it returns an array of
265 'struct statfs'. (4.4BSD, Darwin)])
267 ac_list_mounted_fs=found
268 AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
269 [Define if there is a function named getmntinfo for reading the
270 list of mounted file systems and it returns an array of
271 'struct statvfs'. (NetBSD 3.0)])
276 if test -z "$ac_list_mounted_fs"; then
278 AC_MSG_CHECKING([for getmnt function])
279 AC_CACHE_VAL([fu_cv_sys_mounted_getmnt],
280 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
281 #include <sys/fs_types.h>
282 #include <sys/mount.h>]])],
283 [fu_cv_sys_mounted_getmnt=yes],
284 [fu_cv_sys_mounted_getmnt=no])])
285 AC_MSG_RESULT([$fu_cv_sys_mounted_getmnt])
286 if test $fu_cv_sys_mounted_getmnt = yes; then
287 ac_list_mounted_fs=found
288 AC_DEFINE([MOUNTED_GETMNT], [1],
289 [Define if there is a function named getmnt for reading the list of
290 mounted file systems. (Ultrix)])
294 if test -z "$ac_list_mounted_fs"; then
296 AC_CHECK_FUNCS([next_dev fs_stat_dev])
297 AC_CHECK_HEADERS([fs_info.h])
298 AC_MSG_CHECKING([for BEOS mounted file system support functions])
299 if test $ac_cv_header_fs_info_h = yes \
300 && test $ac_cv_func_next_dev = yes \
301 && test $ac_cv_func_fs_stat_dev = yes; then
306 AC_MSG_RESULT([$fu_result])
307 if test $fu_result = yes; then
308 ac_list_mounted_fs=found
309 AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
310 [Define if there are functions named next_dev and fs_stat_dev for
311 reading the list of mounted file systems. (BeOS)])
315 if test -z "$ac_list_mounted_fs"; then
317 AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
318 AC_CACHE_VAL([fu_cv_sys_mounted_fread],
319 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <mnttab.h>]])],
320 [fu_cv_sys_mounted_fread=yes],
321 [fu_cv_sys_mounted_fread=no])])
322 AC_MSG_RESULT([$fu_cv_sys_mounted_fread])
323 if test $fu_cv_sys_mounted_fread = yes; then
324 ac_list_mounted_fs=found
325 AC_DEFINE([MOUNTED_FREAD], [1],
326 [Define if there is no specific function for reading the list of
327 mounted file systems. fread will be used to read /etc/mnttab.
332 if test -z "$ac_list_mounted_fs"; then
333 # Interix / BSD alike statvfs
334 # the code is really interix specific, so make sure, we're on it.
337 AC_CHECK_FUNCS([statvfs])
338 if test $ac_cv_func_statvfs = yes; then
339 ac_list_mounted_fs=found
340 AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
341 [Define if we are on interix, and ought to use statvfs plus
342 some special knowledge on where mounted filesystems can be
349 if test -z "$ac_list_mounted_fs"; then
350 AC_MSG_ERROR([could not determine how to read list of mounted file systems])
351 # FIXME -- no need to abort building the whole package
352 # Can't build mountlist.c or anything that needs its functions
355 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])