博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
stat函数组
阅读量:4298 次
发布时间:2019-05-27

本文共 2739 字,大约阅读时间需要 9 分钟。

1、索引号

      –一个文件对应一个索引号inode,inode是文件系统提供的唯一数值编址,

      这个数值叫inode编号(索引号)

      –使用命令"ls -i""ls -al""ls -ail"可以查看索引号等元数据

      – inode中存储了与文件相关的元数据。

2、通过ls命令查看到的文件信息,都可以使用stat函数组提取出来

3、stat函数组

     –使用命令man stat查看相关文档

4、函数int stat(const char *path, struct stat *buf)

     –参数*path:文件路径
     –参数*buf:文件信息
     –返回值:成功为0,否则为-1

5、函数int fstat(int fd, struct stat *buf);

     –参数fd:文件描述符
     –参数*buf:文件信息
     –返回值:成功为0,否则为-1

6、函数int lstat(const char *path, struct stat *buf);

     –参数*path:文件路径
     –参数*buf:返回文件的信息,针对符号链接,lstat 返回链接本身,而不是而非目标文件
     –返回值:成功为0,否则为-1

7、struct stat 结构体:

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 */               /* Since Linux 2.6, the kernel supports nanosecond                  precision for the following timestamp fields.                  For the details before Linux 2.6, see NOTES. */               struct timespec st_atim;  /* time of last access */               struct timespec st_mtim;  /* time of last modification */               struct timespec st_ctim;  /* time of last status change */           #define st_atime st_atim.tv_sec      /* Backward compatibility */           #define st_mtime st_mtim.tv_sec           #define st_ctime st_ctim.tv_sec};

例:

#include 
//通过man文档可以查看到stat函数组头文件#include
#include
#include
//open函数的参数头文件#include
int main(int argc,char *argv[]){ struct stat groupstat; int fd,ret; if(argc <2){ printf("\nPlease input file path\n"); return 1; }//stat函数测试 ret = stat(argv[1],&groupstat); if(ret){ printf("Please make sure file path\n"); return 1; } printf("stat function test , %s of st_ino inode is %ld\n",argv[1],groupstat.st_ino); //fstat函数测试 fd = open(argv[1],O_RDWR|O_NOCTTY|O_NDELAY); if(fd<0) { printf("Please make sure file path\n"); return 1; } ret = fstat(fd,&groupstat); if(ret){ printf("Please make sure file path\n"); return 1; } printf("fstat function test , %s of st_ino inode is %ld\n",argv[1],groupstat.st_ino); //lstat函数测试 ret = lstat(argv[1],&groupstat); if(ret){ printf("Please make sure file path\n"); return 1; } printf("lstat function test , %s of st_ino inode is %ld\n",argv[1],groupstat.st_ino); return 0;}

转载地址:http://uynws.baihongyu.com/

你可能感兴趣的文章
vnpy通过jqdatasdk初始化实时数据及历史数据下载
查看>>
设计模式19_状态
查看>>
设计模式20_观察者
查看>>
vnpy学习10_常见坑
查看>>
vnpy学习10_常见坑02
查看>>
用时三个月,终于把所有的Python库全部整理了!拿去别客气!
查看>>
pd.stats.ols.MovingOLS以及替代
查看>>
vnpy学习11_增加测试评估指标
查看>>
资金流入流出计算方法
查看>>
海龟交易法则07_如何衡量风险
查看>>
海龟交易法则08_风险与资金管理
查看>>
海龟交易法则09_海龟式积木
查看>>
海龟交易法则10_通用积木
查看>>
海龟交易法则14_掌控心魔
查看>>
海龟交易法则15_万事俱备
查看>>
海龟交易法则16_附原版海龟交易法则
查看>>
克罗谈投资策略01_期货交易中的墨菲法则
查看>>
克罗谈投资策略02_赢家和输家
查看>>
克罗谈投资策略03_你所期望的赌博方式
查看>>
克罗谈投资策略04_感觉与现实
查看>>