Update of /cvsroot/sysfence/sysfence
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23819
Modified Files:
getstats.c
Log Message:
faster function fetch_pathspace(...)
Index: getstats.c
===================================================================
RCS file: /cvsroot/sysfence/sysfence/getstats.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- getstats.c 17 Apr 2004 16:59:04 -0000 1.7
+++ getstats.c 18 Apr 2004 17:25:36 -0000 1.8
@@ -21,6 +21,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <strings.h>
+#include <sys/vfs.h>
statval stat [STA_LAST] = {
[STA_LA1] = { "la1", DOUBLE, {0} },
@@ -125,32 +126,19 @@
if (memfha < 0) bail_out (EXIT_IO, memfile);
}
-void fetch_pathspace(pathspaceval *pathspace) {
-
- char command[BUFSIZE];
- char *ptr;
- FILE *pipe;
-
- /* getting inf. through pipe from 'df' */
-
- sprintf(command, "df %s", pathspace->path);
- pipe = popen(command, "r");
- fread ((char *) &fbuf, BUFSIZE,1,pipe);
- pclose(pipe);
-
- /* reading space values for path */
-
- /* 1. total space - 2nd line, 2nd column */
- ptr = fto_notspace (fto_space (fto_newline ((char *)&fbuf)));
- pathspace->total = atoi(ptr);
+void fetch_pathspace(pathspaceval *pathspace)
+{
+ struct statfs buf;
+ long int bsizeKB;
- /* 2. used space - 2nd line, 3rd column */
- ptr = fto_notspace (fto_space (ptr));
- pathspace->used = atoi(ptr);
+ statfs(pathspace->path, &buf);
- /* 3. free space - 2nd line, 4th column */
- ptr = fto_notspace (fto_space (ptr));
- pathspace->free = atoi(ptr);
+ /* block size in KB */
+ bsizeKB = buf.f_bsize / 1024;
+
+ pathspace->total = buf.f_blocks * bsizeKB;
+ pathspace->free = buf.f_bavail * bsizeKB;
+ pathspace->used = (buf.f_blocks - buf.f_bfree) * bsizeKB;
#ifdef DEBUG
printf ("fetch_pathspace(): path %s total=%d used=%d free=%d\n",
@@ -160,7 +148,6 @@
pathspace->free
);
#endif
-
}
/* fast text parsing helpers */
|