![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to get free disk space size in C/C++ program( Solaris system) | yidu | High Level Programming | 4 | 01-30-2009 12:49 AM |
| command to find free disk space on solaris | harishankar | SUN Solaris | 2 | 08-26-2007 11:47 AM |
| free space, associated by filesystem name... | mr_manny | SUN Solaris | 2 | 10-31-2005 12:47 PM |
| available disk space on disk device??? | alan | UNIX for Dummies Questions & Answers | 4 | 01-02-2004 03:06 AM |
| Device Free Space | jorge.ferreira | UNIX for Dummies Questions & Answers | 1 | 12-12-2003 11:17 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
free disk space calc
I everybody!!
How can i use statvfs() to calculate disk usage and free disk space?? Im using this code: /* 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; But when i execute "df ." the values dont match Can anyone help me. Best regards to all |
|
||||
|
Two points:
POSIX df reports blocks, you are reporting blocks * blocksize Since you are reporting on a filesystem, other users can create/delete files, so that in the time you run your code, exit, and then do a df, a lot can happen. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|