fsusage, mountlist, getloadavg: Remove support for Dynix/ptx.
[gnulib.git] / m4 / ls-mntd-fs.m4
blob64a2dfcf789a7806b4db869e37a877ac72ce9c45
1 # serial 35
2 # How to list mounted file systems.
4 # Copyright (C) 1998-2004, 2006, 2009-2018 Free Software Foundation, Inc.
6 # This file is free software; the Free Software Foundation
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
10 dnl From Jim Meyering.
11 dnl
12 dnl This is not pretty.  I've just taken the autoconf code and wrapped
13 dnl it in an AC_DEFUN and made some other fixes.
14 dnl
16 # Replace Autoconf's AC_FUNC_GETMNTENT to work around a bug in Autoconf
17 # through Autoconf 2.59.  We can remove this once we assume Autoconf 2.60
18 # or later.
19 AC_DEFUN([AC_FUNC_GETMNTENT],
21   # getmntent is in the standard C library on UNICOS, in -lsun on Irix 4,
22   # -lgen on Unixware.
23   AC_SEARCH_LIBS([getmntent], [sun gen])
24   AC_CHECK_FUNCS([getmntent])
27 # gl_LIST_MOUNTED_FILE_SYSTEMS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
28 AC_DEFUN([gl_LIST_MOUNTED_FILE_SYSTEMS],
30   AC_REQUIRE([AC_CANONICAL_HOST])
31   AC_CHECK_FUNCS([listmntent])
32   AC_CHECK_HEADERS_ONCE([sys/param.h sys/statvfs.h])
34   # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses
35   # NGROUPS (as the array dimension for a struct member) without a definition.
36   AC_CHECK_HEADERS([sys/ucred.h], [], [], [#include <grp.h>])
38   AC_CHECK_HEADERS([sys/mount.h], [], [],
39     [AC_INCLUDES_DEFAULT
40      [#if HAVE_SYS_PARAM_H
41        #include <sys/param.h>
42       #endif
43     ]])
45   AC_CHECK_HEADERS([mntent.h sys/fs_types.h])
46   getfsstat_includes="\
47 $ac_includes_default
48 #if HAVE_SYS_PARAM_H
49 # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
50 #endif
51 #if HAVE_SYS_UCRED_H
52 # include <grp.h> /* needed for definition of NGROUPS */
53 # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
54 #endif
55 #if HAVE_SYS_MOUNT_H
56 # include <sys/mount.h>
57 #endif
58 #if HAVE_SYS_FS_TYPES_H
59 # include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
60 #endif
62   AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
64   # Determine how to get the list of mounted file systems.
65   ac_list_mounted_fs=
67   # If the getmntent function is available but not in the standard library,
68   # make sure LIBS contains the appropriate -l option.
69   AC_FUNC_GETMNTENT
71   # This test must precede the ones for getmntent because Unicos-9 is
72   # reported to have the getmntent function, but its support is incompatible
73   # with other getmntent implementations.
75   # NOTE: Normally, I wouldn't use a check for system type as I've done for
76   # 'CRAY' below since that goes against the whole autoconf philosophy.  But
77   # I think there is too great a chance that some non-Cray system has a
78   # function named listmntent to risk the false positive.
80   if test -z "$ac_list_mounted_fs"; then
81     # (obsolete) Cray UNICOS 9
82     AC_CACHE_CHECK([for listmntent of Cray/Unicos-9],
83       [fu_cv_sys_mounted_cray_listmntent],
84       [fu_cv_sys_mounted_cray_listmntent=no
85         AC_EGREP_CPP([yes],
86           [#ifdef _CRAY
87 yes
88 #endif
89           ], [test $ac_cv_func_listmntent = yes \
90               && fu_cv_sys_mounted_cray_listmntent=yes]
91         )
92       ])
93     if test $fu_cv_sys_mounted_cray_listmntent = yes; then
94       ac_list_mounted_fs=found
95       AC_DEFINE([MOUNTED_LISTMNTENT], [1],
96         [Define if there is a function named listmntent that can be used to
97          list all mounted file systems.  (UNICOS)])
98     fi
99   fi
101   if test -z "$ac_list_mounted_fs"; then
102     # AIX.
103     AC_CACHE_CHECK([for mntctl function and struct vmount],
104       [fu_cv_sys_mounted_vmount],
105       [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <fshelp.h>]])],
106          [fu_cv_sys_mounted_vmount=yes],
107          [fu_cv_sys_mounted_vmount=no])])
108     if test $fu_cv_sys_mounted_vmount = yes; then
109       ac_list_mounted_fs=found
110       AC_DEFINE([MOUNTED_VMOUNT], [1],
111         [Define if there is a function named mntctl that can be used to read
112          the list of mounted file systems, and there is a system header file
113          that declares 'struct vmount'.  (AIX)])
114     fi
115   fi
117   if test $ac_cv_func_getmntent = yes; then
119     # This system has the getmntent function.
120     # Determine whether it's the one-argument variant or the two-argument one.
122     if test -z "$ac_list_mounted_fs"; then
123       # glibc, HP-UX, IRIX, Cygwin, Android, also (obsolete) 4.3BSD, SunOS.
124       AC_CACHE_CHECK([for one-argument getmntent function],
125         [fu_cv_sys_mounted_getmntent1],
126         [AC_COMPILE_IFELSE(
127            [AC_LANG_PROGRAM([[
128 /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
129 #include <stdio.h>
131 #include <mntent.h>
132 #if !defined MOUNTED
133 # if defined _PATH_MOUNTED      /* GNU libc  */
134 #  define MOUNTED _PATH_MOUNTED
135 # endif
136 # if defined MNT_MNTTAB /* HP-UX.  */
137 #  define MOUNTED MNT_MNTTAB
138 # endif
139 #endif
141               [[struct mntent *mnt = 0; char *table = MOUNTED;
142                 if (sizeof mnt && sizeof table) return 0;
143               ]])],
144            [fu_cv_sys_mounted_getmntent1=yes],
145            [fu_cv_sys_mounted_getmntent1=no])
146         ])
147       if test $fu_cv_sys_mounted_getmntent1 = yes; then
148         ac_list_mounted_fs=found
149         AC_DEFINE([MOUNTED_GETMNTENT1], [1],
150           [Define if there is a function named getmntent for reading the list
151            of mounted file systems, and that function takes a single argument.
152            (4.3BSD, SunOS, HP-UX, Irix)])
153         AC_CHECK_FUNCS([hasmntopt])
154       fi
155     fi
157     if test -z "$ac_list_mounted_fs"; then
158       # Solaris >= 8.
159       AC_CACHE_CHECK([for getextmntent function],
160         [fu_cv_sys_mounted_getextmntent],
161         [AC_EGREP_HEADER([getextmntent], [sys/mnttab.h],
162            [fu_cv_sys_mounted_getextmntent=yes],
163            [fu_cv_sys_mounted_getextmntent=no])])
164       if test $fu_cv_sys_mounted_getextmntent = yes; then
165         ac_list_mounted_fs=found
166         AC_DEFINE([MOUNTED_GETEXTMNTENT], [1],
167           [Define if there is a function named getextmntent for reading the list
168            of mounted file systems.  (Solaris)])
169       fi
170     fi
172     if test -z "$ac_list_mounted_fs"; then
173       # Solaris < 8, also (obsolete) SVR4.
174       # Solaris >= 8 has the two-argument getmntent but is already handled above.
175       AC_CACHE_CHECK([for two-argument getmntent function],
176         [fu_cv_sys_mounted_getmntent2],
177         [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
178            [fu_cv_sys_mounted_getmntent2=yes],
179            [fu_cv_sys_mounted_getmntent2=no])
180         ])
181       if test $fu_cv_sys_mounted_getmntent2 = yes; then
182         ac_list_mounted_fs=found
183         AC_DEFINE([MOUNTED_GETMNTENT2], [1],
184           [Define if there is a function named getmntent for reading the list of
185            mounted file systems, and that function takes two arguments.  (SVR4)])
186         AC_CHECK_FUNCS([hasmntopt])
187       fi
188     fi
190   fi
192   if test -z "$ac_list_mounted_fs"; then
193     # OSF/1, also (obsolete) Apple Darwin 1.3.
194     # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
196     AC_CACHE_CHECK([for getfsstat function],
197       [fu_cv_sys_mounted_getfsstat],
198       [AC_LINK_IFELSE(
199          [AC_LANG_PROGRAM([[
200 #include <sys/types.h>
201 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
202 # define FS_TYPE(Ent) ((Ent).f_fstypename)
203 #else
204 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
205 #endif
206 $getfsstat_includes
207             ]],
208             [[struct statfs *stats;
209               int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
210               char *t = FS_TYPE (*stats);
211             ]])],
212          [fu_cv_sys_mounted_getfsstat=yes],
213          [fu_cv_sys_mounted_getfsstat=no])
214       ])
215     if test $fu_cv_sys_mounted_getfsstat = yes; then
216       ac_list_mounted_fs=found
217       AC_DEFINE([MOUNTED_GETFSSTAT], [1],
218         [Define if there is a function named getfsstat for reading the
219          list of mounted file systems.  (DEC Alpha running OSF/1)])
220     fi
221   fi
223   if test -z "$ac_list_mounted_fs"; then
224     # (obsolete) SVR3
225     AC_CACHE_CHECK([for FIXME existence of three headers],
226       [fu_cv_sys_mounted_fread_fstyp],
227       [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
228 #include <sys/statfs.h>
229 #include <sys/fstyp.h>
230 #include <mnttab.h>
231 ]])],
232          [fu_cv_sys_mounted_fread_fstyp=yes],
233          [fu_cv_sys_mounted_fread_fstyp=no])
234       ])
235     if test $fu_cv_sys_mounted_fread_fstyp = yes; then
236       ac_list_mounted_fs=found
237       AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
238         [Define if (like SVR2) there is no specific function for reading the
239          list of mounted file systems, and your system has these header files:
240          <sys/fstyp.h> and <sys/statfs.h>.  (SVR3)])
241     fi
242   fi
244   if test -z "$ac_list_mounted_fs"; then
245     # Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, also (obsolete) 4.4BSD.
246     # OSF/1 also has getmntinfo but is already handled above.
247     # We cannot use AC_CHECK_FUNCS([getmntinfo]) here, because at the linker
248     # level the function is sometimes called getmntinfo64 or getmntinfo$INODE64
249     # on Mac OS X, __getmntinfo13 on NetBSD and Minix, _F64_getmntinfo on OSF/1.
250     AC_CACHE_CHECK([for getmntinfo function],
251       [fu_cv_sys_mounted_getmntinfo],
252       [AC_LINK_IFELSE(
253          [AC_LANG_PROGRAM([[
254 #if HAVE_SYS_PARAM_H
255 # include <sys/param.h>
256 #endif
257 #include <sys/types.h>
258 #if HAVE_SYS_MOUNT_H
259 # include <sys/mount.h>
260 #endif
261 #if HAVE_SYS_STATVFS_H
262 # include <sys/statvfs.h>
263 #endif
264 #include <stdlib.h>
265             ]],
266             [[int count = getmntinfo (NULL, MNT_WAIT);
267             ]])],
268          [fu_cv_sys_mounted_getmntinfo=yes],
269          [fu_cv_sys_mounted_getmntinfo=no])
270       ])
271     if test $fu_cv_sys_mounted_getmntinfo = yes; then
272       AC_CACHE_CHECK([whether getmntinfo returns statvfs structures],
273         [fu_cv_sys_mounted_getmntinfo2],
274         [AC_COMPILE_IFELSE(
275            [AC_LANG_PROGRAM([[
276 #if HAVE_SYS_PARAM_H
277 # include <sys/param.h>
278 #endif
279 #include <sys/types.h>
280 #if HAVE_SYS_MOUNT_H
281 # include <sys/mount.h>
282 #endif
283 #if HAVE_SYS_STATVFS_H
284 # include <sys/statvfs.h>
285 #endif
286 extern
287 #ifdef __cplusplus
289 #endif
290 int getmntinfo (struct statfs **, int);
291               ]], [])],
292            [fu_cv_sys_mounted_getmntinfo2=no],
293            [fu_cv_sys_mounted_getmntinfo2=yes])
294         ])
295       if test $fu_cv_sys_mounted_getmntinfo2 = no; then
296         # Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD.
297         ac_list_mounted_fs=found
298         AC_DEFINE([MOUNTED_GETMNTINFO], [1],
299           [Define if there is a function named getmntinfo for reading the
300            list of mounted file systems and it returns an array of
301            'struct statfs'.  (4.4BSD, Darwin)])
302       else
303         # NetBSD, Minix.
304         ac_list_mounted_fs=found
305         AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
306           [Define if there is a function named getmntinfo for reading the
307            list of mounted file systems and it returns an array of
308            'struct statvfs'.  (NetBSD 3.0)])
309       fi
310     fi
311   fi
313   if test -z "$ac_list_mounted_fs"; then
314     # (obsolete) Ultrix.
315     AC_CACHE_CHECK([for getmnt function],
316       [fu_cv_sys_mounted_getmnt],
317       [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
318 #include <sys/fs_types.h>
319 #include <sys/mount.h>]])],
320          [fu_cv_sys_mounted_getmnt=yes],
321          [fu_cv_sys_mounted_getmnt=no])
322       ])
323     if test $fu_cv_sys_mounted_getmnt = yes; then
324       ac_list_mounted_fs=found
325       AC_DEFINE([MOUNTED_GETMNT], [1],
326         [Define if there is a function named getmnt for reading the list of
327          mounted file systems.  (Ultrix)])
328     fi
329   fi
331   if test -z "$ac_list_mounted_fs"; then
332     # Haiku, also (obsolete) BeOS.
333     AC_CHECK_FUNCS([next_dev fs_stat_dev])
334     AC_CHECK_HEADERS([fs_info.h])
335     AC_CACHE_CHECK([for BEOS mounted file system support functions],
336       [fu_cv_sys_mounted_fs_stat_dev],
337       [if test $ac_cv_header_fs_info_h = yes \
338           && test $ac_cv_func_next_dev = yes \
339           && test $ac_cv_func_fs_stat_dev = yes; then
340          fu_cv_sys_mounted_fs_stat_dev=yes
341        else
342          fu_cv_sys_mounted_fs_stat_dev=no
343        fi
344       ])
345     if test $fu_cv_sys_mounted_fs_stat_dev = yes; then
346       ac_list_mounted_fs=found
347       AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
348         [Define if there are functions named next_dev and fs_stat_dev for
349          reading the list of mounted file systems.  (BeOS)])
350     fi
351   fi
353   if test -z "$ac_list_mounted_fs"; then
354     # Interix / BSD alike statvfs
355     # the code is really interix specific, so make sure, we're on it.
356     case "$host" in
357       *-interix*)
358         AC_CHECK_FUNCS([statvfs])
359         if test $ac_cv_func_statvfs = yes; then
360           ac_list_mounted_fs=found
361           AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
362             [Define if we are on interix, and ought to use statvfs plus
363              some special knowledge on where mounted file systems can be
364              found. (Interix)])
365         fi
366         ;;
367     esac
368   fi
370   if test -z "$ac_list_mounted_fs"; then
371     AC_MSG_ERROR([could not determine how to read list of mounted file systems])
372     # FIXME -- no need to abort building the whole package
373     # Can't build mountlist.c or anything that needs its functions
374   fi
376   AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])