9.文件的元数据,内存映射文件
文件的元数据
#include
int stat(char const* path,struct stat* buf);
int fstat(int fd,struct stat* buf);
int lstat(char const* path, struct stat* buf);
功能:从 i 节点中提取文件的元数据,即文件的属性信息
参数: path 文件路径
buf 文件元数据结构,存在这里,被称为输出型参数
fd 文件描述符
返回值:成功返回0,失败返回-1
struct stat s;
stat(".....',&s); //保存元数据
lstat()函数与另外两个函数的区别在于它不跟踪符号链接(软连接)
例:
abc.txt ------> xyz.txt abc.txt文件是xyz.txt文件的符号链接
stat("abc.txt",...) //得到xyz.txt文件的元数据
lstat("abc.txt"); //得到abc.txt文件的元数据
xyz有自己的i节点和数据块
而abc也有自己的 i 节点和数据块, 它的数据块,记录着xyz的完整路径
stat通过abc找到xyz文件的元数据
而lstat则不去追踪,只获得abc的元数据
stat函数通过stat结构体,向调用者输出文件的元数据
struct stat{
dev_t st_dev; //设备ID
ino_t st_ino; //i节点号
nlink_t st_nlink; //硬链接数
uid_t st_uid; //拥有者用户ID
gid_t st_gid; //拥有者组ID
dev_t st_rdev; //特殊设备ID
off_t st_size; //总字节数
blksize_t st_blksize;//I/O块字节数
blkcnt_t st_blocks;//存储块数
time_t st_atime; //最后访问时间
time_t st_mtime; //最后修改时间
time_t st_ctime; //最后状态改变时间
}
文件元数据结构
1.stat结构的st_mode成员表示文件的类型和权限,该成员在stat结构中被声明为mode_t类型,其原始类型在32位系统中被定义为unsigned int,即32位无符号整数,但到目前为止
因篇幅问题不能全部显示,请点此查看更多更全内容