(checking for getmntinfo function...): Remove now-bogus
[gnulib.git] / m4 / ls-mntd-fs.m4
1 #serial 11
2
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
8
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])
30
31 # Determine how to get the list of mounted filesystems.
32 ac_list_mounted_fs=
33
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
37
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.
41
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.
46
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
69
70 if test $ac_cv_func_getmntent = yes; then
71
72   # This system has the getmntent function.
73   # Determine whether it's the one-argument variant or the two-argument one.
74
75   if test -z "$ac_list_mounted_fs"; then
76     # 4.3BSD, SunOS, HP-UX, Dynix, Irix
77     AC_MSG_CHECKING([for one-argument getmntent function])
78     AC_CACHE_VAL(fu_cv_sys_mounted_getmntent1,
79                  [AC_TRY_COMPILE([
80 /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
81 #include <stdio.h>
82
83 #include <mntent.h>
84 #if !defined MOUNTED
85 # if defined _PATH_MOUNTED      /* GNU libc  */
86 #  define MOUNTED _PATH_MOUNTED
87 # endif
88 # if defined MNT_MNTTAB /* HP-UX.  */
89 #  define MOUNTED MNT_MNTTAB
90 # endif
91 # if defined MNTTABNAME /* Dynix.  */
92 #  define MOUNTED MNTTABNAME
93 # endif
94 #endif
95 ],
96                     [ struct mntent *mnt = 0; char *table = MOUNTED; ],
97                     fu_cv_sys_mounted_getmntent1=yes,
98                     fu_cv_sys_mounted_getmntent1=no)])
99     AC_MSG_RESULT($fu_cv_sys_mounted_getmntent1)
100     if test $fu_cv_sys_mounted_getmntent1 = yes; then
101       ac_list_mounted_fs=found
102       AC_DEFINE(MOUNTED_GETMNTENT1, 1,
103   [Define if there is a function named getmntent for reading the list
104    of mounted filesystems, and that function takes a single argument.
105    (4.3BSD, SunOS, HP-UX, Dynix, Irix)])
106     fi
107   fi
108
109   if test -z "$ac_list_mounted_fs"; then
110     # SVR4
111     AC_MSG_CHECKING([for two-argument getmntent function])
112     AC_CACHE_VAL(fu_cv_sys_mounted_getmntent2,
113     [AC_EGREP_HEADER(getmntent, sys/mnttab.h,
114       fu_cv_sys_mounted_getmntent2=yes,
115       fu_cv_sys_mounted_getmntent2=no)])
116     AC_MSG_RESULT($fu_cv_sys_mounted_getmntent2)
117     if test $fu_cv_sys_mounted_getmntent2 = yes; then
118       ac_list_mounted_fs=found
119       AC_DEFINE(MOUNTED_GETMNTENT2, 1,
120   [Define if there is a function named getmntent for reading the list of
121    mounted filesystems, and that function takes two arguments.  (SVR4)])
122     fi
123   fi
124
125 fi
126
127 if test -z "$ac_list_mounted_fs"; then
128   # DEC Alpha running OSF/1, and Apple Darwin 1.3.
129   # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
130
131   AC_MSG_CHECKING([for getfsstat function])
132   AC_CACHE_VAL(fu_cv_sys_mounted_getfsstat,
133   [AC_TRY_LINK([
134 #include <sys/types.h>
135 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
136 # define FS_TYPE(Ent) ((Ent).f_fstypename)
137 #else
138 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
139 #endif
140 ]$getfsstat_includes
141 ,
142   [struct statfs *stats;
143    int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
144    char *t = FS_TYPE (*stats); ],
145     fu_cv_sys_mounted_getfsstat=yes,
146     fu_cv_sys_mounted_getfsstat=no)])
147   AC_MSG_RESULT($fu_cv_sys_mounted_getfsstat)
148   if test $fu_cv_sys_mounted_getfsstat = yes; then
149     ac_list_mounted_fs=found
150     AC_DEFINE(MOUNTED_GETFSSTAT, 1,
151               [Define if there is a function named getfsstat for reading the
152    list of mounted filesystems.  (DEC Alpha running OSF/1)])
153   fi
154 fi
155
156 if test -z "$ac_list_mounted_fs"; then
157   # AIX.
158   AC_MSG_CHECKING([for mntctl function and struct vmount])
159   AC_CACHE_VAL(fu_cv_sys_mounted_vmount,
160   [AC_TRY_CPP([#include <fshelp.h>],
161     fu_cv_sys_mounted_vmount=yes,
162     fu_cv_sys_mounted_vmount=no)])
163   AC_MSG_RESULT($fu_cv_sys_mounted_vmount)
164   if test $fu_cv_sys_mounted_vmount = yes; then
165     ac_list_mounted_fs=found
166     AC_DEFINE(MOUNTED_VMOUNT, 1,
167         [Define if there is a function named mntctl that can be used to read
168    the list of mounted filesystems, and there is a system header file
169    that declares `struct vmount.'  (AIX)])
170   fi
171 fi
172
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
192
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
210
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
228
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
249
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
265
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
271
272 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])
273
274   ])