ls-mntd-fs.m4 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. # serial 36
  2. # How to list mounted file systems.
  3. # Copyright (C) 1998-2004, 2006, 2009-2018 Free Software Foundation, Inc.
  4. #
  5. # This file is free software; the Free Software Foundation
  6. # gives unlimited permission to copy and/or distribute it,
  7. # with or without modifications, as long as this notice is preserved.
  8. dnl From Jim Meyering.
  9. AC_PREREQ([2.60])
  10. dnl This is not pretty. I've just taken the autoconf code and wrapped
  11. dnl it in an AC_DEFUN and made some other fixes.
  12. # Replace Autoconf's AC_FUNC_GETMNTENT to omit checks that are unnecessary
  13. # nowadays.
  14. AC_DEFUN([AC_FUNC_GETMNTENT],
  15. [
  16. # getmntent is in the standard C library on UNICOS, in -lsun on Irix 4,
  17. # -lgen on Unixware.
  18. AC_SEARCH_LIBS([getmntent], [sun gen])
  19. AC_CHECK_FUNCS([getmntent])
  20. ])
  21. # gl_LIST_MOUNTED_FILE_SYSTEMS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
  22. AC_DEFUN([gl_LIST_MOUNTED_FILE_SYSTEMS],
  23. [
  24. AC_REQUIRE([AC_CANONICAL_HOST])
  25. AC_CHECK_FUNCS([listmntent])
  26. AC_CHECK_HEADERS_ONCE([sys/param.h sys/statvfs.h])
  27. # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses
  28. # NGROUPS (as the array dimension for a struct member) without a definition.
  29. AC_CHECK_HEADERS([sys/ucred.h], [], [], [#include <grp.h>])
  30. AC_CHECK_HEADERS([sys/mount.h], [], [],
  31. [AC_INCLUDES_DEFAULT
  32. [#if HAVE_SYS_PARAM_H
  33. #include <sys/param.h>
  34. #endif
  35. ]])
  36. AC_CHECK_HEADERS([mntent.h sys/fs_types.h])
  37. getfsstat_includes="\
  38. $ac_includes_default
  39. #if HAVE_SYS_PARAM_H
  40. # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
  41. #endif
  42. #if HAVE_SYS_UCRED_H
  43. # include <grp.h> /* needed for definition of NGROUPS */
  44. # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
  45. #endif
  46. #if HAVE_SYS_MOUNT_H
  47. # include <sys/mount.h>
  48. #endif
  49. #if HAVE_SYS_FS_TYPES_H
  50. # include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
  51. #endif
  52. "
  53. AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
  54. # Determine how to get the list of mounted file systems.
  55. ac_list_mounted_fs=
  56. # If the getmntent function is available but not in the standard library,
  57. # make sure LIBS contains the appropriate -l option.
  58. AC_FUNC_GETMNTENT
  59. if test -z "$ac_list_mounted_fs"; then
  60. # AIX.
  61. AC_CACHE_CHECK([for mntctl function and struct vmount],
  62. [fu_cv_sys_mounted_vmount],
  63. [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <fshelp.h>]])],
  64. [fu_cv_sys_mounted_vmount=yes],
  65. [fu_cv_sys_mounted_vmount=no])])
  66. if test $fu_cv_sys_mounted_vmount = yes; then
  67. ac_list_mounted_fs=found
  68. AC_DEFINE([MOUNTED_VMOUNT], [1],
  69. [Define if there is a function named mntctl that can be used to read
  70. the list of mounted file systems, and there is a system header file
  71. that declares 'struct vmount'. (AIX)])
  72. fi
  73. fi
  74. if test $ac_cv_func_getmntent = yes; then
  75. # This system has the getmntent function.
  76. # Determine whether it's the one-argument variant or the two-argument one.
  77. if test -z "$ac_list_mounted_fs"; then
  78. # glibc, HP-UX, IRIX, Cygwin, Android, also (obsolete) 4.3BSD, SunOS.
  79. AC_CACHE_CHECK([for one-argument getmntent function],
  80. [fu_cv_sys_mounted_getmntent1],
  81. [AC_COMPILE_IFELSE(
  82. [AC_LANG_PROGRAM([[
  83. /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
  84. #include <stdio.h>
  85. #include <mntent.h>
  86. #if !defined MOUNTED
  87. # if defined _PATH_MOUNTED /* GNU libc */
  88. # define MOUNTED _PATH_MOUNTED
  89. # endif
  90. # if defined MNT_MNTTAB /* HP-UX. */
  91. # define MOUNTED MNT_MNTTAB
  92. # endif
  93. #endif
  94. ]],
  95. [[struct mntent *mnt = 0; char *table = MOUNTED;
  96. if (sizeof mnt && sizeof table) return 0;
  97. ]])],
  98. [fu_cv_sys_mounted_getmntent1=yes],
  99. [fu_cv_sys_mounted_getmntent1=no])
  100. ])
  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 file systems, and that function takes a single argument.
  106. (4.3BSD, SunOS, HP-UX, Irix)])
  107. AC_CHECK_FUNCS([hasmntopt])
  108. fi
  109. fi
  110. if test -z "$ac_list_mounted_fs"; then
  111. # Solaris >= 8.
  112. AC_CACHE_CHECK([for getextmntent function],
  113. [fu_cv_sys_mounted_getextmntent],
  114. [AC_EGREP_HEADER([getextmntent], [sys/mnttab.h],
  115. [fu_cv_sys_mounted_getextmntent=yes],
  116. [fu_cv_sys_mounted_getextmntent=no])])
  117. if test $fu_cv_sys_mounted_getextmntent = yes; then
  118. ac_list_mounted_fs=found
  119. AC_DEFINE([MOUNTED_GETEXTMNTENT], [1],
  120. [Define if there is a function named getextmntent for reading the list
  121. of mounted file systems. (Solaris)])
  122. fi
  123. fi
  124. if test -z "$ac_list_mounted_fs"; then
  125. # Solaris < 8, also (obsolete) SVR4.
  126. # Solaris >= 8 has the two-argument getmntent but is already handled above.
  127. AC_CACHE_CHECK([for two-argument getmntent function],
  128. [fu_cv_sys_mounted_getmntent2],
  129. [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
  130. [fu_cv_sys_mounted_getmntent2=yes],
  131. [fu_cv_sys_mounted_getmntent2=no])
  132. ])
  133. if test $fu_cv_sys_mounted_getmntent2 = yes; then
  134. ac_list_mounted_fs=found
  135. AC_DEFINE([MOUNTED_GETMNTENT2], [1],
  136. [Define if there is a function named getmntent for reading the list of
  137. mounted file systems, and that function takes two arguments. (SVR4)])
  138. AC_CHECK_FUNCS([hasmntopt])
  139. fi
  140. fi
  141. fi
  142. if test -z "$ac_list_mounted_fs"; then
  143. # OSF/1, also (obsolete) Apple Darwin 1.3.
  144. # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
  145. AC_CACHE_CHECK([for getfsstat function],
  146. [fu_cv_sys_mounted_getfsstat],
  147. [AC_LINK_IFELSE(
  148. [AC_LANG_PROGRAM([[
  149. #include <sys/types.h>
  150. #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
  151. # define FS_TYPE(Ent) ((Ent).f_fstypename)
  152. #else
  153. # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
  154. #endif
  155. $getfsstat_includes
  156. ]],
  157. [[struct statfs *stats;
  158. int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
  159. char *t = FS_TYPE (*stats);
  160. ]])],
  161. [fu_cv_sys_mounted_getfsstat=yes],
  162. [fu_cv_sys_mounted_getfsstat=no])
  163. ])
  164. if test $fu_cv_sys_mounted_getfsstat = yes; then
  165. ac_list_mounted_fs=found
  166. AC_DEFINE([MOUNTED_GETFSSTAT], [1],
  167. [Define if there is a function named getfsstat for reading the
  168. list of mounted file systems. (DEC Alpha running OSF/1)])
  169. fi
  170. fi
  171. if test -z "$ac_list_mounted_fs"; then
  172. # (obsolete) SVR3
  173. AC_CACHE_CHECK([for FIXME existence of three headers],
  174. [fu_cv_sys_mounted_fread_fstyp],
  175. [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
  176. #include <sys/statfs.h>
  177. #include <sys/fstyp.h>
  178. #include <mnttab.h>
  179. ]])],
  180. [fu_cv_sys_mounted_fread_fstyp=yes],
  181. [fu_cv_sys_mounted_fread_fstyp=no])
  182. ])
  183. if test $fu_cv_sys_mounted_fread_fstyp = yes; then
  184. ac_list_mounted_fs=found
  185. AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
  186. [Define if (like SVR2) there is no specific function for reading the
  187. list of mounted file systems, and your system has these header files:
  188. <sys/fstyp.h> and <sys/statfs.h>. (SVR3)])
  189. fi
  190. fi
  191. if test -z "$ac_list_mounted_fs"; then
  192. # Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, also (obsolete) 4.4BSD.
  193. # OSF/1 also has getmntinfo but is already handled above.
  194. # We cannot use AC_CHECK_FUNCS([getmntinfo]) here, because at the linker
  195. # level the function is sometimes called getmntinfo64 or getmntinfo$INODE64
  196. # on Mac OS X, __getmntinfo13 on NetBSD and Minix, _F64_getmntinfo on OSF/1.
  197. AC_CACHE_CHECK([for getmntinfo function],
  198. [fu_cv_sys_mounted_getmntinfo],
  199. [AC_LINK_IFELSE(
  200. [AC_LANG_PROGRAM([[
  201. #if HAVE_SYS_PARAM_H
  202. # include <sys/param.h>
  203. #endif
  204. #include <sys/types.h>
  205. #if HAVE_SYS_MOUNT_H
  206. # include <sys/mount.h>
  207. #endif
  208. #if HAVE_SYS_STATVFS_H
  209. # include <sys/statvfs.h>
  210. #endif
  211. #include <stdlib.h>
  212. ]],
  213. [[int count = getmntinfo (NULL, MNT_WAIT);
  214. ]])],
  215. [fu_cv_sys_mounted_getmntinfo=yes],
  216. [fu_cv_sys_mounted_getmntinfo=no])
  217. ])
  218. if test $fu_cv_sys_mounted_getmntinfo = yes; then
  219. AC_CACHE_CHECK([whether getmntinfo returns statvfs structures],
  220. [fu_cv_sys_mounted_getmntinfo2],
  221. [AC_COMPILE_IFELSE(
  222. [AC_LANG_PROGRAM([[
  223. #if HAVE_SYS_PARAM_H
  224. # include <sys/param.h>
  225. #endif
  226. #include <sys/types.h>
  227. #if HAVE_SYS_MOUNT_H
  228. # include <sys/mount.h>
  229. #endif
  230. #if HAVE_SYS_STATVFS_H
  231. # include <sys/statvfs.h>
  232. #endif
  233. extern
  234. #ifdef __cplusplus
  235. "C"
  236. #endif
  237. int getmntinfo (struct statfs **, int);
  238. ]], [])],
  239. [fu_cv_sys_mounted_getmntinfo2=no],
  240. [fu_cv_sys_mounted_getmntinfo2=yes])
  241. ])
  242. if test $fu_cv_sys_mounted_getmntinfo2 = no; then
  243. # Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD.
  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 and it returns an array of
  248. 'struct statfs'. (4.4BSD, Darwin)])
  249. else
  250. # NetBSD, Minix.
  251. ac_list_mounted_fs=found
  252. AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
  253. [Define if there is a function named getmntinfo for reading the
  254. list of mounted file systems and it returns an array of
  255. 'struct statvfs'. (NetBSD 3.0)])
  256. fi
  257. fi
  258. fi
  259. if test -z "$ac_list_mounted_fs"; then
  260. # Haiku, also (obsolete) BeOS.
  261. AC_CHECK_FUNCS([next_dev fs_stat_dev])
  262. AC_CHECK_HEADERS([fs_info.h])
  263. AC_CACHE_CHECK([for BEOS mounted file system support functions],
  264. [fu_cv_sys_mounted_fs_stat_dev],
  265. [if test $ac_cv_header_fs_info_h = yes \
  266. && test $ac_cv_func_next_dev = yes \
  267. && test $ac_cv_func_fs_stat_dev = yes; then
  268. fu_cv_sys_mounted_fs_stat_dev=yes
  269. else
  270. fu_cv_sys_mounted_fs_stat_dev=no
  271. fi
  272. ])
  273. if test $fu_cv_sys_mounted_fs_stat_dev = yes; then
  274. ac_list_mounted_fs=found
  275. AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
  276. [Define if there are functions named next_dev and fs_stat_dev for
  277. reading the list of mounted file systems. (BeOS)])
  278. fi
  279. fi
  280. if test -z "$ac_list_mounted_fs"; then
  281. # Interix / BSD alike statvfs
  282. # the code is really interix specific, so make sure, we're on it.
  283. case "$host" in
  284. *-interix*)
  285. AC_CHECK_FUNCS([statvfs])
  286. if test $ac_cv_func_statvfs = yes; then
  287. ac_list_mounted_fs=found
  288. AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
  289. [Define if we are on interix, and ought to use statvfs plus
  290. some special knowledge on where mounted file systems can be
  291. found. (Interix)])
  292. fi
  293. ;;
  294. esac
  295. fi
  296. if test -z "$ac_list_mounted_fs"; then
  297. AC_MSG_ERROR([could not determine how to read list of mounted file systems])
  298. # FIXME -- no need to abort building the whole package
  299. # Can't build mountlist.c or anything that needs its functions
  300. fi
  301. AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])
  302. ])