2 * Conky, a system monitor, based on torsmo
4 * Any original torsmo code is licensed under the BSD license
6 * All code written since the fork of torsmo is licensed under the GPL
8 * Please see COPYING for details
10 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
11 * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 #include <sys/types.h>
38 #ifdef HAVE_SYS_STATFS_H
39 #include <sys/statfs.h>
42 /* freebsd && netbsd */
43 #ifdef HAVE_SYS_PARAM_H
44 #include <sys/param.h>
46 #ifdef HAVE_SYS_MOUNT_H
47 #include <sys/mount.h>
50 #define MAX_FS_STATS 64
52 static struct fs_stat fs_stats_[MAX_FS_STATS];
53 struct fs_stat *fs_stats = fs_stats_;
55 static void update_fs_stat(struct fs_stat* fs);
57 void update_fs_stats()
60 for(i=0; i<MAX_FS_STATS; ++i)
62 update_fs_stat(&fs_stats[i]);
68 for(i=0; i<MAX_FS_STATS; ++i)
69 if(fs_stats[i].path) {
70 free(fs_stats[i].path);
75 struct fs_stat *prepare_fs_stat(const char *s)
77 struct fs_stat* new = 0;
79 /* lookup existing or get new */
80 for(i=0; i<MAX_FS_STATS; ++i) {
81 if(fs_stats[i].path) {
82 if(strcmp(fs_stats[i].path, s) == 0)
89 ERR("too many fs stats");
92 new->path = strdup(s);
98 void update_fs_stat(struct fs_stat* fs)
101 if(statfs(fs->path, &s) == 0) {
102 fs->size = (long long) s.f_blocks * s.f_bsize;
103 /* bfree (root) or bavail (non-roots) ? */
104 fs->avail = (long long) s.f_bavail* s.f_bsize;
105 fs->free = (long long) s.f_bfree * s.f_bsize;;
110 ERR("statfs '%s': %s", fs->path, strerror(errno));