summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/diskspace.c
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-04-29 20:54:10 +0200
committerDan McGee <dan@archlinux.org>2012-06-26 06:26:50 +0200
commit82c999a8bfbffab4740742b4746435f5f1657643 (patch)
tree8c70c419ca93c05b88a2bef7ad9a8a5b5629c6b4 /lib/libalpm/diskspace.c
parent377cc23a09f7605e1f14ab89933f4d7dc69bc2cf (diff)
downloadpacman-82c999a8bfbffab4740742b4746435f5f1657643.tar.gz
pacman-82c999a8bfbffab4740742b4746435f5f1657643.tar.xz
diskspace: dedupe code for loading FS usage
add mount_point_load_fsinfo() for platforms using getmntent(). Dan: move the #ifdef slightly so we don't have unused functions on certain platforms (e.g., OS X). Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/diskspace.c')
-rw-r--r--lib/libalpm/diskspace.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
index a80a62b6..405bcd43 100644
--- a/lib/libalpm/diskspace.c
+++ b/lib/libalpm/diskspace.c
@@ -69,6 +69,23 @@ static void mount_point_list_free(alpm_list_t *mount_points)
FREELIST(mount_points);
}
+#if defined(HAVE_GETMNTENT)
+static int mount_point_load_fsinfo(alpm_handle_t *handle, alpm_mountpoint_t *mountpoint)
+{
+ /* grab the filesystem usage */
+ if(statvfs(mountpoint->mount_dir, &(mountpoint->fsp)) != 0) {
+ _alpm_log(handle, ALPM_LOG_WARNING,
+ _("could not get filesystem information for %s: %s\n"),
+ mountpoint->mount_dir, strerror(errno));
+ return -1;
+ }
+
+ mountpoint->read_only = mountpoint->fsp.f_flag & ST_RDONLY;
+
+ return 0;
+}
+#endif
+
static alpm_list_t *mount_point_list(alpm_handle_t *handle)
{
alpm_list_t *mount_points = NULL, *ptr;
@@ -86,24 +103,14 @@ 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"));
- continue;
- }
- if(statvfs(mnt->mnt_dir, &fsp) != 0) {
- _alpm_log(handle, ALPM_LOG_WARNING,
- _("could not get filesystem information for %s: %s\n"),
- mnt->mnt_dir, strerror(errno));
- continue;
- }
-
CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
mp->mount_dir = strdup(mnt->mnt_dir);
mp->mount_dir_len = strlen(mp->mount_dir);
- memcpy(&(mp->fsp), &fsp, sizeof(struct statvfs));
- mp->read_only = fsp.f_flag & ST_RDONLY;
+ if(mount_point_load_fsinfo(handle, mp) < 0) {
+ free(mp->mount_dir);
+ free(mp);
+ continue;
+ }
mount_points = alpm_list_add(mount_points, mp);
}
@@ -122,19 +129,14 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle)
}
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;
+ if(mount_point_load_fsinfo(handle, mp) < 0) {
+ free(mp->mount_dir);
+ free(mp);
+ continue;
+ }
mount_points = alpm_list_add(mount_points, mp);
}