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,
22 # -lseq on Dynix/PTX, -lgen on Unixware.
23 AC_SEARCH_LIBS([getmntent], [sun seq 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, Dynix.
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
139 # if defined MNTTABNAME /* Dynix. */
140 # define MOUNTED MNTTABNAME
144 [[struct mntent *mnt = 0; char *table = MOUNTED;
145 if (sizeof mnt && sizeof table) return 0;
147 [fu_cv_sys_mounted_getmntent1=yes],
148 [fu_cv_sys_mounted_getmntent1=no])
150 if test $fu_cv_sys_mounted_getmntent1 = yes; then
151 ac_list_mounted_fs=found
152 AC_DEFINE([MOUNTED_GETMNTENT1], [1],
153 [Define if there is a function named getmntent for reading the list
154 of mounted file systems, and that function takes a single argument.
155 (4.3BSD, SunOS, HP-UX, Dynix, Irix)])
156 AC_CHECK_FUNCS([hasmntopt])
160 if test -z "$ac_list_mounted_fs"; then
162 AC_CACHE_CHECK([for getextmntent function],
163 [fu_cv_sys_mounted_getextmntent],
164 [AC_EGREP_HEADER([getextmntent], [sys/mnttab.h],
165 [fu_cv_sys_mounted_getextmntent=yes],
166 [fu_cv_sys_mounted_getextmntent=no])])
167 if test $fu_cv_sys_mounted_getextmntent = yes; then
168 ac_list_mounted_fs=found
169 AC_DEFINE([MOUNTED_GETEXTMNTENT], [1],
170 [Define if there is a function named getextmntent for reading the list
171 of mounted file systems. (Solaris)])
175 if test -z "$ac_list_mounted_fs"; then
176 # Solaris < 8, also (obsolete) SVR4.
177 # Solaris >= 8 has the two-argument getmntent but is already handled above.
178 AC_CACHE_CHECK([for two-argument getmntent function],
179 [fu_cv_sys_mounted_getmntent2],
180 [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
181 [fu_cv_sys_mounted_getmntent2=yes],
182 [fu_cv_sys_mounted_getmntent2=no])
184 if test $fu_cv_sys_mounted_getmntent2 = yes; then
185 ac_list_mounted_fs=found
186 AC_DEFINE([MOUNTED_GETMNTENT2], [1],
187 [Define if there is a function named getmntent for reading the list of
188 mounted file systems, and that function takes two arguments. (SVR4)])
189 AC_CHECK_FUNCS([hasmntopt])
195 if test -z "$ac_list_mounted_fs"; then
196 # OSF/1, also (obsolete) Apple Darwin 1.3.
197 # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
199 AC_CACHE_CHECK([for getfsstat function],
200 [fu_cv_sys_mounted_getfsstat],
203 #include <sys/types.h>
204 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
205 # define FS_TYPE(Ent) ((Ent).f_fstypename)
207 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
211 [[struct statfs *stats;
212 int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
213 char *t = FS_TYPE (*stats);
215 [fu_cv_sys_mounted_getfsstat=yes],
216 [fu_cv_sys_mounted_getfsstat=no])
218 if test $fu_cv_sys_mounted_getfsstat = yes; then
219 ac_list_mounted_fs=found
220 AC_DEFINE([MOUNTED_GETFSSTAT], [1],
221 [Define if there is a function named getfsstat for reading the
222 list of mounted file systems. (DEC Alpha running OSF/1)])
226 if test -z "$ac_list_mounted_fs"; then
228 AC_CACHE_CHECK([for FIXME existence of three headers],
229 [fu_cv_sys_mounted_fread_fstyp],
230 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
231 #include <sys/statfs.h>
232 #include <sys/fstyp.h>
235 [fu_cv_sys_mounted_fread_fstyp=yes],
236 [fu_cv_sys_mounted_fread_fstyp=no])
238 if test $fu_cv_sys_mounted_fread_fstyp = yes; then
239 ac_list_mounted_fs=found
240 AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
241 [Define if (like SVR2) there is no specific function for reading the
242 list of mounted file systems, and your system has these header files:
243 <sys/fstyp.h> and <sys/statfs.h>. (SVR3)])
247 if test -z "$ac_list_mounted_fs"; then
248 # Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, also (obsolete) 4.4BSD.
249 # OSF/1 also has getmntinfo but is already handled above.
250 # We cannot use AC_CHECK_FUNCS([getmntinfo]) here, because at the linker
251 # level the function is sometimes called getmntinfo64 or getmntinfo$INODE64
252 # on Mac OS X, __getmntinfo13 on NetBSD and Minix, _F64_getmntinfo on OSF/1.
253 AC_CACHE_CHECK([for getmntinfo function],
254 [fu_cv_sys_mounted_getmntinfo],
258 # include <sys/param.h>
260 #include <sys/types.h>
262 # include <sys/mount.h>
264 #if HAVE_SYS_STATVFS_H
265 # include <sys/statvfs.h>
269 [[int count = getmntinfo (NULL, MNT_WAIT);
271 [fu_cv_sys_mounted_getmntinfo=yes],
272 [fu_cv_sys_mounted_getmntinfo=no])
274 if test $fu_cv_sys_mounted_getmntinfo = yes; then
275 AC_CACHE_CHECK([whether getmntinfo returns statvfs structures],
276 [fu_cv_sys_mounted_getmntinfo2],
280 # include <sys/param.h>
282 #include <sys/types.h>
284 # include <sys/mount.h>
286 #if HAVE_SYS_STATVFS_H
287 # include <sys/statvfs.h>
293 int getmntinfo (struct statfs **, int);
295 [fu_cv_sys_mounted_getmntinfo2=no],
296 [fu_cv_sys_mounted_getmntinfo2=yes])
298 if test $fu_cv_sys_mounted_getmntinfo2 = no; then
299 # Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD.
300 ac_list_mounted_fs=found
301 AC_DEFINE([MOUNTED_GETMNTINFO], [1],
302 [Define if there is a function named getmntinfo for reading the
303 list of mounted file systems and it returns an array of
304 'struct statfs'. (4.4BSD, Darwin)])
307 ac_list_mounted_fs=found
308 AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
309 [Define if there is a function named getmntinfo for reading the
310 list of mounted file systems and it returns an array of
311 'struct statvfs'. (NetBSD 3.0)])
316 if test -z "$ac_list_mounted_fs"; then
318 AC_CACHE_CHECK([for getmnt function],
319 [fu_cv_sys_mounted_getmnt],
320 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
321 #include <sys/fs_types.h>
322 #include <sys/mount.h>]])],
323 [fu_cv_sys_mounted_getmnt=yes],
324 [fu_cv_sys_mounted_getmnt=no])
326 if test $fu_cv_sys_mounted_getmnt = yes; then
327 ac_list_mounted_fs=found
328 AC_DEFINE([MOUNTED_GETMNT], [1],
329 [Define if there is a function named getmnt for reading the list of
330 mounted file systems. (Ultrix)])
334 if test -z "$ac_list_mounted_fs"; then
335 # Haiku, also (obsolete) BeOS.
336 AC_CHECK_FUNCS([next_dev fs_stat_dev])
337 AC_CHECK_HEADERS([fs_info.h])
338 AC_CACHE_CHECK([for BEOS mounted file system support functions],
339 [fu_cv_sys_mounted_fs_stat_dev],
340 [if test $ac_cv_header_fs_info_h = yes \
341 && test $ac_cv_func_next_dev = yes \
342 && test $ac_cv_func_fs_stat_dev = yes; then
343 fu_cv_sys_mounted_fs_stat_dev=yes
345 fu_cv_sys_mounted_fs_stat_dev=no
348 if test $fu_cv_sys_mounted_fs_stat_dev = yes; then
349 ac_list_mounted_fs=found
350 AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
351 [Define if there are functions named next_dev and fs_stat_dev for
352 reading the list of mounted file systems. (BeOS)])
356 if test -z "$ac_list_mounted_fs"; then
358 AC_CACHE_CHECK([whether it is possible to resort to fread on /etc/mnttab],
359 [fu_cv_sys_mounted_fread],
360 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <mnttab.h>]])],
361 [fu_cv_sys_mounted_fread=yes],
362 [fu_cv_sys_mounted_fread=no])
364 if test $fu_cv_sys_mounted_fread = yes; then
365 ac_list_mounted_fs=found
366 AC_DEFINE([MOUNTED_FREAD], [1],
367 [Define if there is no specific function for reading the list of
368 mounted file systems. fread will be used to read /etc/mnttab.
373 if test -z "$ac_list_mounted_fs"; then
374 # Interix / BSD alike statvfs
375 # the code is really interix specific, so make sure, we're on it.
378 AC_CHECK_FUNCS([statvfs])
379 if test $ac_cv_func_statvfs = yes; then
380 ac_list_mounted_fs=found
381 AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
382 [Define if we are on interix, and ought to use statvfs plus
383 some special knowledge on where mounted file systems can be
390 if test -z "$ac_list_mounted_fs"; then
391 AC_MSG_ERROR([could not determine how to read list of mounted file systems])
392 # FIXME -- no need to abort building the whole package
393 # Can't build mountlist.c or anything that needs its functions
396 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])