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