1 #serial 12
3 dnl From Jim Meyering.
4 dnl
5 dnl This is not pretty. I've just taken the autoconf code and wrapped
6 dnl it in an AC_DEFUN.
7 dnl
9 # jm_LIST_MOUNTED_FILESYSTEMS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
10 AC_DEFUN([jm_LIST_MOUNTED_FILESYSTEMS],
11 [
12 AC_CHECK_FUNCS(listmntent getmntinfo)
13 AC_CHECK_HEADERS(mntent.h sys/param.h sys/ucred.h sys/mount.h sys/fs_types.h)
14 getfsstat_includes="\
15 $ac_includes_default
16 #if HAVE_SYS_PARAM_H
17 # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
18 #endif
19 #if HAVE_SYS_UCRED_H
20 # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
21 #endif
22 #if HAVE_SYS_MOUNT_H
23 # include <sys/mount.h>
24 #endif
25 #if HAVE_SYS_FS_TYPES_H
26 # include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
27 #endif
28 "
29 AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
31 # Determine how to get the list of mounted filesystems.
32 ac_list_mounted_fs=
34 # If the getmntent function is available but not in the standard library,
35 # make sure LIBS contains -lsun (on Irix4) or -lseq (on PTX).
36 AC_FUNC_GETMNTENT
38 # This test must precede the ones for getmntent because Unicos-9 is
39 # reported to have the getmntent function, but its support is incompatible
40 # with other getmntent implementations.
42 # NOTE: Normally, I wouldn't use a check for system type as I've done for
43 # `CRAY' below since that goes against the whole autoconf philosophy. But
44 # I think there is too great a chance that some non-Cray system has a
45 # function named listmntent to risk the false positive.
47 if test -z "$ac_list_mounted_fs"; then
48 # Cray UNICOS 9
49 AC_MSG_CHECKING([for listmntent of Cray/Unicos-9])
50 AC_CACHE_VAL(fu_cv_sys_mounted_cray_listmntent,
51 [fu_cv_sys_mounted_cray_listmntent=no
52 AC_EGREP_CPP(yes,
53 [#ifdef _CRAY
54 yes
55 #endif
56 ], [test $ac_cv_func_listmntent = yes \
57 && fu_cv_sys_mounted_cray_listmntent=yes]
58 )
59 ]
60 )
61 AC_MSG_RESULT($fu_cv_sys_mounted_cray_listmntent)
62 if test $fu_cv_sys_mounted_cray_listmntent = yes; then
63 ac_list_mounted_fs=found
64 AC_DEFINE(MOUNTED_LISTMNTENT, 1,
65 [Define if there is a function named listmntent that can be used to
66 list all mounted filesystems. (UNICOS)])
67 fi
68 fi
70 if test -z "$ac_list_mounted_fs"; then
71 # AIX.
72 AC_MSG_CHECKING([for mntctl function and struct vmount])
73 AC_CACHE_VAL(fu_cv_sys_mounted_vmount,
74 [AC_TRY_CPP([#include <fshelp.h>],
75 fu_cv_sys_mounted_vmount=yes,
76 fu_cv_sys_mounted_vmount=no)])
77 AC_MSG_RESULT($fu_cv_sys_mounted_vmount)
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 filesystems, and there is a system header file
83 that declares `struct vmount.' (AIX)])
84 fi
85 fi
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 # 4.3BSD, SunOS, HP-UX, Dynix, Irix
94 AC_MSG_CHECKING([for one-argument getmntent function])
95 AC_CACHE_VAL(fu_cv_sys_mounted_getmntent1,
96 [AC_TRY_COMPILE([
97 /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
98 #include <stdio.h>
100 #include <mntent.h>
101 #if !defined MOUNTED
102 # if defined _PATH_MOUNTED /* GNU libc */
103 # define MOUNTED _PATH_MOUNTED
104 # endif
105 # if defined MNT_MNTTAB /* HP-UX. */
106 # define MOUNTED MNT_MNTTAB
107 # endif
108 # if defined MNTTABNAME /* Dynix. */
109 # define MOUNTED MNTTABNAME
110 # endif
111 #endif
112 ],
113 [ struct mntent *mnt = 0; char *table = MOUNTED; ],
114 fu_cv_sys_mounted_getmntent1=yes,
115 fu_cv_sys_mounted_getmntent1=no)])
116 AC_MSG_RESULT($fu_cv_sys_mounted_getmntent1)
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 filesystems, and that function takes a single argument.
122 (4.3BSD, SunOS, HP-UX, Dynix, Irix)])
123 fi
124 fi
126 if test -z "$ac_list_mounted_fs"; then
127 # SVR4
128 AC_MSG_CHECKING([for two-argument getmntent function])
129 AC_CACHE_VAL(fu_cv_sys_mounted_getmntent2,
130 [AC_EGREP_HEADER(getmntent, sys/mnttab.h,
131 fu_cv_sys_mounted_getmntent2=yes,
132 fu_cv_sys_mounted_getmntent2=no)])
133 AC_MSG_RESULT($fu_cv_sys_mounted_getmntent2)
134 if test $fu_cv_sys_mounted_getmntent2 = yes; then
135 ac_list_mounted_fs=found
136 AC_DEFINE(MOUNTED_GETMNTENT2, 1,
137 [Define if there is a function named getmntent for reading the list of
138 mounted filesystems, and that function takes two arguments. (SVR4)])
139 fi
140 fi
142 fi
144 if test -z "$ac_list_mounted_fs"; then
145 # DEC Alpha running OSF/1, and Apple Darwin 1.3.
146 # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
148 AC_MSG_CHECKING([for getfsstat function])
149 AC_CACHE_VAL(fu_cv_sys_mounted_getfsstat,
150 [AC_TRY_LINK([
151 #include <sys/types.h>
152 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
153 # define FS_TYPE(Ent) ((Ent).f_fstypename)
154 #else
155 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
156 #endif
157 ]$getfsstat_includes
158 ,
159 [struct statfs *stats;
160 int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
161 char *t = FS_TYPE (*stats); ],
162 fu_cv_sys_mounted_getfsstat=yes,
163 fu_cv_sys_mounted_getfsstat=no)])
164 AC_MSG_RESULT($fu_cv_sys_mounted_getfsstat)
165 if test $fu_cv_sys_mounted_getfsstat = yes; then
166 ac_list_mounted_fs=found
167 AC_DEFINE(MOUNTED_GETFSSTAT, 1,
168 [Define if there is a function named getfsstat for reading the
169 list of mounted filesystems. (DEC Alpha running OSF/1)])
170 fi
171 fi
173 if test -z "$ac_list_mounted_fs"; then
174 # SVR3
175 AC_MSG_CHECKING([for FIXME existence of three headers])
176 AC_CACHE_VAL(fu_cv_sys_mounted_fread_fstyp,
177 [AC_TRY_CPP([
178 #include <sys/statfs.h>
179 #include <sys/fstyp.h>
180 #include <mnttab.h>],
181 fu_cv_sys_mounted_fread_fstyp=yes,
182 fu_cv_sys_mounted_fread_fstyp=no)])
183 AC_MSG_RESULT($fu_cv_sys_mounted_fread_fstyp)
184 if test $fu_cv_sys_mounted_fread_fstyp = yes; then
185 ac_list_mounted_fs=found
186 AC_DEFINE(MOUNTED_FREAD_FSTYP, 1,
187 [Define if (like SVR2) there is no specific function for reading the
188 list of mounted filesystems, and your system has these header files:
189 <sys/fstyp.h> and <sys/statfs.h>. (SVR3)])
190 fi
191 fi
193 if test -z "$ac_list_mounted_fs"; then
194 # 4.4BSD and DEC OSF/1.
195 AC_MSG_CHECKING([for getmntinfo function])
196 AC_CACHE_VAL(fu_cv_sys_mounted_getmntinfo,
197 [
198 test "$ac_cv_func_getmntinfo" = yes \
199 && fu_cv_sys_mounted_getmntinfo=yes \
200 || fu_cv_sys_mounted_getmntinfo=no
201 ])
202 AC_MSG_RESULT($fu_cv_sys_mounted_getmntinfo)
203 if test $fu_cv_sys_mounted_getmntinfo = yes; then
204 ac_list_mounted_fs=found
205 AC_DEFINE(MOUNTED_GETMNTINFO, 1,
206 [Define if there is a function named getmntinfo for reading the
207 list of mounted filesystems. (4.4BSD, Darwin)])
208 fi
209 fi
211 if test -z "$ac_list_mounted_fs"; then
212 # Ultrix
213 AC_MSG_CHECKING([for getmnt function])
214 AC_CACHE_VAL(fu_cv_sys_mounted_getmnt,
215 [AC_TRY_CPP([
216 #include <sys/fs_types.h>
217 #include <sys/mount.h>],
218 fu_cv_sys_mounted_getmnt=yes,
219 fu_cv_sys_mounted_getmnt=no)])
220 AC_MSG_RESULT($fu_cv_sys_mounted_getmnt)
221 if test $fu_cv_sys_mounted_getmnt = yes; then
222 ac_list_mounted_fs=found
223 AC_DEFINE(MOUNTED_GETMNT, 1,
224 [Define if there is a function named getmnt for reading the list of
225 mounted filesystems. (Ultrix)])
226 fi
227 fi
229 if test -z "$ac_list_mounted_fs"; then
230 # BeOS
231 AC_CHECK_FUNCS(next_dev fs_stat_dev)
232 AC_CHECK_HEADERS(fs_info.h)
233 AC_MSG_CHECKING([for BEOS mounted file system support functions])
234 if test $ac_cv_header_fs_info_h = yes \
235 && test $ac_cv_func_next_dev = yes \
236 && test $ac_cv_func_fs_stat_dev = yes; then
237 fu_result=yes
238 else
239 fu_result=no
240 fi
241 AC_MSG_RESULT($fu_result)
242 if test $fu_result = yes; then
243 ac_list_mounted_fs=found
244 AC_DEFINE(MOUNTED_FS_STAT_DEV, 1,
245 [Define if there are functions named next_dev and fs_stat_dev for
246 reading the list of mounted filesystems. (BeOS)])
247 fi
248 fi
250 if test -z "$ac_list_mounted_fs"; then
251 # SVR2
252 AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
253 AC_CACHE_VAL(fu_cv_sys_mounted_fread,
254 [AC_TRY_CPP([#include <mnttab.h>],
255 fu_cv_sys_mounted_fread=yes,
256 fu_cv_sys_mounted_fread=no)])
257 AC_MSG_RESULT($fu_cv_sys_mounted_fread)
258 if test $fu_cv_sys_mounted_fread = yes; then
259 ac_list_mounted_fs=found
260 AC_DEFINE(MOUNTED_FREAD, 1,
261 [Define if there is no specific function for reading the list of
262 mounted filesystems. fread will be used to read /etc/mnttab. (SVR2) ])
263 fi
264 fi
266 if test -z "$ac_list_mounted_fs"; then
267 AC_MSG_ERROR([could not determine how to read list of mounted filesystems])
268 # FIXME -- no need to abort building the whole package
269 # Can't build mountlist.c or anything that needs its functions
270 fi
272 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])
274 ])