2 # How to list mounted file systems.
4 # Copyright (C) 1998-2004, 2006, 2009-2018 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],
21 # getmntent is in the standard C library on UNICOS, in -lsun on Irix 4,
23 AC_SEARCH_LIBS([getmntent], [sun gen])
24 AC_CHECK_FUNCS([getmntent])
27 # gl_LIST_MOUNTED_FILE_SYSTEMS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
28 AC_DEFUN([gl_LIST_MOUNTED_FILE_SYSTEMS],
30 AC_REQUIRE([AC_CANONICAL_HOST])
31 AC_CHECK_FUNCS([listmntent])
32 AC_CHECK_HEADERS_ONCE([sys/param.h sys/statvfs.h])
34 # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses
35 # NGROUPS (as the array dimension for a struct member) without a definition.
36 AC_CHECK_HEADERS([sys/ucred.h], [], [], [#include <grp.h>])
38 AC_CHECK_HEADERS([sys/mount.h], [], [],
41 #include <sys/param.h>
45 AC_CHECK_HEADERS([mntent.h sys/fs_types.h])
49 # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
52 # include <grp.h> /* needed for definition of NGROUPS */
53 # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
56 # include <sys/mount.h>
58 #if HAVE_SYS_FS_TYPES_H
59 # include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
62 AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
64 # Determine how to get the list of mounted file systems.
67 # If the getmntent function is available but not in the standard library,
68 # make sure LIBS contains the appropriate -l option.
71 # This test must precede the ones for getmntent because Unicos-9 is
72 # reported to have the getmntent function, but its support is incompatible
73 # with other getmntent implementations.
75 # NOTE: Normally, I wouldn't use a check for system type as I've done for
76 # 'CRAY' below since that goes against the whole autoconf philosophy. But
77 # I think there is too great a chance that some non-Cray system has a
78 # function named listmntent to risk the false positive.
80 if test -z "$ac_list_mounted_fs"; then
81 # (obsolete) Cray UNICOS 9
82 AC_CACHE_CHECK([for listmntent of Cray/Unicos-9],
83 [fu_cv_sys_mounted_cray_listmntent],
84 [fu_cv_sys_mounted_cray_listmntent=no
89 ], [test $ac_cv_func_listmntent = yes \
90 && fu_cv_sys_mounted_cray_listmntent=yes]
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)])
101 if test -z "$ac_list_mounted_fs"; then
103 AC_CACHE_CHECK([for mntctl function and struct vmount],
104 [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 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 # glibc, HP-UX, IRIX, Cygwin, Android, also (obsolete) 4.3BSD, SunOS.
124 AC_CACHE_CHECK([for one-argument getmntent function],
125 [fu_cv_sys_mounted_getmntent1],
128 /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
133 # if defined _PATH_MOUNTED /* GNU libc */
134 # define MOUNTED _PATH_MOUNTED
136 # if defined MNT_MNTTAB /* HP-UX. */
137 # define MOUNTED MNT_MNTTAB
141 [[struct mntent *mnt = 0; char *table = MOUNTED;
142 if (sizeof mnt && sizeof table) return 0;
144 [fu_cv_sys_mounted_getmntent1=yes],
145 [fu_cv_sys_mounted_getmntent1=no])
147 if test $fu_cv_sys_mounted_getmntent1 = yes; then
148 ac_list_mounted_fs=found
149 AC_DEFINE([MOUNTED_GETMNTENT1], [1],
150 [Define if there is a function named getmntent for reading the list
151 of mounted file systems, and that function takes a single argument.
152 (4.3BSD, SunOS, HP-UX, Irix)])
153 AC_CHECK_FUNCS([hasmntopt])
157 if test -z "$ac_list_mounted_fs"; then
159 AC_CACHE_CHECK([for getextmntent function],
160 [fu_cv_sys_mounted_getextmntent],
161 [AC_EGREP_HEADER([getextmntent], [sys/mnttab.h],
162 [fu_cv_sys_mounted_getextmntent=yes],
163 [fu_cv_sys_mounted_getextmntent=no])])
164 if test $fu_cv_sys_mounted_getextmntent = yes; then
165 ac_list_mounted_fs=found
166 AC_DEFINE([MOUNTED_GETEXTMNTENT], [1],
167 [Define if there is a function named getextmntent for reading the list
168 of mounted file systems. (Solaris)])
172 if test -z "$ac_list_mounted_fs"; then
173 # Solaris < 8, also (obsolete) SVR4.
174 # Solaris >= 8 has the two-argument getmntent but is already handled above.
175 AC_CACHE_CHECK([for two-argument getmntent function],
176 [fu_cv_sys_mounted_getmntent2],
177 [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
178 [fu_cv_sys_mounted_getmntent2=yes],
179 [fu_cv_sys_mounted_getmntent2=no])
181 if test $fu_cv_sys_mounted_getmntent2 = yes; then
182 ac_list_mounted_fs=found
183 AC_DEFINE([MOUNTED_GETMNTENT2], [1],
184 [Define if there is a function named getmntent for reading the list of
185 mounted file systems, and that function takes two arguments. (SVR4)])
186 AC_CHECK_FUNCS([hasmntopt])
192 if test -z "$ac_list_mounted_fs"; then
193 # OSF/1, also (obsolete) Apple Darwin 1.3.
194 # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
196 AC_CACHE_CHECK([for getfsstat function],
197 [fu_cv_sys_mounted_getfsstat],
200 #include <sys/types.h>
201 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
202 # define FS_TYPE(Ent) ((Ent).f_fstypename)
204 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
208 [[struct statfs *stats;
209 int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
210 char *t = FS_TYPE (*stats);
212 [fu_cv_sys_mounted_getfsstat=yes],
213 [fu_cv_sys_mounted_getfsstat=no])
215 if test $fu_cv_sys_mounted_getfsstat = yes; then
216 ac_list_mounted_fs=found
217 AC_DEFINE([MOUNTED_GETFSSTAT], [1],
218 [Define if there is a function named getfsstat for reading the
219 list of mounted file systems. (DEC Alpha running OSF/1)])
223 if test -z "$ac_list_mounted_fs"; then
225 AC_CACHE_CHECK([for FIXME existence of three headers],
226 [fu_cv_sys_mounted_fread_fstyp],
227 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
228 #include <sys/statfs.h>
229 #include <sys/fstyp.h>
232 [fu_cv_sys_mounted_fread_fstyp=yes],
233 [fu_cv_sys_mounted_fread_fstyp=no])
235 if test $fu_cv_sys_mounted_fread_fstyp = yes; then
236 ac_list_mounted_fs=found
237 AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
238 [Define if (like SVR2) there is no specific function for reading the
239 list of mounted file systems, and your system has these header files:
240 <sys/fstyp.h> and <sys/statfs.h>. (SVR3)])
244 if test -z "$ac_list_mounted_fs"; then
245 # Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, also (obsolete) 4.4BSD.
246 # OSF/1 also has getmntinfo but is already handled above.
247 # We cannot use AC_CHECK_FUNCS([getmntinfo]) here, because at the linker
248 # level the function is sometimes called getmntinfo64 or getmntinfo$INODE64
249 # on Mac OS X, __getmntinfo13 on NetBSD and Minix, _F64_getmntinfo on OSF/1.
250 AC_CACHE_CHECK([for getmntinfo function],
251 [fu_cv_sys_mounted_getmntinfo],
255 # include <sys/param.h>
257 #include <sys/types.h>
259 # include <sys/mount.h>
261 #if HAVE_SYS_STATVFS_H
262 # include <sys/statvfs.h>
266 [[int count = getmntinfo (NULL, MNT_WAIT);
268 [fu_cv_sys_mounted_getmntinfo=yes],
269 [fu_cv_sys_mounted_getmntinfo=no])
271 if test $fu_cv_sys_mounted_getmntinfo = yes; then
272 AC_CACHE_CHECK([whether getmntinfo returns statvfs structures],
273 [fu_cv_sys_mounted_getmntinfo2],
277 # include <sys/param.h>
279 #include <sys/types.h>
281 # include <sys/mount.h>
283 #if HAVE_SYS_STATVFS_H
284 # include <sys/statvfs.h>
290 int getmntinfo (struct statfs **, int);
292 [fu_cv_sys_mounted_getmntinfo2=no],
293 [fu_cv_sys_mounted_getmntinfo2=yes])
295 if test $fu_cv_sys_mounted_getmntinfo2 = no; then
296 # Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD.
297 ac_list_mounted_fs=found
298 AC_DEFINE([MOUNTED_GETMNTINFO], [1],
299 [Define if there is a function named getmntinfo for reading the
300 list of mounted file systems and it returns an array of
301 'struct statfs'. (4.4BSD, Darwin)])
304 ac_list_mounted_fs=found
305 AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
306 [Define if there is a function named getmntinfo for reading the
307 list of mounted file systems and it returns an array of
308 'struct statvfs'. (NetBSD 3.0)])
313 if test -z "$ac_list_mounted_fs"; then
315 AC_CACHE_CHECK([for getmnt function],
316 [fu_cv_sys_mounted_getmnt],
317 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
318 #include <sys/fs_types.h>
319 #include <sys/mount.h>]])],
320 [fu_cv_sys_mounted_getmnt=yes],
321 [fu_cv_sys_mounted_getmnt=no])
323 if test $fu_cv_sys_mounted_getmnt = yes; then
324 ac_list_mounted_fs=found
325 AC_DEFINE([MOUNTED_GETMNT], [1],
326 [Define if there is a function named getmnt for reading the list of
327 mounted file systems. (Ultrix)])
331 if test -z "$ac_list_mounted_fs"; then
332 # Haiku, also (obsolete) BeOS.
333 AC_CHECK_FUNCS([next_dev fs_stat_dev])
334 AC_CHECK_HEADERS([fs_info.h])
335 AC_CACHE_CHECK([for BEOS mounted file system support functions],
336 [fu_cv_sys_mounted_fs_stat_dev],
337 [if test $ac_cv_header_fs_info_h = yes \
338 && test $ac_cv_func_next_dev = yes \
339 && test $ac_cv_func_fs_stat_dev = yes; then
340 fu_cv_sys_mounted_fs_stat_dev=yes
342 fu_cv_sys_mounted_fs_stat_dev=no
345 if test $fu_cv_sys_mounted_fs_stat_dev = yes; then
346 ac_list_mounted_fs=found
347 AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
348 [Define if there are functions named next_dev and fs_stat_dev for
349 reading the list of mounted file systems. (BeOS)])
353 if test -z "$ac_list_mounted_fs"; then
354 # Interix / BSD alike statvfs
355 # the code is really interix specific, so make sure, we're on it.
358 AC_CHECK_FUNCS([statvfs])
359 if test $ac_cv_func_statvfs = yes; then
360 ac_list_mounted_fs=found
361 AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
362 [Define if we are on interix, and ought to use statvfs plus
363 some special knowledge on where mounted file systems can be
370 if test -z "$ac_list_mounted_fs"; then
371 AC_MSG_ERROR([could not determine how to read list of mounted file systems])
372 # FIXME -- no need to abort building the whole package
373 # Can't build mountlist.c or anything that needs its functions
376 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])