The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


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
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 02-13-2008
Registered User
 

Join Date: Feb 2008
Posts: 2
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
Reply With Quote
Forum Sponsor
  #2  
Old 02-13-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,199
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;
}
Regards
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0