首页 > Web开发 > 详细

learning statfs func

时间:2020-01-09 19:18:41      阅读:70      评论:0      收藏:0      [点我收藏+]

statfs 查询文件系统相关的信息。

code:

#include <sys/statfs.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
    struct statfs sfs;

    if (argc != 2 || strcmp(argv[1], "--help") == 0){
             return -1;
    }
             

    if (statfs(argv[1], &sfs) == -1){
            perror("statfs");
            return -1;
    }

    printf("File system type:              %#lx\n",
            (unsigned long) sfs.f_type);
    printf("Optimal I/O block size:        %lu\n",
            (unsigned long) sfs.f_bsize);
    printf("Total data blocks:             %lu\n",
            (unsigned long) sfs.f_blocks);
    printf("Free data blocks:              %lu\n",
            (unsigned long) sfs.f_bfree);
    printf("Free blocks for nonsuperuser:  %lu\n",
            (unsigned long) sfs.f_bavail);
    printf("Total i-nodes:                 %lu\n",
            (unsigned long) sfs.f_files);
    printf("File system ID:                %#x, %#x\n",
            (unsigned) sfs.f_fsid.__val[0], (unsigned) sfs.f_fsid.__val[1]);
    printf("Free i-nodes:                  %lu\n",
            (unsigned long) sfs.f_ffree);
    printf("Maximum file name length:      %lu\n",
            (unsigned long) sfs.f_namelen);

    exit(0);
}
    

result:

# ./a.out /dev/sdb1
File system type:              0x1021994
Optimal I/O block size:        4096
Total data blocks:             756675
Free data blocks:              756675
Free blocks for nonsuperuser:  756675
Total i-nodes:                 756675
File system ID:                0, 0
Free i-nodes:                  756172
Maximum file name length:      255

learning statfs func

原文:https://www.cnblogs.com/lianghong881018/p/12172477.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!