The helper function _alpm_mount_list provides a relatively portable interface to obtaining a list of mount pints on a system. This will be useful in checking for disk space availability when installing packages. Signed-off-by: Allan McRae <allan@archlinux.org> --- I have not tested the HAVE_GETMNTINFO path as that requires BSD4.4, OSX or NetBSD 3.0. However, it is taken from various example code on the internet so should work... configure.ac | 6 +++--- lib/libalpm/util.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/libalpm/util.h | 1 + 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 6f601f4..5bbd761 100644 --- a/configure.ac +++ b/configure.ac @@ -185,9 +185,9 @@ AC_FUNC_FORK AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK AC_FUNC_MKTIME AC_TYPE_SIGNAL -AC_CHECK_FUNCS([geteuid realpath regcomp strcasecmp \ - strndup strrchr strsep swprintf \ - wcwidth uname]) +AC_CHECK_FUNCS([geteuid getmntent getmntinfo realpath \ + regcomp strcasecmp strndup strrchr \ + strsep swprintf wcwidth uname]) # Enable large file support if available AC_SYS_LARGEFILE diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 2661241..9b7454f 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -39,6 +39,15 @@ #include <sys/stat.h> #include <sys/wait.h> +#ifdef HAVE_GETMNTENT +#include <mntent.h> +#endif + +#ifdef HAVE_GETMNTINFO +#include <sys/mount.h> +#include <sys/statvfs.h> +#endif + /* libarchive */ #include <archive.h> #include <archive_entry.h> @@ -845,4 +854,44 @@ int _alpm_splitname(const char *target, pmpkg_t *pkg) return(0); } +alpm_list_t *_alpm_mount_list() +{ + alpm_list_t *mount_points = NULL; + +#ifdef HAVE_GETMNTENT + struct mntent *mnt; + FILE *fp; + + fp = setmntent(MOUNTED, "r"); + + if (fp == NULL) { + return NULL; + } + + while((mnt = getmntent (fp))) { + mount_points = alpm_list_add(mount_points, strdup(mnt->mnt_dir)); + } + + endmntent(fp); +#endif + +#ifdef HAVE_GETMNTINFO + struct statvfs *fsp; + int entries; + + entries = getmntinfo (&fsp, MNT_NOWAIT); + + if (entries < 0) { + return NULL; + } + + for (; entries-- > 0; fsp++) { + mount_points = alpm_list_add(mount_points, strdup(fsp->f_mntonname)); + } +#endif + + mount_points = alpm_list_msort(mount_points, alpm_list_count(mount_points), _alpm_str_cmp); + return(mount_points); +} + /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 75e2c45..0d2ac79 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -78,6 +78,7 @@ int _alpm_lstat(const char *path, struct stat *buf); int _alpm_test_md5sum(const char *filepath, const char *md5sum); char *_alpm_archive_fgets(char *line, size_t size, struct archive *a); int _alpm_splitname(const char *target, pmpkg_t *pkg); +alpm_list_t *_alpm_mount_list(); #ifndef HAVE_STRSEP char *strsep(char **, const char *); -- 1.7.3.2