Main Page | Class List | Directories | File List | Class Members | File Members

df.c File Reference

#include "../pub/getopt.h"
#include "cf.defs.h"
#include "cf.extern.h"

Go to the source code of this file.

Functions

int GetDiskUsage (char *file, enum cfsizes type)


Function Documentation

int GetDiskUsage char *  file,
enum cfsizes  type
 

Definition at line 48 of file df.c.

References bufsize, bzero, cfabs, cferror, cfinfinity, CfLog(), Debug2, NULL, OUTPUT, snprintf(), and Verbose.

Referenced by CheckFreeSpace(), and GatherDiskData().

00053 {
00054 #if defined SOLARIS || defined OSF || defined UNIXWARE 
00055     struct statvfs buf;
00056 #elif defined ULTRIX
00057     struct fs_data buf;
00058 #else
00059     struct statfs buf;
00060 #endif
00061     u_long blocksize = 1024, total = 0, used = 0, avail = 0;
00062     int capacity = 0;
00063 
00064     bzero (&buf, sizeof (buf));
00065 
00066     Verbose("Checking free space on %s\n",file);
00067 
00068 
00069 #if defined ULTRIX
00070     if (getmnt (NULL, &buf, sizeof (struct fs_data), STAT_ONE, file) == -1)
00071        {
00072        snprintf(OUTPUT,bufsize,"Couldn't get filesystem info for %s\n",file);
00073        CfLog(cferror,OUTPUT,"");
00074        return cfinfinity;
00075        }
00076 #elif defined SOLARIS || defined OSF || defined UNIXWARE 
00077     if (statvfs (file, &buf) != 0)
00078        {
00079        snprintf(OUTPUT,bufsize,"Couldn't get filesystem info for %s\n",file);
00080        CfLog(cferror,OUTPUT,"");
00081        return cfinfinity;
00082        }
00083 #elif defined IRIX || defined SCO || defined CFCRAY || defined UNIXWARE
00084     if (statfs (file, &buf, sizeof (struct statfs), 0) != 0)
00085        {
00086        snprintf(OUTPUT,bufsize,"Couldn't get filesystem info for %s\n",file);
00087        CfLog(cferror,OUTPUT,"");
00088        return cfinfinity;
00089        }
00090 #else
00091     if (statfs (file, &buf) != 0)
00092        {
00093        snprintf(OUTPUT,bufsize,"Couldn't get filesystem info for %s\n",file);
00094        CfLog(cferror,OUTPUT,"");
00095        return cfinfinity;
00096        }
00097 #endif
00098 
00099 #if defined ULTRIX
00100     total = buf.fd_btot;
00101     used = buf.fd_btot - buf.fd_bfree;
00102     avail = buf.fd_bfreen;
00103 #endif
00104 
00105 #if defined SOLARIS
00106     total = buf.f_blocks * (buf.f_frsize / blocksize);
00107     used = (buf.f_blocks - buf.f_bfree) * (buf.f_frsize / blocksize);
00108     avail = buf.f_bavail * (buf.f_frsize / blocksize);
00109 #endif
00110 
00111 #if defined NETBSD || defined FREEBSD || defined OPENBSD || defined SUNOS || defined HPuUX || defined DARWIN
00112     total = buf.f_blocks;
00113     used = buf.f_blocks - buf.f_bfree;
00114     avail = buf.f_bavail;
00115 #endif
00116 
00117 #if defined OSF
00118     total = (buf.f_blocks *  buf.f_frsize) / blocksize;
00119     used = ((buf.f_blocks - buf.f_bfree)* (buf.f_frsize) / blocksize);
00120     avail = (buf.f_bavail * buf.f_frsize) / blocksize;
00121 #endif
00122 
00123 #if defined AIX || defined SCO || defined CFCRAY || defined LINUX
00124     total = buf.f_blocks * (buf.f_bsize / blocksize);
00125     used = (buf.f_blocks - buf.f_bfree) * (buf.f_bsize / blocksize);
00126     avail = buf.f_bfree * (buf.f_bsize / blocksize);
00127 #endif
00128 
00129 #if defined IRIX
00130     /* Float fix by arjen@sara.nl */
00131     total = buf.f_blocks *  ((float)buf.f_bsize / blocksize);
00132     used = (buf.f_blocks - buf.f_bfree) * ((float)buf.f_bsize / blocksize);
00133     avail = buf.f_bfree *  ((float)buf.f_bsize/blocksize);
00134 #endif
00135    
00136 capacity = (double) (avail) / (double) (avail + used) * 100;
00137 
00138 Debug2("GetDiskUsage(%s) = %d/%d\n",file,avail,capacity);
00139     
00140 /* Free kilobytes */
00141 
00142 if (type == cfabs)
00143    {
00144    return avail;
00145    }
00146 else
00147    {
00148    return capacity;
00149    }
00150 }


© sourcejam.com 2005-2008