Friday, October 21, 2005

statvfs / df bug?

statvfs / df bug?

Hi all,
I am trying to get the filesystem information using statvfs/df. I have
an automounted partition mounted on /mntauto. I am running SunOS 5.8

If I say 'df -k /mntauto', I get the following output:
--------
bash-2.03# df -k /mntauto
Filesystem kbytes used avail capacity Mounted on
cpsupsun1:/mntauto 482455 10 434200 1% /mntauto
--------

I have written two different programs using 'statvfs' to print the
filesystem information. Following is the putput fron these two
different programs:

Program 1:
main() {
struct statvfs info;

access("/mntauto",F_OK);

if (-1 == statvfs("/", &info))
perror("statvfs() error");
else {
puts("statvfs() returned the following information");
puts("about the ('/mntauto') file system:");
printf(" f_bsize : %u\n", info.f_bsize);
printf(" f_blocks : %u\n", info.f_blocks);
printf(" f_bfree : %u\n", info.f_bfree );
printf(" f_bavail : %u\n", info.f_bavail);
printf(" f_files : %u\n", info.f_files);
printf(" f_ffree : %u\n", info.f_ffree);
printf(" f_fsid : %u\n", info.f_fsid);
printf(" f_flag : %X\n", info.f_flag);
printf(" f_namemax : %u\n", info.f_namemax);
printf(" f_basetype : %s\n", info.f_basetype);
printf(" f_fstr : %s\n", info.f_fstr);

}

}

Output:
statvfs() returned the following information
about the ('/mntauto') file system:
f_bsize : 8192
f_blocks : 4129290
f_bfree : 3026760
f_bavail : 2985468
f_files : 512512
f_ffree : 507103
f_fsid : 8388608
f_flag : 4
f_namemax : 255
f_basetype : ufs
f_fstr :

Program 2:

main() {
struct statvfs info;
struct stat sb;

if (stat("/mntauto/log", &sb) < 0)
printf("stat failed\n");

if (S_ISDIR(sb.st_mode))
printf("Dir\n");
else
printf("Not a dir\n");

if (-1 == statvfs("/mntauto", &info))
perror("statvfs() error");
else {
puts("statvfs() returned the following information");
puts("about the ('/mntauto') file system:");
printf(" f_bsize : %u\n", info.f_bsize);
printf(" f_blocks : %u\n", info.f_blocks);
printf(" f_bfree : %u\n", info.f_bfree );
printf(" f_bfree : %u\n", info.f_bavail);
printf(" f_files : %u\n", info.f_files);
printf(" f_ffree : %u\n", info.f_ffree);
printf(" f_fsid : %u\n", info.f_fsid);
printf(" f_flag : %X\n", info.f_flag);
printf(" f_namemax : %u\n", info.f_namemax);
printf(" f_basetype : %s\n", info.f_basetype);
printf(" f_fstr : %s\n", info.f_fstr);
}

}

Output:
Dir
statvfs() returned the following information
about the ('/mntauto') file system:
f_bsize : 8192
f_blocks : 964910
f_bfree : 964890
f_bfree : 868400
f_files : 247296
f_ffree : 247290
f_fsid : 80740364
f_flag : 0
f_namemax : 4294967295
f_basetype : nfs
f_fstr :

Could anyone please explain me the differences between the above
outputs? I assume all of the above should print the same answer...Is
this a know bug of statvfs?

Thanks in advance,
Tushar.

Reply


My apologies.
I got the error!
It was a typo...

I would say everything is working okay.
Program 1 does a statvfs of "/" and program 2 calls statvfs for "/mntauto".

0 Comments:

Post a Comment

<< Home