1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-24 11:55:43 +00:00

applied statfs patch

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@364 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Brenden Matthews 2005-11-01 03:19:34 +00:00
parent 87a3edbf01
commit 29facd9a0f
4 changed files with 48 additions and 76 deletions

View File

@ -33,6 +33,7 @@ Daniel Thiele <dthiele at gmx dot net>
Denis <d-st at users dot sourceforge dot net> Denis <d-st at users dot sourceforge dot net>
WM_CLASS patch WM_CLASS patch
statfs patch
Dennis Frommknecht Dennis Frommknecht
NVCtrl, temperature monitoring for nvdia-based graphics cards NVCtrl, temperature monitoring for nvdia-based graphics cards

View File

@ -1,5 +1,8 @@
# $Id$ # $Id$
2005-10-31
* Added statfs sf.net patch 1344493
2005-10-30 2005-10-30
* Added tcp port monitor support (pkovacs) * Added tcp port monitor support (pkovacs)

View File

@ -84,7 +84,6 @@ struct net_stat {
unsigned int diskio_value; unsigned int diskio_value;
struct fs_stat { struct fs_stat {
int fd;
char *path; char *path;
long long size; long long size;
long long avail; long long avail;

119
src/fs.c
View File

@ -27,95 +27,64 @@
#include <sys/mount.h> #include <sys/mount.h>
#endif #endif
/* TODO: benchmark which is faster, fstatvfs() or pre-opened fd and #define MAX_FS_STATS 64
* statvfs() (fstatvfs() would handle mounts I think...) */
static struct fs_stat fs_stats_[64]; static struct fs_stat fs_stats_[MAX_FS_STATS];
struct fs_stat *fs_stats = fs_stats_; struct fs_stat *fs_stats = fs_stats_;
static void update_fs_stat(struct fs_stat* fs);
void update_fs_stats() void update_fs_stats()
{ {
unsigned int i; unsigned i;
struct statfs s; for(i=0; i<MAX_FS_STATS; ++i)
for (i = 0; i < 16; i++) { if(fs_stats[i].path)
if (fs_stats[i].fd <= 0) update_fs_stat(&fs_stats[i]);
break;
fstatfs(fs_stats[i].fd, &s);
fs_stats[i].size = (long long) s.f_blocks * s.f_bsize;
/* bfree (root) or bavail (non-roots) ? */
fs_stats[i].avail = (long long) s.f_bavail * s.f_bsize;
}
} }
void clear_fs_stats() void clear_fs_stats()
{ {
unsigned int i; unsigned i;
for (i = 0; i < 16; i++) { for(i=0; i<MAX_FS_STATS; ++i)
if (fs_stats[i].fd) { if(fs_stats[i].path) {
close(fs_stats[i].fd);
fs_stats[i].fd = -1;
}
if (fs_stats[i].path != NULL) {
free(fs_stats[i].path); free(fs_stats[i].path);
fs_stats[i].path = NULL; fs_stats[i].path = 0;
} }
}
} }
/*void clear_fs_stat(unsigned int i)
{
if (fs_stats[i].fd) {
close(fs_stats[i].fd);
fs_stats[i].fd = -1;
}
if (fs_stats[i].path != NULL) {
free(fs_stats[i].path);
fs_stats[i].path = NULL;
}
}*/
struct fs_stat *prepare_fs_stat(const char *s) struct fs_stat *prepare_fs_stat(const char *s)
{ {
unsigned int i; struct fs_stat* new = 0;
unsigned i;
for (i = 0; i < 16; i++) { /* lookup existing or get new */
struct fs_stat *fs = &fs_stats[i]; for(i=0; i<MAX_FS_STATS; ++i) {
if(fs_stats[i].path) {
if (fs->path && strcmp(fs->path, s) == 0) if(strcmp(fs_stats[i].path, s) == 0)
return fs; return &fs_stats[i];
} else
if (fs->fd <= 0) { new = &fs_stats[i];
/* when compiled with icc, it crashes when leaving function and open() }
* is used, I don't know why /* new path */
* fuck icc */ if(!new) {
ERR("too many fs stats");
/* this icc workaround didn't seem to work */ return 0;
#if 0 }
{ new->path = strdup(s);
FILE *fp = fopen(s, "r"); update_fs_stat(new);
if (fp) return new;
fs->fd = fileno(fp); }
else
fs->fd = -1; static
} void update_fs_stat(struct fs_stat* fs)
#endif {
struct statfs s;
fs->fd = open(s, O_RDONLY); if(statfs(fs->path, &s) == 0) {
fs->size = (long long) s.f_blocks * s.f_bsize;
if (fs->fd <= 0) { /* 0 isn't error but actually it is :) */ /* bfree (root) or bavail (non-roots) ? */
ERR("open '%s': %s", s, strerror(errno)); fs->avail = (long long) s.f_bavail * s.f_bsize;
return 0; } else {
} fs->size = 0;
fs->avail = 0;
fs->path = strdup(s); ERR("statfs '%s': %s", fs->path, strerror(errno));
update_fs_stats();
return fs;
}
} }
ERR("too many fs stats");
return 0;
} }