ls-mntd-fs.m4 13 KB

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