C Program to Get Linux Disc Space Info

Linux Disc Spac Information Retrieving

The C program for Linux disc space information gathering is used to check how much used and free disk space available in the File storage system

C Program to Get Disc Usage Information


#include <sys/statvfs.h>
#include <glib.h>

gchar *
g_get_capacity ( gchar * dev_path)
{
unsigned long long result = 0;
int n;
gchar s_cap[50];
gchar * ss_cap = "N/A";
struct statvfs sfs;
if ( statvfs ( dev_path, &sfs) != -1 )
{
result = (unsigned long long)sfs.f_bsize * sfs.f_blocks;
}
if (result > 0)
{
double f_cap = (double)result/(1024*1024);
n = sprintf(s_cap, "%.2f Mb", f_cap);
ss_cap = g_strdup(s_cap);
}
return ss_cap;
}

gchar *
g_get_free_space ( gchar * dev_path)
{
unsigned long long result = 0;
int n;
gchar s_cap[50];
gchar * ss_cap = "N/A";
struct statvfs sfs;
if ( statvfs ( dev_path, &sfs) != -1 )
{
result = (unsigned long long)sfs.f_bsize * sfs.f_bfree;
}
if (result > 0)
{
double f_cap = (double)result/(1024*1024);
n = sprintf(s_cap, "%.2f Mb", f_cap);
ss_cap = g_strdup(s_cap);
}
return ss_cap;
}


Related Topic How to Install Anti-virus ClamAV
How to Protect the Linux Machine against Dangerous Malware rootkits
What is the Difference between Linux & Windows Swap Files
Linux Swap Partition Installation
CentOS Latest Version Download & Installation Guide
C  Linux  

nScraps.com 2011   Privacy Policy  Terms of Service  Feedback