Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

statfs() problem?

Status
Not open for further replies.

varthi

Programmer
Feb 14, 2002
6
IN
HI,

I want find hard disk free space.
I tried to find by using statfs() function .But vaules that are coming from the statfs() function is different from the one i am getting using "df" command .

code:
#include<sys/types.h>
#include<sys/stat.h>
#include<sys/vfs.h>
#include<stdio.h>
#include<iostream.h>
main()
{
long nFreeSpace=0;
struct statfs *pStatfs;

pStatfs = new struct statfs;

statfs(&quot;/&quot;,pStatfs);

nFreeSpace = pStatfs->f_bfree;

printf(&quot;%d \n&quot;, nFreeSpace);

}

provide solution to find the free harddisk space.
I am using Redhat Linux7.2 ,gcc version 2.96 to compile the above program

Thanks
varthim

 
Just a guess but looking at the man for statfs I believe
the size is in blocks not bytes while df is bytes.
I think the solution is
myStatfs.f_bsize * myStatfs.f_bfree. ?


struct statfs {
u_int32_t f_flags; /* copy of mount flags */
int32_t f_bsize; /* fundamental file system block size */
u_int32_t f_iosize; /* optimal transfer block size */
u_int32_t f_blocks; /* total data blocks in file system */
u_int32_t f_bfree; /* free blocks in fs */
int32_t f_bavail; /* free blocks avail to non-superuser */
u_int32_t f_files; /* total file nodes in file system */
u_int32_t f_ffree; /* free file nodes in fs */
fsid_t f_fsid; /* file system id */
uid_t f_owner; /* user that mounted the file system */
u_int32_t f_syncwrites; /* count of sync writes since mount */
u_int32_t f_asyncwrites; /* count of async writes since mount */
u_int32_t f_spare[4]; /* spare for later */
char f_fstypename[MFSNAMELEN]; /* fs type name */
char f_mntonname[MNAMELEN]; /* directory on which mounted */
char f_mntfromname[MNAMELEN]; /* mounted file system */
union mount_info mount_info; /* per-filesystem mount options */
};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top