ls-mntd-fs.m4 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. #serial 21
  2. # How to list mounted file systems.
  3. # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006 Free Software
  4. # Foundation, Inc.
  5. #
  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.
  9. dnl From Jim Meyering.
  10. dnl
  11. dnl This is not pretty. I've just taken the autoconf code and wrapped
  12. dnl it in an AC_DEFUN and made some other fixes.
  13. dnl
  14. # Replace Autoconf's AC_FUNC_GETMNTENT to work around a bug in Autoconf
  15. # through Autoconf 2.59. We can remove this once we assume Autoconf 2.60
  16. # or later.
  17. AC_DEFUN([AC_FUNC_GETMNTENT],
  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_CHECK_FUNCS(listmntent getmntinfo)
  27. AC_CHECK_HEADERS_ONCE(sys/param.h)
  28. # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses
  29. # NGROUPS (as the array dimension for a struct member) without a definition.
  30. AC_CHECK_HEADERS(sys/ucred.h, [], [], [#include <grp.h>])
  31. AC_CHECK_HEADERS(sys/mount.h, [], [],
  32. [AC_INCLUDES_DEFAULT
  33. [#if HAVE_SYS_PARAM_H
  34. #include <sys/param.h>
  35. #endif]])
  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. # This test must precede the ones for getmntent because Unicos-9 is
  60. # reported to have the getmntent function, but its support is incompatible
  61. # with other getmntent implementations.
  62. # NOTE: Normally, I wouldn't use a check for system type as I've done for
  63. # `CRAY' below since that goes against the whole autoconf philosophy. But
  64. # I think there is too great a chance that some non-Cray system has a
  65. # function named listmntent to risk the false positive.
  66. if test -z "$ac_list_mounted_fs"; then
  67. # Cray UNICOS 9
  68. AC_MSG_CHECKING([for listmntent of Cray/Unicos-9])
  69. AC_CACHE_VAL(fu_cv_sys_mounted_cray_listmntent,
  70. [fu_cv_sys_mounted_cray_listmntent=no
  71. AC_EGREP_CPP(yes,
  72. [#ifdef _CRAY
  73. yes
  74. #endif
  75. ], [test $ac_cv_func_listmntent = yes \
  76. && fu_cv_sys_mounted_cray_listmntent=yes]
  77. )
  78. ]
  79. )
  80. AC_MSG_RESULT($fu_cv_sys_mounted_cray_listmntent)
  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_MSG_CHECKING([for mntctl function and struct vmount])
  91. AC_CACHE_VAL(fu_cv_sys_mounted_vmount,
  92. [AC_TRY_CPP([#include <fshelp.h>],
  93. fu_cv_sys_mounted_vmount=yes,
  94. fu_cv_sys_mounted_vmount=no)])
  95. AC_MSG_RESULT($fu_cv_sys_mounted_vmount)
  96. if test $fu_cv_sys_mounted_vmount = yes; then
  97. ac_list_mounted_fs=found
  98. AC_DEFINE(MOUNTED_VMOUNT, 1,
  99. [Define if there is a function named mntctl that can be used to read
  100. the list of mounted file systems, and there is a system header file
  101. that declares `struct vmount.' (AIX)])
  102. fi
  103. fi
  104. if test $ac_cv_func_getmntent = yes; then
  105. # This system has the getmntent function.
  106. # Determine whether it's the one-argument variant or the two-argument one.
  107. if test -z "$ac_list_mounted_fs"; then
  108. # 4.3BSD, SunOS, HP-UX, Dynix, Irix
  109. AC_MSG_CHECKING([for one-argument getmntent function])
  110. AC_CACHE_VAL(fu_cv_sys_mounted_getmntent1,
  111. [AC_TRY_COMPILE([
  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. 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. fi
  138. fi
  139. if test -z "$ac_list_mounted_fs"; then
  140. # SVR4
  141. AC_MSG_CHECKING([for two-argument getmntent function])
  142. AC_CACHE_VAL(fu_cv_sys_mounted_getmntent2,
  143. [AC_EGREP_HEADER(getmntent, sys/mnttab.h,
  144. fu_cv_sys_mounted_getmntent2=yes,
  145. fu_cv_sys_mounted_getmntent2=no)])
  146. AC_MSG_RESULT($fu_cv_sys_mounted_getmntent2)
  147. if test $fu_cv_sys_mounted_getmntent2 = yes; then
  148. ac_list_mounted_fs=found
  149. AC_DEFINE(MOUNTED_GETMNTENT2, 1,
  150. [Define if there is a function named getmntent for reading the list of
  151. mounted file systems, and that function takes two arguments. (SVR4)])
  152. fi
  153. fi
  154. fi
  155. if test -z "$ac_list_mounted_fs"; then
  156. # DEC Alpha running OSF/1, and Apple Darwin 1.3.
  157. # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
  158. AC_MSG_CHECKING([for getfsstat function])
  159. AC_CACHE_VAL(fu_cv_sys_mounted_getfsstat,
  160. [AC_TRY_LINK([
  161. #include <sys/types.h>
  162. #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
  163. # define FS_TYPE(Ent) ((Ent).f_fstypename)
  164. #else
  165. # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
  166. #endif
  167. ]$getfsstat_includes
  168. ,
  169. [struct statfs *stats;
  170. int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
  171. char *t = FS_TYPE (*stats); ],
  172. fu_cv_sys_mounted_getfsstat=yes,
  173. fu_cv_sys_mounted_getfsstat=no)])
  174. AC_MSG_RESULT($fu_cv_sys_mounted_getfsstat)
  175. if test $fu_cv_sys_mounted_getfsstat = yes; then
  176. ac_list_mounted_fs=found
  177. AC_DEFINE(MOUNTED_GETFSSTAT, 1,
  178. [Define if there is a function named getfsstat for reading the
  179. list of mounted file systems. (DEC Alpha running OSF/1)])
  180. fi
  181. fi
  182. if test -z "$ac_list_mounted_fs"; then
  183. # SVR3
  184. AC_MSG_CHECKING([for FIXME existence of three headers])
  185. AC_CACHE_VAL(fu_cv_sys_mounted_fread_fstyp,
  186. [AC_TRY_CPP([
  187. #include <sys/statfs.h>
  188. #include <sys/fstyp.h>
  189. #include <mnttab.h>],
  190. fu_cv_sys_mounted_fread_fstyp=yes,
  191. fu_cv_sys_mounted_fread_fstyp=no)])
  192. AC_MSG_RESULT($fu_cv_sys_mounted_fread_fstyp)
  193. if test $fu_cv_sys_mounted_fread_fstyp = yes; then
  194. ac_list_mounted_fs=found
  195. AC_DEFINE(MOUNTED_FREAD_FSTYP, 1,
  196. [Define if (like SVR2) there is no specific function for reading the
  197. list of mounted file systems, and your system has these header files:
  198. <sys/fstyp.h> and <sys/statfs.h>. (SVR3)])
  199. fi
  200. fi
  201. if test -z "$ac_list_mounted_fs"; then
  202. # 4.4BSD and DEC OSF/1.
  203. AC_MSG_CHECKING([for getmntinfo function])
  204. AC_CACHE_VAL(fu_cv_sys_mounted_getmntinfo,
  205. [
  206. test "$ac_cv_func_getmntinfo" = yes \
  207. && fu_cv_sys_mounted_getmntinfo=yes \
  208. || fu_cv_sys_mounted_getmntinfo=no
  209. ])
  210. AC_MSG_RESULT($fu_cv_sys_mounted_getmntinfo)
  211. if test $fu_cv_sys_mounted_getmntinfo = yes; then
  212. ac_list_mounted_fs=found
  213. AC_DEFINE(MOUNTED_GETMNTINFO, 1,
  214. [Define if there is a function named getmntinfo for reading the
  215. list of mounted file systems. (4.4BSD, Darwin)])
  216. fi
  217. fi
  218. if test -z "$ac_list_mounted_fs"; then
  219. # Ultrix
  220. AC_MSG_CHECKING([for getmnt function])
  221. AC_CACHE_VAL(fu_cv_sys_mounted_getmnt,
  222. [AC_TRY_CPP([
  223. #include <sys/fs_types.h>
  224. #include <sys/mount.h>],
  225. fu_cv_sys_mounted_getmnt=yes,
  226. fu_cv_sys_mounted_getmnt=no)])
  227. AC_MSG_RESULT($fu_cv_sys_mounted_getmnt)
  228. if test $fu_cv_sys_mounted_getmnt = yes; then
  229. ac_list_mounted_fs=found
  230. AC_DEFINE(MOUNTED_GETMNT, 1,
  231. [Define if there is a function named getmnt for reading the list of
  232. mounted file systems. (Ultrix)])
  233. fi
  234. fi
  235. if test -z "$ac_list_mounted_fs"; then
  236. # BeOS
  237. AC_CHECK_FUNCS(next_dev fs_stat_dev)
  238. AC_CHECK_HEADERS(fs_info.h)
  239. AC_MSG_CHECKING([for BEOS mounted file system support functions])
  240. if test $ac_cv_header_fs_info_h = yes \
  241. && test $ac_cv_func_next_dev = yes \
  242. && test $ac_cv_func_fs_stat_dev = yes; then
  243. fu_result=yes
  244. else
  245. fu_result=no
  246. fi
  247. AC_MSG_RESULT($fu_result)
  248. if test $fu_result = yes; then
  249. ac_list_mounted_fs=found
  250. AC_DEFINE(MOUNTED_FS_STAT_DEV, 1,
  251. [Define if there are functions named next_dev and fs_stat_dev for
  252. reading the list of mounted file systems. (BeOS)])
  253. fi
  254. fi
  255. if test -z "$ac_list_mounted_fs"; then
  256. # SVR2
  257. AC_MSG_CHECKING([whether it is possible to resort to fread on /etc/mnttab])
  258. AC_CACHE_VAL(fu_cv_sys_mounted_fread,
  259. [AC_TRY_CPP([#include <mnttab.h>],
  260. fu_cv_sys_mounted_fread=yes,
  261. fu_cv_sys_mounted_fread=no)])
  262. AC_MSG_RESULT($fu_cv_sys_mounted_fread)
  263. if test $fu_cv_sys_mounted_fread = yes; then
  264. ac_list_mounted_fs=found
  265. AC_DEFINE(MOUNTED_FREAD, 1,
  266. [Define if there is no specific function for reading the list of
  267. mounted file systems. fread will be used to read /etc/mnttab.
  268. (SVR2) ])
  269. fi
  270. fi
  271. if test -z "$ac_list_mounted_fs"; then
  272. AC_MSG_ERROR([could not determine how to read list of mounted file systems])
  273. # FIXME -- no need to abort building the whole package
  274. # Can't build mountlist.c or anything that needs its functions
  275. fi
  276. AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])
  277. ])