![]() |
|
|
|
|
|||||||
| 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 |
| file system size | magasem | AIX | 7 | 02-06-2008 01:21 AM |
| increase root file system size in solaris | sriram.s | SUN Solaris | 4 | 04-02-2007 12:28 AM |
| increasing ufs file system size in solaris | BG_JrAdmin | UNIX for Dummies Questions & Answers | 6 | 12-01-2005 01:56 AM |
| File system size change | jvinn | UNIX for Advanced & Expert Users | 9 | 05-11-2005 03:13 PM |
| Free size for File System | videsh77 | UNIX for Dummies Questions & Answers | 7 | 02-03-2005 03:44 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
how to get the file system size
I have the next code, and the output is incosistent, what is the problem:
free blocks: 1201595 block size: 4096 total size(free blocks * block size): 626765824 1201595 * 4096 not is 626765824, what's the problem??? #include <sys/statvfs.h> #include <stdio.h> int main(){ struct statvfs buffer; int status; int free_blk; int blk_size; status = statvfs("/", &buffer); printf("free blocks: %u\n",buffer.f_bavail); printf("block size: %u\n",buffer.f_bsize); free_blk = buffer.f_bavail; blk_size = buffer.f_bsize; printf("total size: %u\n",free_blk*blk_size); return 0; } Thks |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
The problem is an integer overflow.
Declare the variables free_blk and blk_size as long and change the format of the last printf statement as follow: Code:
#include <sys/statvfs.h>
#include <stdio.h>
int main(){
struct statvfs buffer;
int status;
long free_blk;
long blk_size;
status = statvfs("/", &buffer);
printf("free blocks: %u\n",buffer.f_bavail);
printf("block size: %u\n",buffer.f_bsize);
free_blk = buffer.f_bavail;
blk_size = buffer.f_bsize;
printf("total size: %Ld\n",free_blk*blk_size);
return 0;
}
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|