#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/vfs.h>
#include <unistd.h>
#include "common.h"
closedir(dir);
}
+/*
+ ***************************************************************************
+ * Read filesystems statistics.
+ *
+ * IN:
+ * @st_filesystem Structure where stats will be saved.
+ * @nbr Total number of filesystems.
+ *
+ * OUT:
+ * @st_filesystem Structure with statistics.
+ ***************************************************************************
+ */
+void read_filesystem(struct stats_filesystem *st_filesystem, int nbr)
+{
+ FILE *fp;
+ char line[256], fs_name[MAX_FS_LEN], mountp[128];
+ int fs = 0;
+ struct stats_filesystem *st_filesystem_i;
+ struct statfs buf;
+
+ if ((fp = fopen(MTAB, "r")) == NULL)
+ return;
+
+ while ((fgets(line, 256, fp) != NULL) && (fs < nbr)) {
+ if (line[0] == '/') {
+
+ /* Read current filesystem name and mount point */
+ sscanf(line, "%71s %127s", fs_name, mountp);
+
+ if ((statfs(mountp, &buf) < 0) || (!buf.f_blocks))
+ continue;
+
+ st_filesystem_i = st_filesystem + fs++;
+ st_filesystem_i->f_blocks = buf.f_blocks * buf.f_bsize;
+ st_filesystem_i->f_bfree = buf.f_bfree * buf.f_bsize;
+ st_filesystem_i->f_bavail = buf.f_bavail * buf.f_bsize;
+ st_filesystem_i->f_files = buf.f_files;
+ st_filesystem_i->f_ffree = buf.f_ffree;
+ strcpy(st_filesystem_i->fs_name, fs_name);
+ }
+ }
+
+ fclose(fp);
+}
+
/*
***************************************************************************
* Read machine uptime, independently of the number of processors.
return usb;
}
+
+/*
+ ***************************************************************************
+ * Find number of filesystems in /etc/mtab. Pseudo-filesystems are ignored.
+ *
+ * RETURNS:
+ * Number of filesystems.
+ ***************************************************************************
+ */
+int get_filesystem_nr(void)
+{
+ FILE *fp;
+ char line[256], fs_name[MAX_FS_LEN], mountp[128];
+ int fs = 0;
+ struct statfs buf;
+
+ if ((fp = fopen(MTAB, "r")) == NULL)
+ /* File non-existent */
+ return 0;
+
+ /* Get current filesystem */
+ while (fgets(line, 256, fp) != NULL) {
+ if (line[0] == '/') {
+
+ /* Read filesystem name and mount point */
+ sscanf(line, "%71s %127s", fs_name, mountp);
+
+ /* Check that total size is not null */
+ if (statfs(mountp, &buf) < 0)
+ continue;
+
+ if (buf.f_blocks) {
+ fs++;
+ }
+ }
+ }
+
+ fclose(fp);
+
+ return fs;
+}
#define MAX_MANUF_LEN 24
/* Maximum length of USB product string */
#define MAX_PROD_LEN 48
+/* Maximum length of filesystem name */
+#define MAX_FS_LEN 72
#define CNT_PART 1
#define CNT_ALL_DEV 0
/* Structure for filesystems statistics */
struct stats_filesystem {
- unsigned long long f_blocks __attribute__ ((aligned (16)));
- unsigned long long f_bfree __attribute__ ((aligned (16)));
- unsigned long long f_bavail __attribute__ ((aligned (16)));
- unsigned long long f_files __attribute__ ((aligned (16)));
- unsigned long long f_ffree __attribute__ ((aligned (16)));
+ unsigned long long f_blocks __attribute__ ((aligned (16)));
+ unsigned long long f_bfree __attribute__ ((aligned (16)));
+ unsigned long long f_bavail __attribute__ ((aligned (16)));
+ unsigned long long f_files __attribute__ ((aligned (16)));
+ unsigned long long f_ffree __attribute__ ((aligned (16)));
+ char fs_name[MAX_FS_LEN] __attribute__ ((aligned (16)));
};
#define STATS_FILESYSTEM_SIZE (sizeof(struct stats_filesystem))
read_time_in_state(struct stats_pwr_wghfreq *, int, int);
extern void
read_bus_usb_dev(struct stats_pwr_usb *, int);
+extern void
+ read_filesystem(struct stats_filesystem *, int);
/*
***************************************************************************
get_freq_nr(void);
extern int
get_usb_nr(void);
+extern int
+ get_filesystem_nr(void);
#endif /* _RD_STATS_H */