Skip to main content

Get Disk Details Values in C function Nice one

I want to get the disk details in the format like type, size, used and available space;
The output should be
* disk_details[0] contains mounted FS type
* disk_details[1] contains mounted FS size
* disk_details[2] contains mounted FS used space
* disk_details[3] contains mounted FS Available space
* disk_details[4] contains mounted FS % used space
where FS is file system
Basically i want the output of $df -h | grep /mnt in a c function,
here is the c function which takes double dimension array as in input; updates it with disk details.
int get_disk_details(char disk_details[][50])
{
FILE *fp;
char df_buf[90];
char *name1,*result;
int i;
char *tmp;

system("df -h | grep /mnt | awk '{print $6,$2,$3,$4,$5}' > /var/temp2.txt");
fp= fopen("/var/temp2.txt","r");
i=0;
while(fgets(df_buf,80,fp))
{
result = strtok(df_buf, " ");
while(result != NULL)
{
if(strncmp(result,"/mnt/",5) == 0)
{
name1 = result;
name1 = name1+5;
tmp = strdup(name1);
strcpy(disk_details[i],tmp);
i++;
}
else
{
tmp = strdup(result);
strcpy(disk_details[i],tmp);
i++;
}
result = strtok(NULL," ");
}
}
fclose(fp);

return 0;
}

usage could be
declare
char df_details[5][50];
call from main;
get_disk_details(df_details);

Comments

Popular posts from this blog

ahsec results 2008 | www.ahsec.nic.in

The official website of assam higher secondary education council Results of Assam is down seems they are uploading results , direct link to check ahsec results 2008 is http://resultsassam.nic.in/index.asp You can find results of AHSEC at the link above. current page The Website www.ahsec.nic.in Designed Developed & Hosted by NIC, Assam State Centre, Guwahati is down for result uploading. keep checking this page, I will update as soon as news comes. All the best to AHSEC - assam higher secondary education council students. Direct links http://assam.nic.in/ www.ahsec.nic.in http://resultsassam.nic.in/

Rajasthan Board 10th Results | rajedubord.nic.in | RBSE

Raj Board of Secondary Education, Rajasthan Results at rajeduboard.nic.in Board of Secondary Education, Rajasthan Ajmer declared result of secondary examination today at 4PM official site is rajedubord.nic.in check Secondary Examination- 2008 Result (To be announced on July 1st, 2008 at 4:00 PM) source http:// rajresults.nic.in / Declared result Praveshika Examination-2008 Result (Announced on June 25, 2008 at 4:00 PM) The history of the Board of Secondary Education Rajasthan (BSER) is a remarkable panorama of progressive record of the futurological vision for developing a dynamic system of various sub-systems of examinations and highlights of the academic excellence of the last four decades. The BSER took rapid strides for promotion and development of Secondary Education in Rajasthan, spread over 3,42,239 sq. km. and in more than 6000 schools located in 32 districts involving 8.5 lakhs students for Secondary and Senior Secondary Examination in the year 2000. At present the Board is ...