ls-mntd-fs.m4 13 KB

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