LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-10-2006, 04:37 AM   #1
ninjanesto
LQ Newbie
 
Registered: Nov 2006
Posts: 1

Rep: Reputation: 0
cal free disk space


I all,
i'm trying to calculate the disk usage and free space using statvfs.
I' using this code but when I execute th "df ." the values dont match
Can anyone help me??

Best regards

/* Any file on the filesystem in question */
char *filename = "/home/nesto/test/test.cpp";

struct statvfs buf;
if (!statvfs(filename, &buf)) {

unsigned long blksize, blocks, freeblks, disk_size, used, free;
blksize = buf.f_bsize;
blocks = buf.f_blocks;
freeblks = buf.f_bfree;
disk_size = blocks * blksize;
free = freeblks * blksize;
used = disk_size - free; printf("Disk usage : %lu \t Free space %lu\n", used, free);

} else {

printf("Couldn't get file system statistics\n");
}
return 0;
 
Old 11-10-2006, 03:52 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
df . prints values in 1K size, so you need to multiply by 4, not by blksize.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
No free space on disk, but there is? Recirqie SUSE / openSUSE 4 02-22-2013 01:17 PM
How t get it known free disk space? ukrainet Linux - General 3 05-06-2008 10:52 PM
Free up disk space TheShemeta Slackware 5 11-26-2003 04:50 PM
free disk space? Alf829 Linux - Newbie 3 08-01-2003 11:26 AM
How to see free disk space bripage Linux - General 3 04-29-2002 08:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration