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