2 # How to list mounted file systems.
4 # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software Foundation,
19 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 dnl From Jim Meyering.
23 dnl This is not pretty. I've just taken the autoconf code and wrapped
24 dnl it in an AC_DEFUN and made some other fixes.
27 # Replace Autoconf's AC_FUNC_GETMNTENT to work around a bug in Autoconf
28 # through Autoconf 2.59. We can remove this once we assume Autoconf 2.60
30 AC_DEFUN([AC_FUNC_GETMNTENT],
31 [# getmntent is in the standard C library on UNICOS, in -lsun on Irix 4,
32 # -lseq on Dynix/PTX, -lgen on Unixware.
33 AC_SEARCH_LIBS(getmntent, [sun seq gen], [AC_CHECK_FUNCS(getmntent)])
36 # gl_LIST_MOUNTED_FILE_SYSTEMS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
37 AC_DEFUN([gl_LIST_MOUNTED_FILE_SYSTEMS],
39 AC_CHECK_FUNCS(listmntent getmntinfo)
40 AC_CHECK_HEADERS_ONCE(sys/param.h)
42 # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses
43 # NGROUPS (as the array dimension for a struct member) without a definition.
44 AC_CHECK_HEADERS(sys/ucred.h, [], [], [#include <grp.h>])
46 AC_CHECK_HEADERS(sys/mount.h, [], [],
49 #include <sys/param.h>
52 AC_CHECK_HEADERS(mntent.h sys/fs_types.h)
56 # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
59 # include <grp.h> /* needed for definition of NGROUPS */
60 # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
63 # include <sys/mount.h>
65 #if HAVE_SYS_FS_TYPES_H
66 # include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
69 AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
71 # Determine how to get the list of mounted file systems.
74 # If the getmntent function is available but not in the standard library,
75 # make sure LIBS contains the appropriate -l option.
78 # This test must precede the ones for getmntent because Unicos-9 is
79 # reported to have the getmntent function, but its support is incompatible
80 # with other getmntent implementations.
82 # NOTE: Normally, I wouldn't use a check for system type as I've done for
83 # `CRAY' below since that goes against the whole autoconf philosophy. But
84 # I think there is too great a chance that some non-Cray system has a
85 # function named listmntent to risk the false positive.
87 if test -z "$ac_list_mounted_fs"; then
89 AC_MSG_CHECKING([for listmntent of Cray/Unicos-9])
90 AC_CACHE_VAL(fu_cv_sys_mounted_cray_listmntent,
91 [fu_cv_sys_mounted_cray_listmntent=no
96 ], [test $ac_cv_func_listmntent = yes \
97 && fu_cv_sys_mounted_cray_listmntent=yes]
101 AC_MSG_RESULT($fu_cv_sys_mounted_cray_listmntent)
102 if test $fu_cv_sys_mounted_cray_listmntent = yes; then
103 ac_list_mounted_fs=found
104 AC_DEFINE(MOUNTED_LISTMNTENT, 1,
105 [Define if there is a function named listmntent that can be used to
106 list all mounted file systems. (UNICOS)])
110 if test -z "$ac_list_mounted_fs"; then
112 AC_MSG_CHECKING([for mntctl function and struct vmount])
113 AC_CACHE_VAL(fu_cv_sys_mounted_vmount,
114 [AC_TRY_CPP([#include <fshelp.h>],
115 fu_cv_sys_mounted_vmount=yes,
116 fu_cv_sys_mounted_vmount=no)])
117 AC_MSG_RESULT($fu_cv_sys_mounted_vmount)
118 if test $fu_cv_sys_mounted_vmount = yes; then
119 ac_list_mounted_fs=found
120 AC_DEFINE(MOUNTED_VMOUNT, 1,
121 [Define if there is a function named mntctl that can be used to read
122 the list of mounted file systems, and there is a system header file
123 that declares `struct vmount.' (AIX)])
127 if test $ac_cv_func_getmntent = yes; then
129 # This system has the getmntent function.
130 # Determine whether it's the one-argument variant or the two-argument one.
132 if test -z "$ac_list_mounted_fs"; then
133 # 4.3BSD, SunOS, HP-UX, Dynix, Irix
134 AC_MSG_CHECKING([for one-argument getmntent function])
135 AC_CACHE_VAL(fu_cv_sys_mounted_getmntent1,
137 /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
142 # if defined _PATH_MOUNTED /* GNU libc */
143 # define MOUNTED _PATH_MOUNTED
145 # if defined MNT_MNTTAB /* HP-UX. */
146 # define MOUNTED MNT_MNTTAB
148 # if defined MNTTABNAME /* Dynix. */
149 # define MOUNTED MNTTABNAME
153 [ struct mntent *mnt = 0; char *table = MOUNTED; ],
154 fu_cv_sys_mounted_getmntent1=yes,
155 fu_cv_sys_mounted_getmntent1=no)])
156 AC_MSG_RESULT($fu_cv_sys_mounted_getmntent1)
157 if test $fu_cv_sys_mounted_getmntent1 = yes; then
158 ac_list_mounted_fs=found
159 AC_DEFINE(MOUNTED_GETMNTENT1, 1,
160 [Define if there is a function named getmntent for reading the list
161 of mounted file systems, and that function takes a single argument.
162 (4.3BSD, SunOS, HP-UX, Dynix, Irix)])
166 if test -z "$ac_list_mounted_fs"; then
168 AC_MSG_CHECKING([for two-argument getmntent function])
169 AC_CACHE_VAL(fu_cv_sys_mounted_getmntent2,
170 [AC_EGREP_HEADER(getmntent, sys/mnttab.h,
171 fu_cv_sys_mounted_getmntent2=yes,
172 fu_cv_sys_mounted_getmntent2=no)])
173 AC_MSG_RESULT($fu_cv_sys_mounted_getmntent2)
174 if test $fu_cv_sys_mounted_getmntent2 = yes; then
175 ac_list_mounted_fs=found
176 AC_DEFINE(MOUNTED_GETMNTENT2, 1,
177 [Define if there is a function named getmntent for reading the list of
178 mounted file systems, and that function takes two arguments. (SVR4)])
184 if test -z "$ac_list_mounted_fs"; then
185 # DEC Alpha running OSF/1, and Apple Darwin 1.3.
186 # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
188 AC_MSG_CHECKING([for getfsstat function])
189 AC_CACHE_VAL(fu_cv_sys_mounted_getfsstat,
191 #include <sys/types.h>
192 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
193 # define FS_TYPE(Ent) ((Ent).f_fstypename)
195 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
199 [struct statfs *stats;
200 int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
201 char *t = FS_TYPE (*stats); ],
202 fu_cv_sys_mounted_getfsstat=yes,
203 fu_cv_sys_mounted_getfsstat=no)])
204 AC_MSG_RESULT($fu_cv_sys_mounted_getfsstat)
205 if test $fu_cv_sys_mounted_getfsstat = yes; then
206 ac_list_mounted_fs=found
207 AC_DEFINE(MOUNTED_GETFSSTAT, 1,
208 [Define if there is a function named getfsstat for reading the
209 list of mounted file systems. (DEC Alpha running OSF/1)])
213 if test -z "$ac_list_mounted_fs"; then
215 AC_MSG_CHECKING([for FIXME existence of three headers])
216 AC_CACHE_VAL(fu_cv_sys_mounted_fread_fstyp,
218 #include <sys/statfs.h>
219 #include <sys/fstyp.h>
220 #include <mnttab.h>],
221 fu_cv_sys_mounted_fread_fstyp=yes,
222 fu_cv_sys_mounted_fread_fstyp=no)])
223 AC_MSG_RESULT($fu_cv_sys_mounted_fread_fstyp)
224 if test $fu_cv_sys_mounted_fread_fstyp = yes; then
225 ac_list_mounted_fs=found
226 AC_DEFINE(MOUNTED_FREAD_FSTYP, 1,
227 [Define if (like SVR2) there is no specific function for reading the
228 list of mounted file systems, and your system has these header files:
229 <sys/fstyp.h> and <sys/statfs.h>. (SVR3)])
233 if test -z "$ac_list_mounted_fs"; then
234 # 4.4BSD and DEC OSF/1.
235 AC_MSG_CHECKING([for getmntinfo function])
236 AC_CACHE_VAL(fu_cv_sys_mounted_getmntinfo,
238 test "$ac_cv_func_getmntinfo" = yes \
239 && fu_cv_sys_mounted_getmntinfo=yes \
240 || fu_cv_sys_mounted_getmntinfo=no
242 AC_MSG_RESULT($fu_cv_sys_mounted_getmntinfo)
243 if test $fu_cv_sys_mounted_getmntinfo = yes; then
244 ac_list_mounted_fs=found
245 AC_DEFINE(MOUNTED_GETMNTINFO, 1,
246 [Define if there is a function named getmntinfo for reading the
247 list of mounted file systems. (4.4BSD, Darwin)])
251 if test -z "$ac_list_mounted_fs"; then
253 AC_MSG_CHECKING([for getmnt function])
254 AC_CACHE_VAL(fu_cv_sys_mounted_getmnt,
256 #include <sys/fs_types.h>
257 #include <sys/mount.h>],
258 fu_cv_sys_mounted_getmnt=yes,
259 fu_cv_sys_mounted_getmnt=no)])
260 AC_MSG_RESULT($fu_cv_sys_mounted_getmnt)
261 if test $fu_cv_sys_mounted_getmnt = yes; then
262 ac_list_mounted_fs=found
263 AC_DEFINE(MOUNTED_GETMNT, 1,
264 [Define if there is a function named getmnt for reading the list of
265 mounted file systems. (Ultrix)])
269 if test -z "$ac_list_mounted_fs"; then
271 AC_CHECK_FUNCS(next_dev fs_stat_dev)
272 AC_CHECK_HEADERS(fs_info.h)
273 AC_MSG_CHECKING([for BEOS mounted file system support functions])
274 if test $ac_cv_header_fs_info_h = yes \
275 && test $ac_cv_func_next_dev = yes \
276 && test $ac_cv_func_fs_stat_dev = yes; then
281 AC_MSG_RESULT($fu_result)
282 if test $fu_result = yes; then
283 ac_list_mounted_fs=found
284 AC_DEFINE(MOUNTED_FS_STAT_DEV, 1,
285 [Define if there are functions named next_dev and fs_stat_dev for
286 reading the list of mounted file systems. (BeOS)])
290 if test -z "$ac_list_mounted_fs"; then
292 AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
293 AC_CACHE_VAL(fu_cv_sys_mounted_fread,
294 [AC_TRY_CPP([#include <mnttab.h>],
295 fu_cv_sys_mounted_fread=yes,
296 fu_cv_sys_mounted_fread=no)])
297 AC_MSG_RESULT($fu_cv_sys_mounted_fread)
298 if test $fu_cv_sys_mounted_fread = yes; then
299 ac_list_mounted_fs=found
300 AC_DEFINE(MOUNTED_FREAD, 1,
301 [Define if there is no specific function for reading the list of
302 mounted file systems. fread will be used to read /etc/mnttab.
307 if test -z "$ac_list_mounted_fs"; then
308 AC_MSG_ERROR([could not determine how to read list of mounted file systems])
309 # FIXME -- no need to abort building the whole package
310 # Can't build mountlist.c or anything that needs its functions
313 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])