From 1eb40c83287b07ac7428ad2d58504f386fad98f1 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 19 Jan 2012 16:21:06 -0600 Subject: Add diskspace checking support for Solaris/Illumos Was able to get my hands on one of these boxes today, so add yet another new way of doing this. I'm glad these calls are so standardized. This was compile tested on Linux and Illumos and seems to still be working in both places. Signed-off-by: Dan McGee --- lib/libalpm/diskspace.c | 54 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c index fe2036d5..4127153d 100644 --- a/lib/libalpm/diskspace.c +++ b/lib/libalpm/diskspace.c @@ -1,7 +1,7 @@ /* * diskspace.c * - * Copyright (c) 2010-2011 Pacman Development Team + * Copyright (c) 2010-2012 Pacman Development Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,10 +19,15 @@ #include "config.h" +#include #include + #if defined(HAVE_MNTENT_H) #include #endif +#if defined(HAVE_MNTTAB_H) +#include +#endif #if defined(HAVE_SYS_STATVFS_H) #include #endif @@ -60,10 +65,10 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle) alpm_list_t *mount_points = NULL, *ptr; alpm_mountpoint_t *mp; -#if defined HAVE_GETMNTENT +#if defined(HAVE_GETMNTENT) && defined(HAVE_MNTENT_H) + /* Linux */ struct mntent *mnt; FILE *fp; - struct statvfs fsp; fp = setmntent(MOUNTED, "r"); @@ -72,8 +77,10 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle) } while((mnt = getmntent(fp))) { + struct statvfs fsp; if(!mnt) { - _alpm_log(handle, ALPM_LOG_WARNING, _("could not get filesystem information\n")); + _alpm_log(handle, ALPM_LOG_WARNING, + _("could not get filesystem information\n")); continue; } if(statvfs(mnt->mnt_dir, &fsp) != 0) { @@ -93,7 +100,44 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle) } endmntent(fp); -#elif defined HAVE_GETMNTINFO +#elif defined(HAVE_GETMNTENT) && defined(HAVE_MNTTAB_H) + /* Solaris, Illumos */ + struct mnttab mnt; + FILE *fp; + int ret; + + fp = fopen("/etc/mnttab", "r"); + + if(fp == NULL) { + return NULL; + } + + while((ret = getmntent(fp, &mnt)) == 0) { + struct statvfs fsp; + if(statvfs(mnt->mnt_mountp, &fsp) != 0) { + _alpm_log(handle, ALPM_LOG_WARNING, + _("could not get filesystem information for %s: %s\n"), + mnt->mnt_mountp, strerror(errno)); + continue; + } + + CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, ALPM_ERR_MEMORY, NULL)); + mp->mount_dir = strdup(mnt->mnt_mountp); + mp->mount_dir_len = strlen(mp->mount_dir); + memcpy(&(mp->fsp), &fsp, sizeof(struct statvfs)); + mp->read_only = fsp.f_flag & ST_RDONLY; + + mount_points = alpm_list_add(mount_points, mp); + } + /* -1 == EOF */ + if(ret != -1) { + _alpm_log(handle, ALPM_LOG_WARNING, + _("could not get filesystem information\n")); + } + + fclose(fp); +#elif defined(HAVE_GETMNTINFO) + /* FreeBSD (statfs), NetBSD (statvfs), OpenBSD (statfs), OS X (statfs) */ int entries; FSSTATSTYPE *fsp; -- cgit v1.2.3-70-g09d2