* modules/error (Depends-on): Remove gettext.
[gnulib.git] / m4 / ls-mntd-fs.m4
1 #serial 19
2 # How to list mounted file systems.
3
4 # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
5 # Foundation, Inc.
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software Foundation,
19 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21 dnl From Jim Meyering.
22 dnl
23 dnl This is not pretty.  I've just taken the autoconf code and wrapped
24 dnl it in an AC_DEFUN and made some other fixes.
25 dnl
26
27 # Replace Autoconf's AC_FUNC_GETMNTENT to work around a bug in Autoconf
28 # through Autoconf 2.59.  We can remove this once we assume Autoconf 2.60
29 # or later.
30 AC_DEFUN([AC_FUNC_GETMNTENT],
31 [# getmntent is in the standard C library on UNICOS, in -lsun on Irix 4,
32 # -lseq on Dynix/PTX, -lgen on Unixware.
33 AC_SEARCH_LIBS(getmntent, [sun seq gen], [AC_CHECK_FUNCS(getmntent)])
34 ])
35
36 # gl_LIST_MOUNTED_FILE_SYSTEMS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
37 AC_DEFUN([gl_LIST_MOUNTED_FILE_SYSTEMS],
38   [
39 AC_CHECK_FUNCS(listmntent getmntinfo)
40 AC_CHECK_HEADERS_ONCE(sys/param.h)
41
42 # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses
43 # NGROUPS (as the array dimension for a struct member) without a definition.
44 AC_CHECK_HEADERS(sys/ucred.h, [], [], [#include <grp.h>])
45
46 AC_CHECK_HEADERS(sys/mount.h, [], [],
47   [AC_INCLUDES_DEFAULT
48    [#if HAVE_SYS_PARAM_H
49      #include <sys/param.h>
50     #endif]])
51
52 AC_CHECK_HEADERS(mntent.h sys/fs_types.h)
53     getfsstat_includes="\
54 $ac_includes_default
55 #if HAVE_SYS_PARAM_H
56 # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
57 #endif
58 #if HAVE_SYS_UCRED_H
59 # include <grp.h> /* needed for definition of NGROUPS */
60 # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
61 #endif
62 #if HAVE_SYS_MOUNT_H
63 # include <sys/mount.h>
64 #endif
65 #if HAVE_SYS_FS_TYPES_H
66 # include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
67 #endif
68 "
69 AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
70
71 # Determine how to get the list of mounted file systems.
72 ac_list_mounted_fs=
73
74 # If the getmntent function is available but not in the standard library,
75 # make sure LIBS contains the appropriate -l option.
76 AC_FUNC_GETMNTENT
77
78 # This test must precede the ones for getmntent because Unicos-9 is
79 # reported to have the getmntent function, but its support is incompatible
80 # with other getmntent implementations.
81
82 # NOTE: Normally, I wouldn't use a check for system type as I've done for
83 # `CRAY' below since that goes against the whole autoconf philosophy.  But
84 # I think there is too great a chance that some non-Cray system has a
85 # function named listmntent to risk the false positive.
86
87 if test -z "$ac_list_mounted_fs"; then
88   # Cray UNICOS 9
89   AC_MSG_CHECKING([for listmntent of Cray/Unicos-9])
90   AC_CACHE_VAL(fu_cv_sys_mounted_cray_listmntent,
91     [fu_cv_sys_mounted_cray_listmntent=no
92       AC_EGREP_CPP(yes,
93         [#ifdef _CRAY
94 yes
95 #endif
96         ], [test $ac_cv_func_listmntent = yes \
97             && fu_cv_sys_mounted_cray_listmntent=yes]
98       )
99     ]
100   )
101   AC_MSG_RESULT($fu_cv_sys_mounted_cray_listmntent)
102   if test $fu_cv_sys_mounted_cray_listmntent = yes; then
103     ac_list_mounted_fs=found
104     AC_DEFINE(MOUNTED_LISTMNTENT, 1,
105       [Define if there is a function named listmntent that can be used to
106        list all mounted file systems.  (UNICOS)])
107   fi
108 fi
109
110 if test -z "$ac_list_mounted_fs"; then
111   # AIX.
112   AC_MSG_CHECKING([for mntctl function and struct vmount])
113   AC_CACHE_VAL(fu_cv_sys_mounted_vmount,
114   [AC_TRY_CPP([#include <fshelp.h>],
115     fu_cv_sys_mounted_vmount=yes,
116     fu_cv_sys_mounted_vmount=no)])
117   AC_MSG_RESULT($fu_cv_sys_mounted_vmount)
118   if test $fu_cv_sys_mounted_vmount = yes; then
119     ac_list_mounted_fs=found
120     AC_DEFINE(MOUNTED_VMOUNT, 1,
121         [Define if there is a function named mntctl that can be used to read
122          the list of mounted file systems, and there is a system header file
123          that declares `struct vmount.'  (AIX)])
124   fi
125 fi
126
127 if test $ac_cv_func_getmntent = yes; then
128
129   # This system has the getmntent function.
130   # Determine whether it's the one-argument variant or the two-argument one.
131
132   if test -z "$ac_list_mounted_fs"; then
133     # 4.3BSD, SunOS, HP-UX, Dynix, Irix
134     AC_MSG_CHECKING([for one-argument getmntent function])
135     AC_CACHE_VAL(fu_cv_sys_mounted_getmntent1,
136                  [AC_TRY_COMPILE([
137 /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
138 #include <stdio.h>
139
140 #include <mntent.h>
141 #if !defined MOUNTED
142 # if defined _PATH_MOUNTED      /* GNU libc  */
143 #  define MOUNTED _PATH_MOUNTED
144 # endif
145 # if defined MNT_MNTTAB /* HP-UX.  */
146 #  define MOUNTED MNT_MNTTAB
147 # endif
148 # if defined MNTTABNAME /* Dynix.  */
149 #  define MOUNTED MNTTABNAME
150 # endif
151 #endif
152 ],
153                     [ struct mntent *mnt = 0; char *table = MOUNTED; ],
154                     fu_cv_sys_mounted_getmntent1=yes,
155                     fu_cv_sys_mounted_getmntent1=no)])
156     AC_MSG_RESULT($fu_cv_sys_mounted_getmntent1)
157     if test $fu_cv_sys_mounted_getmntent1 = yes; then
158       ac_list_mounted_fs=found
159       AC_DEFINE(MOUNTED_GETMNTENT1, 1,
160         [Define if there is a function named getmntent for reading the list
161          of mounted file systems, and that function takes a single argument.
162          (4.3BSD, SunOS, HP-UX, Dynix, Irix)])
163     fi
164   fi
165
166   if test -z "$ac_list_mounted_fs"; then
167     # SVR4
168     AC_MSG_CHECKING([for two-argument getmntent function])
169     AC_CACHE_VAL(fu_cv_sys_mounted_getmntent2,
170     [AC_EGREP_HEADER(getmntent, sys/mnttab.h,
171       fu_cv_sys_mounted_getmntent2=yes,
172       fu_cv_sys_mounted_getmntent2=no)])
173     AC_MSG_RESULT($fu_cv_sys_mounted_getmntent2)
174     if test $fu_cv_sys_mounted_getmntent2 = yes; then
175       ac_list_mounted_fs=found
176       AC_DEFINE(MOUNTED_GETMNTENT2, 1,
177         [Define if there is a function named getmntent for reading the list of
178          mounted file systems, and that function takes two arguments.  (SVR4)])
179     fi
180   fi
181
182 fi
183
184 if test -z "$ac_list_mounted_fs"; then
185   # DEC Alpha running OSF/1, and Apple Darwin 1.3.
186   # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
187
188   AC_MSG_CHECKING([for getfsstat function])
189   AC_CACHE_VAL(fu_cv_sys_mounted_getfsstat,
190   [AC_TRY_LINK([
191 #include <sys/types.h>
192 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
193 # define FS_TYPE(Ent) ((Ent).f_fstypename)
194 #else
195 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
196 #endif
197 ]$getfsstat_includes
198 ,
199   [struct statfs *stats;
200    int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
201    char *t = FS_TYPE (*stats); ],
202     fu_cv_sys_mounted_getfsstat=yes,
203     fu_cv_sys_mounted_getfsstat=no)])
204   AC_MSG_RESULT($fu_cv_sys_mounted_getfsstat)
205   if test $fu_cv_sys_mounted_getfsstat = yes; then
206     ac_list_mounted_fs=found
207     AC_DEFINE(MOUNTED_GETFSSTAT, 1,
208               [Define if there is a function named getfsstat for reading the
209                list of mounted file systems.  (DEC Alpha running OSF/1)])
210   fi
211 fi
212
213 if test -z "$ac_list_mounted_fs"; then
214   # SVR3
215   AC_MSG_CHECKING([for FIXME existence of three headers])
216   AC_CACHE_VAL(fu_cv_sys_mounted_fread_fstyp,
217     [AC_TRY_CPP([
218 #include <sys/statfs.h>
219 #include <sys/fstyp.h>
220 #include <mnttab.h>],
221                 fu_cv_sys_mounted_fread_fstyp=yes,
222                 fu_cv_sys_mounted_fread_fstyp=no)])
223   AC_MSG_RESULT($fu_cv_sys_mounted_fread_fstyp)
224   if test $fu_cv_sys_mounted_fread_fstyp = yes; then
225     ac_list_mounted_fs=found
226     AC_DEFINE(MOUNTED_FREAD_FSTYP, 1,
227       [Define if (like SVR2) there is no specific function for reading the
228        list of mounted file systems, and your system has these header files:
229        <sys/fstyp.h> and <sys/statfs.h>.  (SVR3)])
230   fi
231 fi
232
233 if test -z "$ac_list_mounted_fs"; then
234   # 4.4BSD and DEC OSF/1.
235   AC_MSG_CHECKING([for getmntinfo function])
236   AC_CACHE_VAL(fu_cv_sys_mounted_getmntinfo,
237     [
238       test "$ac_cv_func_getmntinfo" = yes \
239           && fu_cv_sys_mounted_getmntinfo=yes \
240           || fu_cv_sys_mounted_getmntinfo=no
241     ])
242   AC_MSG_RESULT($fu_cv_sys_mounted_getmntinfo)
243   if test $fu_cv_sys_mounted_getmntinfo = yes; then
244     ac_list_mounted_fs=found
245     AC_DEFINE(MOUNTED_GETMNTINFO, 1,
246               [Define if there is a function named getmntinfo for reading the
247                list of mounted file systems.  (4.4BSD, Darwin)])
248   fi
249 fi
250
251 if test -z "$ac_list_mounted_fs"; then
252   # Ultrix
253   AC_MSG_CHECKING([for getmnt function])
254   AC_CACHE_VAL(fu_cv_sys_mounted_getmnt,
255     [AC_TRY_CPP([
256 #include <sys/fs_types.h>
257 #include <sys/mount.h>],
258                 fu_cv_sys_mounted_getmnt=yes,
259                 fu_cv_sys_mounted_getmnt=no)])
260   AC_MSG_RESULT($fu_cv_sys_mounted_getmnt)
261   if test $fu_cv_sys_mounted_getmnt = yes; then
262     ac_list_mounted_fs=found
263     AC_DEFINE(MOUNTED_GETMNT, 1,
264       [Define if there is a function named getmnt for reading the list of
265        mounted file systems.  (Ultrix)])
266   fi
267 fi
268
269 if test -z "$ac_list_mounted_fs"; then
270   # BeOS
271   AC_CHECK_FUNCS(next_dev fs_stat_dev)
272   AC_CHECK_HEADERS(fs_info.h)
273   AC_MSG_CHECKING([for BEOS mounted file system support functions])
274   if test $ac_cv_header_fs_info_h = yes \
275       && test $ac_cv_func_next_dev = yes \
276         && test $ac_cv_func_fs_stat_dev = yes; then
277     fu_result=yes
278   else
279     fu_result=no
280   fi
281   AC_MSG_RESULT($fu_result)
282   if test $fu_result = yes; then
283     ac_list_mounted_fs=found
284     AC_DEFINE(MOUNTED_FS_STAT_DEV, 1,
285       [Define if there are functions named next_dev and fs_stat_dev for
286        reading the list of mounted file systems.  (BeOS)])
287   fi
288 fi
289
290 if test -z "$ac_list_mounted_fs"; then
291   # SVR2
292   AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
293   AC_CACHE_VAL(fu_cv_sys_mounted_fread,
294     [AC_TRY_CPP([#include <mnttab.h>],
295                 fu_cv_sys_mounted_fread=yes,
296                 fu_cv_sys_mounted_fread=no)])
297   AC_MSG_RESULT($fu_cv_sys_mounted_fread)
298   if test $fu_cv_sys_mounted_fread = yes; then
299     ac_list_mounted_fs=found
300     AC_DEFINE(MOUNTED_FREAD, 1,
301               [Define if there is no specific function for reading the list of
302                mounted file systems.  fread will be used to read /etc/mnttab.
303                (SVR2) ])
304   fi
305 fi
306
307 if test -z "$ac_list_mounted_fs"; then
308   AC_MSG_ERROR([could not determine how to read list of mounted file systems])
309   # FIXME -- no need to abort building the whole package
310   # Can't build mountlist.c or anything that needs its functions
311 fi
312
313 AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])
314
315   ])