1828234 Members
2309 Online
109975 Solutions
New Discussion

statvfs systemcall

 
sodani
Occasional Contributor

statvfs systemcall

Hi,

Call statvfs() on an existing file. Check file system block and inode counts. Check file system ID.


Solution:
=========


#define ExistingFile "/shwetha/readme.htm"

strcpy(DirectoryName,ExistingFile);
fd = statvfs(DirectoryName,&buf);
perror("1.Systemcall statvfs failed on ExistingFile\n");
}
else {
fprintf (stdout,"Systemcall statvfs Success on ExistingFile\n");
if(buf.f_blocks & buf.f_files & buf.f_fsid) {
fprintf (stdout, "successfully verified the the file system block, inode c
ount and file system ID \n");
}
else {
perror ("Failed to verify the the file system block, inode count and file
system ID\n");
}
}


The testcase for checking the file system block , inode counts,file system ID the logic which i used is with & operator.
i think this logic is wrong..
Please let me know how to do this..

Thanks in Advance,
shwetha

3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: statvfs systemcall

>Call statvfs() on an existing file.

This looks like an exam or homework question. This forum is not for those questions.

>the logic which i used is with & operator.

Yes, "&" is the wrong operator. Perhaps you want to use "&&" for logical AND. But checking for non-zero doesn't really "verify" anything.
James R. Ferguson
Acclaimed Contributor

Re: statvfs systemcall

HI:

As Dennis noted, checking a non-zero return status doesn't provide a great amount of information. You would be better to use 'strerror()' and 'errno' to be able to relate errors to those documented in the manpages for 'statvfs()' :

http://www.docs.hp.com/en/B3921-60631/statvfs.2.html

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: statvfs systemcall

>JRF: checking a non-zero return status doesn't provide a great amount of information

I wasn't talking about the return status since that wasn't in the above fragment. (A bug)
I was pointing out this if:
if(buf.f_blocks & buf.f_files & buf.f_fsid) {