2 # How to list mounted file systems.
4 # Copyright (C) 1998-2004, 2006, 2009-2019 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.
14 dnl This is not pretty. I've just taken the autoconf code and wrapped
15 dnl it in an AC_DEFUN and made some other fixes.
17 # Replace Autoconf's AC_FUNC_GETMNTENT to omit checks that are unnecessary
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 if test -z "$ac_list_mounted_fs"; then
73 AC_CACHE_CHECK([for mntctl function and struct vmount],
74 [fu_cv_sys_mounted_vmount],
75 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <fshelp.h>]])],
76 [fu_cv_sys_mounted_vmount=yes],
77 [fu_cv_sys_mounted_vmount=no])])
78 if test $fu_cv_sys_mounted_vmount = yes; then
79 ac_list_mounted_fs=found
80 AC_DEFINE([MOUNTED_VMOUNT], [1],
81 [Define if there is a function named mntctl that can be used to read
82 the list of mounted file systems, and there is a system header file
83 that declares 'struct vmount'. (AIX)])
87 if test $ac_cv_func_getmntent = yes; then
89 # This system has the getmntent function.
90 # Determine whether it's the one-argument variant or the two-argument one.
92 if test -z "$ac_list_mounted_fs"; then
93 # glibc, HP-UX, IRIX, Cygwin, Android, also (obsolete) 4.3BSD, SunOS.
94 AC_CACHE_CHECK([for one-argument getmntent function],
95 [fu_cv_sys_mounted_getmntent1],
98 /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
103 # if defined _PATH_MOUNTED /* GNU libc */
104 # define MOUNTED _PATH_MOUNTED
106 # if defined MNT_MNTTAB /* HP-UX. */
107 # define MOUNTED MNT_MNTTAB
111 [[struct mntent *mnt = 0; char *table = MOUNTED;
112 if (sizeof mnt && sizeof table) return 0;
114 [fu_cv_sys_mounted_getmntent1=yes],
115 [fu_cv_sys_mounted_getmntent1=no])
117 if test $fu_cv_sys_mounted_getmntent1 = yes; then
118 ac_list_mounted_fs=found
119 AC_DEFINE([MOUNTED_GETMNTENT1], [1],
120 [Define if there is a function named getmntent for reading the list
121 of mounted file systems, and that function takes a single argument.
122 (4.3BSD, SunOS, HP-UX, Irix)])
123 AC_CHECK_FUNCS([hasmntopt])
127 if test -z "$ac_list_mounted_fs"; then
129 AC_CACHE_CHECK([for getextmntent function],
130 [fu_cv_sys_mounted_getextmntent],
131 [AC_EGREP_HEADER([getextmntent], [sys/mnttab.h],
132 [fu_cv_sys_mounted_getextmntent=yes],
133 [fu_cv_sys_mounted_getextmntent=no])])
134 if test $fu_cv_sys_mounted_getextmntent = yes; then
135 ac_list_mounted_fs=found
136 AC_DEFINE([MOUNTED_GETEXTMNTENT], [1],
137 [Define if there is a function named getextmntent for reading the list
138 of mounted file systems. (Solaris)])
142 if test -z "$ac_list_mounted_fs"; then
143 # Solaris < 8, also (obsolete) SVR4.
144 # Solaris >= 8 has the two-argument getmntent but is already handled above.
145 AC_CACHE_CHECK([for two-argument getmntent function],
146 [fu_cv_sys_mounted_getmntent2],
147 [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
148 [fu_cv_sys_mounted_getmntent2=yes],
149 [fu_cv_sys_mounted_getmntent2=no])
151 if test $fu_cv_sys_mounted_getmntent2 = yes; then
152 ac_list_mounted_fs=found
153 AC_DEFINE([MOUNTED_GETMNTENT2], [1],
154 [Define if there is a function named getmntent for reading the list of
155 mounted file systems, and that function takes two arguments. (SVR4)])
156 AC_CHECK_FUNCS([hasmntopt])
162 if test -z "$ac_list_mounted_fs"; then
163 # OSF/1, also (obsolete) Apple Darwin 1.3.
164 # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
166 AC_CACHE_CHECK([for getfsstat function],
167 [fu_cv_sys_mounted_getfsstat],
170 #include <sys/types.h>
171 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
172 # define FS_TYPE(Ent) ((Ent).f_fstypename)
174 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
178 [[struct statfs *stats;
179 int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
180 char *t = FS_TYPE (*stats);
182 [fu_cv_sys_mounted_getfsstat=yes],
183 [fu_cv_sys_mounted_getfsstat=no])
185 if test $fu_cv_sys_mounted_getfsstat = yes; then
186 ac_list_mounted_fs=found
187 AC_DEFINE([MOUNTED_GETFSSTAT], [1],
188 [Define if there is a function named getfsstat for reading the
189 list of mounted file systems. (DEC Alpha running OSF/1)])
193 if test -z "$ac_list_mounted_fs"; then
195 AC_CACHE_CHECK([for FIXME existence of three headers],
196 [fu_cv_sys_mounted_fread_fstyp],
197 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
198 #include <sys/statfs.h>
199 #include <sys/fstyp.h>
202 [fu_cv_sys_mounted_fread_fstyp=yes],
203 [fu_cv_sys_mounted_fread_fstyp=no])
205 if test $fu_cv_sys_mounted_fread_fstyp = yes; then
206 ac_list_mounted_fs=found
207 AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
208 [Define if (like SVR2) there is no specific function for reading the
209 list of mounted file systems, and your system has these header files:
210 <sys/fstyp.h> and <sys/statfs.h>. (SVR3)])
214 if test -z "$ac_list_mounted_fs"; then
215 # Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, also (obsolete) 4.4BSD.
216 # OSF/1 also has getmntinfo but is already handled above.
217 # We cannot use AC_CHECK_FUNCS([getmntinfo]) here, because at the linker
218 # level the function is sometimes called getmntinfo64 or getmntinfo$INODE64
219 # on Mac OS X, __getmntinfo13 on NetBSD and Minix, _F64_getmntinfo on OSF/1.
220 AC_CACHE_CHECK([for getmntinfo function],
221 [fu_cv_sys_mounted_getmntinfo],
225 # include <sys/param.h>
227 #include <sys/types.h>
229 # include <sys/mount.h>
231 #if HAVE_SYS_STATVFS_H
232 # include <sys/statvfs.h>
236 [[int count = getmntinfo (NULL, MNT_WAIT);
238 [fu_cv_sys_mounted_getmntinfo=yes],
239 [fu_cv_sys_mounted_getmntinfo=no])
241 if test $fu_cv_sys_mounted_getmntinfo = yes; then
242 AC_CACHE_CHECK([whether getmntinfo returns statvfs structures],
243 [fu_cv_sys_mounted_getmntinfo2],
247 # include <sys/param.h>
249 #include <sys/types.h>
251 # include <sys/mount.h>
253 #if HAVE_SYS_STATVFS_H
254 # include <sys/statvfs.h>
260 int getmntinfo (struct statfs **, int);
262 [fu_cv_sys_mounted_getmntinfo2=no],
263 [fu_cv_sys_mounted_getmntinfo2=yes])
265 if test $fu_cv_sys_mounted_getmntinfo2 = no; then
266 # Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD.
267 ac_list_mounted_fs=found
268 AC_DEFINE([MOUNTED_GETMNTINFO], [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 statfs'. (4.4BSD, Darwin)])
274 ac_list_mounted_fs=found
275 AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
276 [Define if there is a function named getmntinfo for reading the
277 list of mounted file systems and it returns an array of
278 'struct statvfs'. (NetBSD 3.0)])
283 if test -z "$ac_list_mounted_fs"; then
284 # Haiku, also (obsolete) BeOS.
285 AC_CHECK_FUNCS([next_dev fs_stat_dev])
286 AC_CHECK_HEADERS([fs_info.h])
287 AC_CACHE_CHECK([for BEOS mounted file system support functions],
288 [fu_cv_sys_mounted_fs_stat_dev],
289 [if test $ac_cv_header_fs_info_h = yes \
290 && test $ac_cv_func_next_dev = yes \
291 && test $ac_cv_func_fs_stat_dev = yes; then
292 fu_cv_sys_mounted_fs_stat_dev=yes
294 fu_cv_sys_mounted_fs_stat_dev=no
297 if test $fu_cv_sys_mounted_fs_stat_dev = yes; then
298 ac_list_mounted_fs=found
299 AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
300 [Define if there are functions named next_dev and fs_stat_dev for
301 reading the list of mounted file systems. (BeOS)])
305 if test -z "$ac_list_mounted_fs"; then
306 # Interix / BSD alike statvfs
307 # the code is really interix specific, so make sure, we're on it.
310 AC_CHECK_FUNCS([statvfs])
311 if test $ac_cv_func_statvfs = yes; then
312 ac_list_mounted_fs=found
313 AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
314 [Define if we are on interix, and ought to use statvfs plus
315 some special knowledge on where mounted file systems can be
322 if test -z "$ac_list_mounted_fs"; then
323 AC_MSG_ERROR([could not determine how to read list of mounted file systems])
324 # FIXME -- no need to abort building the whole package
325 # Can't build mountlist.c or anything that needs its functions
328 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])