2 * Conky, a system monitor, based on torsmo
4 * This program is licensed under BSD license, read COPYING
14 #include <sys/types.h>
18 #ifdef HAVE_SYS_STATFS_H
19 #include <sys/statfs.h>
22 /* freebsd && netbsd */
23 #ifdef HAVE_SYS_PARAM_H
24 #include <sys/param.h>
26 #ifdef HAVE_SYS_MOUNT_H
27 #include <sys/mount.h>
30 #define MAX_FS_STATS 64
32 static struct fs_stat fs_stats_[MAX_FS_STATS];
33 struct fs_stat *fs_stats = fs_stats_;
35 static void update_fs_stat(struct fs_stat* fs);
37 void update_fs_stats()
40 for(i=0; i<MAX_FS_STATS; ++i)
42 update_fs_stat(&fs_stats[i]);
48 for(i=0; i<MAX_FS_STATS; ++i)
49 if(fs_stats[i].path) {
50 free(fs_stats[i].path);
55 struct fs_stat *prepare_fs_stat(const char *s)
57 struct fs_stat* new = 0;
59 /* lookup existing or get new */
60 for(i=0; i<MAX_FS_STATS; ++i) {
61 if(fs_stats[i].path) {
62 if(strcmp(fs_stats[i].path, s) == 0)
69 ERR("too many fs stats");
72 new->path = strdup(s);
78 void update_fs_stat(struct fs_stat* fs)
81 if(statfs(fs->path, &s) == 0) {
82 fs->size = (long long) s.f_blocks * s.f_bsize;
83 /* bfree (root) or bavail (non-roots) ? */
84 fs->avail = (long long) s.f_bavail* s.f_bsize;
85 fs->free = (long long) s.f_bfree * s.f_bsize;;
90 ERR("statfs '%s': %s", fs->path, strerror(errno));