常用文件属性获取

《朱老师物联网大讲堂》学习笔记  

学习地址:www.zhulaoshi.org


文件属性,

文件的属性信息,只能被专用的api打开看到,

常用的api有,stat,fstat,lstat,

同时stat也是一个shell命令,其内部调用的也是stat,

       int stat(const char *path, struct stat *buf);

       int fstat(int fd, struct stat *buf);

       int lstat(const char *path, struct stat *buf);

fstat是从内存中读取,stat是从硬盘读取,

lstat与上面的差别是,对于符号链接文件,stat和fstat查看的都是符号链接文件指向的文件,lstat查看的是符号链接文件本身的属性个,

           struct stat {

               dev_t     st_dev;     /* ID of device containing file */

               ino_t     st_ino;     /* inode number */

               mode_t    st_mode;    /* protection */

               nlink_t   st_nlink;   /* number of hard links */

               uid_t     st_uid;     /* user ID of owner */

               gid_t     st_gid;     /* group ID of owner */

               dev_t     st_rdev;    /* device ID (if special file) */

               off_t     st_size;    /* total size, in bytes */

               blksize_t st_blksize; /* blocksize for filesystem I/O */

               blkcnt_t  st_blocks;  /* number of 512B blocks allocated */

               time_t    st_atime;   /* time of last access */

               time_t    st_mtime;   /* time of last modification */

               time_t    st_ctime;   /* time of last status change */

           };

  //这里面的一些属性,某些文件用不到

struct stat buf;

ret = stat( name, &buf );

  

  

stat a.out,

即可查看文件属性,


IO BLOCK :1024,

即文件读写缓冲区大小,


struct stat结构体,

包含在sys/stat.h中声明,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值