1

任何人都可以找出这段代码中的问题。问题是它为所有路径名显示相同的输出,即使它们具有不同的内容、不同的文件。

#include<stdio.h>  
#include<sys/stat.h>
#include<unistd.h>  
#include<sys/types.h>
#include<sys/vfs.h>
int main(int argc,char *argv[])  
{
    struct statfs sb;
    if((statfs(argv[1],&sb))==0)
    {
            printf("optimal transfer blk size is %d\n",sb.f_bsize);
            printf("total data blocks are %d\n",sb.f_blocks);
            printf("free blocks in fs are %d\n",sb.f_bfree);
            printf("total file nodes in fs are %d\n",sb.f_files);
            printf("free file nodes in fs are %d\n",sb.f_ffree);
    }
}

[testuser@hdchshocms6344 ex4]$ ./a.out /home/testuser
optimal transfer blk size is 4096  
total data blocks are 8819390
free blocks in fs are 6771045  
total file nodes in fs are 2240224  
free file nodes in fs are 1927385 

[testuser@hdchshocms6344 ex4]$ ./a.out /home/testuser/harish
optimal transfer blk size is 4096
total data blocks are 8819390
free blocks in fs are 6771034
total file nodes in fs are 2240224
free file nodes in fs are 1927386

提前致谢。

4

1 回答 1

1

statfs提供已安装文件系统的信息,而不是目录。除非/home/testuser/harish是完全不同的文件系统(即您已经在该位置安装了一个分区),否则您会得到与/home/testuser.

于 2012-05-02T05:39:54.353 回答