mountlist.m4 11 KB

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