7229f78f50efa7c59456cf75d1e56f5e73a7ce85
[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       ok=
199       if test $ac_cv_func_getmntinfo = yes; then
200         AC_EGREP_HEADER(f_type;, sys/mount.h,
201                         ok=yes)
202       fi
203       test -n "$ok" \
204           && fu_cv_sys_mounted_getmntinfo=yes \
205           || fu_cv_sys_mounted_getmntinfo=no
206     ])
207   AC_MSG_RESULT($fu_cv_sys_mounted_getmntinfo)
208   if test $fu_cv_sys_mounted_getmntinfo = yes; then
209     ac_list_mounted_fs=found
210     AC_DEFINE(MOUNTED_GETMNTINFO, 1,
211               [Define if there is a function named getmntinfo for reading the
212    list of mounted filesystems.  (4.4BSD)])
213   fi
214 fi
215
216 if test -z "$ac_list_mounted_fs"; then
217   # Ultrix
218   AC_MSG_CHECKING([for getmnt function])
219   AC_CACHE_VAL(fu_cv_sys_mounted_getmnt,
220     [AC_TRY_CPP([
221 #include <sys/fs_types.h>
222 #include <sys/mount.h>],
223                 fu_cv_sys_mounted_getmnt=yes,
224                 fu_cv_sys_mounted_getmnt=no)])
225   AC_MSG_RESULT($fu_cv_sys_mounted_getmnt)
226   if test $fu_cv_sys_mounted_getmnt = yes; then
227     ac_list_mounted_fs=found
228     AC_DEFINE(MOUNTED_GETMNT, 1,
229       [Define if there is a function named getmnt for reading the list of
230    mounted filesystems.  (Ultrix)])
231   fi
232 fi
233
234 if test -z "$ac_list_mounted_fs"; then
235   # BeOS
236   AC_CHECK_FUNCS(next_dev fs_stat_dev)
237   AC_CHECK_HEADERS(fs_info.h)
238   AC_MSG_CHECKING([for BEOS mounted file system support functions])
239   if test $ac_cv_header_fs_info_h = yes \
240       && test $ac_cv_func_next_dev = yes \
241         && test $ac_cv_func_fs_stat_dev = yes; then
242     fu_result=yes
243   else
244     fu_result=no
245   fi
246   AC_MSG_RESULT($fu_result)
247   if test $fu_result = yes; then
248     ac_list_mounted_fs=found
249     AC_DEFINE(MOUNTED_FS_STAT_DEV, 1,
250       [Define if there are functions named next_dev and fs_stat_dev for
251    reading the list of mounted filesystems.  (BeOS)])
252   fi
253 fi
254
255 if test -z "$ac_list_mounted_fs"; then
256   # SVR2
257   AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
258   AC_CACHE_VAL(fu_cv_sys_mounted_fread,
259     [AC_TRY_CPP([#include <mnttab.h>],
260                 fu_cv_sys_mounted_fread=yes,
261                 fu_cv_sys_mounted_fread=no)])
262   AC_MSG_RESULT($fu_cv_sys_mounted_fread)
263   if test $fu_cv_sys_mounted_fread = yes; then
264     ac_list_mounted_fs=found
265     AC_DEFINE(MOUNTED_FREAD, 1,
266               [Define if there is no specific function for reading the list of
267    mounted filesystems.  fread will be used to read /etc/mnttab.  (SVR2) ])
268   fi
269 fi
270
271 if test -z "$ac_list_mounted_fs"; then
272   AC_MSG_ERROR([could not determine how to read list of mounted filesystems])
273   # FIXME -- no need to abort building the whole package
274   # Can't build mountlist.c or anything that needs its functions
275 fi
276
277 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])
278
279   ])