3 dnl Copyright (C) 2002-2006, 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
12 AC_DEFUN([gl_MOUNTLIST],
14 AC_REQUIRE([AC_CANONICAL_HOST])
15 AC_CHECK_FUNCS([listmntent])
16 AC_CHECK_HEADERS_ONCE([sys/param.h sys/statvfs.h])
18 # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses
19 # NGROUPS (as the array dimension for a struct member) without a definition.
20 AC_CHECK_HEADERS([sys/ucred.h], [], [], [#include <grp.h>])
22 AC_CHECK_HEADERS([sys/mount.h], [], [],
25 #include <sys/param.h>
29 AC_CHECK_HEADERS([mntent.h sys/fs_types.h])
33 # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
36 # include <grp.h> /* needed for definition of NGROUPS */
37 # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
40 # include <sys/mount.h>
42 #if HAVE_SYS_FS_TYPES_H
43 # include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
46 AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
48 # Determine how to get the list of mounted file systems.
51 # If the getmntent function is available but not in the standard library,
52 # make sure LIBS contains the appropriate -l option.
55 if test -z "$ac_list_mounted_fs"; then
57 AC_CACHE_CHECK([for mntctl function and struct vmount],
58 [fu_cv_sys_mounted_vmount],
59 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <fshelp.h>]])],
60 [fu_cv_sys_mounted_vmount=yes],
61 [fu_cv_sys_mounted_vmount=no])])
62 if test $fu_cv_sys_mounted_vmount = yes; then
63 ac_list_mounted_fs=found
64 AC_DEFINE([MOUNTED_VMOUNT], [1],
65 [Define if there is a function named mntctl that can be used to read
66 the list of mounted file systems, and there is a system header file
67 that declares 'struct vmount'. (AIX)])
71 if test $ac_cv_func_getmntent = yes; then
73 # This system has the getmntent function.
74 # Determine whether it's the one-argument variant or the two-argument one.
76 if test -z "$ac_list_mounted_fs"; then
77 # glibc, HP-UX, IRIX, Cygwin, Android, also (obsolete) 4.3BSD, SunOS.
78 AC_CACHE_CHECK([for one-argument getmntent function],
79 [fu_cv_sys_mounted_getmntent1],
82 /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
86 #if defined __ANDROID__ /* Android */
88 # define MOUNTED "/proc/mounts"
89 #elif !defined MOUNTED
90 # if defined _PATH_MOUNTED /* GNU libc */
91 # define MOUNTED _PATH_MOUNTED
93 # if defined MNT_MNTTAB /* HP-UX. */
94 # define MOUNTED MNT_MNTTAB
98 [[struct mntent *mnt = 0; char *table = MOUNTED;
99 if (sizeof mnt && sizeof table) return 0;
101 [fu_cv_sys_mounted_getmntent1=yes],
102 [fu_cv_sys_mounted_getmntent1=no])
104 if test $fu_cv_sys_mounted_getmntent1 = yes; then
105 ac_list_mounted_fs=found
106 AC_DEFINE([MOUNTED_GETMNTENT1], [1],
107 [Define if there is a function named getmntent for reading the list
108 of mounted file systems, and that function takes a single argument.
109 (4.3BSD, SunOS, HP-UX, Irix)])
110 gl_CHECK_FUNCS_ANDROID([setmntent],
114 gl_CHECK_FUNCS_ANDROID([endmntent],
118 gl_CHECK_FUNCS_ANDROID([hasmntopt],
125 if test -z "$ac_list_mounted_fs"; then
127 AC_CACHE_CHECK([for getextmntent function],
128 [fu_cv_sys_mounted_getextmntent],
129 [AC_EGREP_HEADER([getextmntent], [sys/mnttab.h],
130 [fu_cv_sys_mounted_getextmntent=yes],
131 [fu_cv_sys_mounted_getextmntent=no])])
132 if test $fu_cv_sys_mounted_getextmntent = yes; then
133 ac_list_mounted_fs=found
134 AC_DEFINE([MOUNTED_GETEXTMNTENT], [1],
135 [Define if there is a function named getextmntent for reading the list
136 of mounted file systems. (Solaris)])
140 if test -z "$ac_list_mounted_fs"; then
141 # Solaris < 8, also (obsolete) SVR4.
142 # Solaris >= 8 has the two-argument getmntent but is already handled above.
143 AC_CACHE_CHECK([for two-argument getmntent function],
144 [fu_cv_sys_mounted_getmntent2],
145 [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
146 [fu_cv_sys_mounted_getmntent2=yes],
147 [fu_cv_sys_mounted_getmntent2=no])
149 if test $fu_cv_sys_mounted_getmntent2 = yes; then
150 ac_list_mounted_fs=found
151 AC_DEFINE([MOUNTED_GETMNTENT2], [1],
152 [Define if there is a function named getmntent for reading the list of
153 mounted file systems, and that function takes two arguments. (SVR4)])
154 AC_CHECK_FUNCS([hasmntopt])
160 if test -z "$ac_list_mounted_fs"; then
161 # OSF/1, also (obsolete) Apple Darwin 1.3.
162 # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
164 AC_CACHE_CHECK([for getfsstat function],
165 [fu_cv_sys_mounted_getfsstat],
168 #include <sys/types.h>
169 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
170 # define FS_TYPE(Ent) ((Ent).f_fstypename)
172 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
176 [[struct statfs *stats;
177 int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
178 char *t = FS_TYPE (*stats);
180 [fu_cv_sys_mounted_getfsstat=yes],
181 [fu_cv_sys_mounted_getfsstat=no])
183 if test $fu_cv_sys_mounted_getfsstat = yes; then
184 ac_list_mounted_fs=found
185 AC_DEFINE([MOUNTED_GETFSSTAT], [1],
186 [Define if there is a function named getfsstat for reading the
187 list of mounted file systems. (DEC Alpha running OSF/1)])
191 if test -z "$ac_list_mounted_fs"; then
193 AC_CACHE_CHECK([for FIXME existence of three headers],
194 [fu_cv_sys_mounted_fread_fstyp],
195 [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
196 #include <sys/statfs.h>
197 #include <sys/fstyp.h>
200 [fu_cv_sys_mounted_fread_fstyp=yes],
201 [fu_cv_sys_mounted_fread_fstyp=no])
203 if test $fu_cv_sys_mounted_fread_fstyp = yes; then
204 ac_list_mounted_fs=found
205 AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
206 [Define if (like SVR2) there is no specific function for reading the
207 list of mounted file systems, and your system has these header files:
208 <sys/fstyp.h> and <sys/statfs.h>. (SVR3)])
212 if test -z "$ac_list_mounted_fs"; then
213 # Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, also (obsolete) 4.4BSD.
214 # OSF/1 also has getmntinfo but is already handled above.
215 # We cannot use AC_CHECK_FUNCS([getmntinfo]) here, because at the linker
216 # level the function is sometimes called getmntinfo64 or getmntinfo$INODE64
217 # on Mac OS X, __getmntinfo13 on NetBSD and Minix, _F64_getmntinfo on OSF/1.
218 AC_CACHE_CHECK([for getmntinfo function],
219 [fu_cv_sys_mounted_getmntinfo],
223 # include <sys/param.h>
225 #include <sys/types.h>
227 # include <sys/mount.h>
229 #if HAVE_SYS_STATVFS_H
230 # include <sys/statvfs.h>
234 [[int count = getmntinfo (NULL, MNT_WAIT);
236 [fu_cv_sys_mounted_getmntinfo=yes],
237 [fu_cv_sys_mounted_getmntinfo=no])
239 if test $fu_cv_sys_mounted_getmntinfo = yes; then
240 AC_CACHE_CHECK([whether getmntinfo returns statvfs structures],
241 [fu_cv_sys_mounted_getmntinfo2],
245 # include <sys/param.h>
247 #include <sys/types.h>
249 # include <sys/mount.h>
251 #if HAVE_SYS_STATVFS_H
252 # include <sys/statvfs.h>
258 int getmntinfo (struct statfs **, int);
260 [fu_cv_sys_mounted_getmntinfo2=no],
261 [fu_cv_sys_mounted_getmntinfo2=yes])
263 if test $fu_cv_sys_mounted_getmntinfo2 = no; then
264 # Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD.
265 ac_list_mounted_fs=found
266 AC_DEFINE([MOUNTED_GETMNTINFO], [1],
267 [Define if there is a function named getmntinfo for reading the
268 list of mounted file systems and it returns an array of
269 'struct statfs'. (4.4BSD, Darwin)])
272 ac_list_mounted_fs=found
273 AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
274 [Define if there is a function named getmntinfo for reading the
275 list of mounted file systems and it returns an array of
276 'struct statvfs'. (NetBSD 3.0)])
281 if test -z "$ac_list_mounted_fs"; then
282 # Haiku, also (obsolete) BeOS.
283 AC_CHECK_FUNCS([next_dev fs_stat_dev])
284 AC_CHECK_HEADERS([fs_info.h])
285 AC_CACHE_CHECK([for BEOS mounted file system support functions],
286 [fu_cv_sys_mounted_fs_stat_dev],
287 [if test $ac_cv_header_fs_info_h = yes \
288 && test $ac_cv_func_next_dev = yes \
289 && test $ac_cv_func_fs_stat_dev = yes; then
290 fu_cv_sys_mounted_fs_stat_dev=yes
292 fu_cv_sys_mounted_fs_stat_dev=no
295 if test $fu_cv_sys_mounted_fs_stat_dev = yes; then
296 ac_list_mounted_fs=found
297 AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
298 [Define if there are functions named next_dev and fs_stat_dev for
299 reading the list of mounted file systems. (BeOS)])
303 if test -z "$ac_list_mounted_fs"; then
304 # Interix / BSD alike statvfs
305 # the code is really interix specific, so make sure, we're on it.
308 AC_CHECK_FUNCS([statvfs])
309 if test $ac_cv_func_statvfs = yes; then
310 ac_list_mounted_fs=found
311 AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
312 [Define if we are on interix, and ought to use statvfs plus
313 some special knowledge on where mounted file systems can be
320 if test -z "$ac_list_mounted_fs"; then
321 AC_MSG_ERROR([could not determine how to read list of mounted file systems])
322 # FIXME -- no need to abort building the whole package
323 # Can't build mountlist.c or anything that needs its functions
326 if test $ac_list_mounted_fs = found; then
327 gl_cv_list_mounted_fs=yes
329 gl_cv_list_mounted_fs=no
333 # Prerequisites of lib/mountlist.c not done by gl_MOUNTLIST.
334 AC_DEFUN([gl_PREREQ_MOUNTLIST_EXTRA],
336 dnl Note gl_MOUNTLIST checks for mntent.h, not sys/mntent.h.
337 AC_CHECK_HEADERS([sys/mntent.h])
338 AC_HEADER_MAJOR()dnl for use of makedev ()
342 # Replace Autoconf's AC_FUNC_GETMNTENT to omit checks that are unnecessary
344 AC_DEFUN([AC_FUNC_GETMNTENT],
346 # getmntent is in the standard C library on most systems, but in -lgen on
348 AC_SEARCH_LIBS([getmntent], [gen])
349 AC_CHECK_FUNCS([getmntent])