FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 05-02-2012, 07:47 PM
Dave Reisner
 
Default diskspace: dedupe code for loading FS usage

add mount_point_load_fsinfo() for platforms using getmntent().

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
This is just code movement for the following patches.

lib/libalpm/diskspace.c | 52 ++++++++++++++++++++++++-----------------------
1 file changed, 27 insertions(+), 25 deletions(-)

diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
index daee244..f3f9092 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);
}

+static int mount_point_load_fsinfo(alpm_handle_t *handle, alpm_mountpoint_t *mountpoint)
+{
+#ifdef HAVE_GETMNTENT
+ /* 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
"),
+ mountpoint->mount_dir, strerror(errno));
+ return -1;
+ }
+
+ mountpoint->read_only = mountpoint->fsp.f_flag & ST_RDONLY;
+#endif
+
+ return 0;
+}
+
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
"));
- continue;
- }
- if(statvfs(mnt->mnt_dir, &fsp) != 0) {
- _alpm_log(handle, ALPM_LOG_WARNING,
- _("could not get filesystem information for %s: %s
"),
- 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
"),
- 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);
}
--
1.7.10.1
 

Thread Tools




All times are GMT. The time now is 09:38 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org