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 */
102 #if defined __ANDROID__ /* Android */
104 # define MOUNTED "/proc/mounts"
105 #elif !defined MOUNTED
106 # if defined _PATH_MOUNTED /* GNU libc */
107 # define MOUNTED _PATH_MOUNTED
109 # if defined MNT_MNTTAB /* HP-UX. */
110 # define MOUNTED MNT_MNTTAB
114 [[struct mntent *mnt = 0; char *table = MOUNTED;
115 if (sizeof mnt && sizeof table) return 0;
117 [fu_cv_sys_mounted_getmntent1=yes],
118 [fu_cv_sys_mounted_getmntent1=no])
120 if test $fu_cv_sys_mounted_getmntent1 = yes; then
121 ac_list_mounted_fs=found
122 AC_DEFINE([MOUNTED_GETMNTENT1], [1],
123 [Define if there is a function named getmntent for reading the list
124 of mounted file systems, and that function takes a single argument.
125 (4.3BSD, SunOS, HP-UX, Irix)])
126 AC_CHECK_FUNCS([setmntent endmntent hasmntopt])
130 if test -z "$ac_list_mounted_fs"; then
132 AC_CACHE_CHECK([for getextmntent function],
133 [fu_cv_sys_mounted_getextmntent],
134 [AC_EGREP_HEADER([getextmntent], [sys/mnttab.h],
135 [fu_cv_sys_mounted_getextmntent=yes],
136 [fu_cv_sys_mounted_getextmntent=no])])
137 if test $fu_cv_sys_mounted_getextmntent = yes; then
138 ac_list_mounted_fs=found
139 AC_DEFINE([MOUNTED_GETEXTMNTENT], [1],
140 [Define if there is a function named getextmntent for reading the list
141 of mounted file systems. (Solaris)])
145 if test -z "$ac_list_mounted_fs"; then
146 # Solaris < 8, also (obsolete) SVR4.
147 # Solaris >= 8 has the two-argument getmntent but is already handled above.
148 AC_CACHE_CHECK([for two-argument getmntent function],
149 [fu_cv_sys_mounted_getmntent2],
150 [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
151 [fu_cv_sys_mounted_getmntent2=yes],
152 [fu_cv_sys_mounted_getmntent2=no])
154 if test $fu_cv_sys_mounted_getmntent2 = yes; then
155 ac_list_mounted_fs=found
156 AC_DEFINE([MOUNTED_GETMNTENT2], [1],
157 [Define if there is a function named getmntent for reading the list of
158 mounted file systems, and that function takes two arguments. (SVR4)])
159 AC_CHECK_FUNCS([hasmntopt])
165 if test -z "$ac_list_mounted_fs"; then
166 # OSF/1, also (obsolete) Apple Darwin 1.3.
167 # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
169 AC_CACHE_CHECK([for getfsstat function],
170 [fu_cv_sys_mounted_getfsstat],
173 #include <sys/types.h>
174 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
175 # define FS_TYPE(Ent) ((Ent).f_fstypename)
177 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
181 [[struct statfs *stats;
182 int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
183 char *t = FS_TYPE (*stats);
185 [fu_cv_sys_mounted_getfsstat=yes],
186 [fu_cv_sys_mounted_getfsstat=no])
188 if test $fu_cv_sys_mounted_getfsstat = yes; then
189 ac_list_mounted_fs=found
190 AC_DEFINE([MOUNTED_GETFSSTAT], [1],
191 [Define if there is a function named getfsstat for reading the
192 list of mounted file systems. (DEC Alpha running OSF/1)])
196 if test -z "$ac_list_mounted_fs"; then
198 AC_CACHE_CHECK([for FIXME existence of three headers],
199 [fu_cv_sys_mounted_fread_fstyp],
200 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
201 #include <sys/statfs.h>
202 #include <sys/fstyp.h>
205 [fu_cv_sys_mounted_fread_fstyp=yes],
206 [fu_cv_sys_mounted_fread_fstyp=no])
208 if test $fu_cv_sys_mounted_fread_fstyp = yes; then
209 ac_list_mounted_fs=found
210 AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
211 [Define if (like SVR2) there is no specific function for reading the
212 list of mounted file systems, and your system has these header files:
213 <sys/fstyp.h> and <sys/statfs.h>. (SVR3)])
217 if test -z "$ac_list_mounted_fs"; then
218 # Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, also (obsolete) 4.4BSD.
219 # OSF/1 also has getmntinfo but is already handled above.
220 # We cannot use AC_CHECK_FUNCS([getmntinfo]) here, because at the linker
221 # level the function is sometimes called getmntinfo64 or getmntinfo$INODE64
222 # on Mac OS X, __getmntinfo13 on NetBSD and Minix, _F64_getmntinfo on OSF/1.
223 AC_CACHE_CHECK([for getmntinfo function],
224 [fu_cv_sys_mounted_getmntinfo],
228 # include <sys/param.h>
230 #include <sys/types.h>
232 # include <sys/mount.h>
234 #if HAVE_SYS_STATVFS_H
235 # include <sys/statvfs.h>
239 [[int count = getmntinfo (NULL, MNT_WAIT);
241 [fu_cv_sys_mounted_getmntinfo=yes],
242 [fu_cv_sys_mounted_getmntinfo=no])
244 if test $fu_cv_sys_mounted_getmntinfo = yes; then
245 AC_CACHE_CHECK([whether getmntinfo returns statvfs structures],
246 [fu_cv_sys_mounted_getmntinfo2],
250 # include <sys/param.h>
252 #include <sys/types.h>
254 # include <sys/mount.h>
256 #if HAVE_SYS_STATVFS_H
257 # include <sys/statvfs.h>
263 int getmntinfo (struct statfs **, int);
265 [fu_cv_sys_mounted_getmntinfo2=no],
266 [fu_cv_sys_mounted_getmntinfo2=yes])
268 if test $fu_cv_sys_mounted_getmntinfo2 = no; then
269 # Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD.
270 ac_list_mounted_fs=found
271 AC_DEFINE([MOUNTED_GETMNTINFO], [1],
272 [Define if there is a function named getmntinfo for reading the
273 list of mounted file systems and it returns an array of
274 'struct statfs'. (4.4BSD, Darwin)])
277 ac_list_mounted_fs=found
278 AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
279 [Define if there is a function named getmntinfo for reading the
280 list of mounted file systems and it returns an array of
281 'struct statvfs'. (NetBSD 3.0)])
286 if test -z "$ac_list_mounted_fs"; then
287 # Haiku, also (obsolete) BeOS.
288 AC_CHECK_FUNCS([next_dev fs_stat_dev])
289 AC_CHECK_HEADERS([fs_info.h])
290 AC_CACHE_CHECK([for BEOS mounted file system support functions],
291 [fu_cv_sys_mounted_fs_stat_dev],
292 [if test $ac_cv_header_fs_info_h = yes \
293 && test $ac_cv_func_next_dev = yes \
294 && test $ac_cv_func_fs_stat_dev = yes; then
295 fu_cv_sys_mounted_fs_stat_dev=yes
297 fu_cv_sys_mounted_fs_stat_dev=no
300 if test $fu_cv_sys_mounted_fs_stat_dev = yes; then
301 ac_list_mounted_fs=found
302 AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
303 [Define if there are functions named next_dev and fs_stat_dev for
304 reading the list of mounted file systems. (BeOS)])
308 if test -z "$ac_list_mounted_fs"; then
309 # Interix / BSD alike statvfs
310 # the code is really interix specific, so make sure, we're on it.
313 AC_CHECK_FUNCS([statvfs])
314 if test $ac_cv_func_statvfs = yes; then
315 ac_list_mounted_fs=found
316 AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
317 [Define if we are on interix, and ought to use statvfs plus
318 some special knowledge on where mounted file systems can be
325 if test -z "$ac_list_mounted_fs"; then
326 AC_MSG_ERROR([could not determine how to read list of mounted file systems])
327 # FIXME -- no need to abort building the whole package
328 # Can't build mountlist.c or anything that needs its functions
331 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])