1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-25 04:06:03 +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;

115
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
* fuck icc */
/* this icc workaround didn't seem to work */
#if 0
{
FILE *fp = fopen(s, "r");
if (fp)
fs->fd = fileno(fp);
else
fs->fd = -1;
} }
#endif /* new path */
if(!new) {
fs->fd = open(s, O_RDONLY);
if (fs->fd <= 0) { /* 0 isn't error but actually it is :) */
ERR("open '%s': %s", s, strerror(errno));
return 0;
}
fs->path = strdup(s);
update_fs_stats();
return fs;
}
}
ERR("too many fs stats"); ERR("too many fs stats");
return 0; return 0;
} }
new->path = strdup(s);
update_fs_stat(new);
return new;
}
static
void update_fs_stat(struct fs_stat* fs)
{
struct statfs s;
if(statfs(fs->path, &s) == 0) {
fs->size = (long long) s.f_blocks * s.f_bsize;
/* bfree (root) or bavail (non-roots) ? */
fs->avail = (long long) s.f_bavail * s.f_bsize;
} else {
fs->size = 0;
fs->avail = 0;
ERR("statfs '%s': %s", fs->path, strerror(errno));
}
}