![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| command to find free disk space on solaris | harishankar | SUN Solaris | 2 | 08-26-2007 08:47 AM |
| How to get free disk space size in C/C++ program( Solaris system) | yidu | High Level Programming | 3 | 08-07-2007 02:26 AM |
| free space, associated by filesystem name... | mr_manny | SUN Solaris | 2 | 10-31-2005 09:47 AM |
| available disk space on disk device??? | alan | UNIX for Dummies Questions & Answers | 4 | 01-02-2004 12:06 AM |
| Device Free Space | jorge.ferreira | UNIX for Dummies Questions & Answers | 1 | 12-12-2003 08:17 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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. |
|||
| Google The UNIX and Linux Forums |