4.25 小结

来源:互联网 发布:日本留学生中国知乎 编辑:程序博客网 时间:2024/06/02 16:17

本章内容一直围绕stat结构,分析了stat各个成员在表示文件相关属性中的意义以及相对应的操作函数:

1、文件的stat结构反应了文件在文件系统中的管理信息。

2、GNU C 对stat结构的定义如下,熟悉这个定义很重要。

struct stat  {    __dev_t st_dev;/* Device.  */    unsigned short int __pad1;    __ino_t __st_ino;/* 32bit file serial number.*/    __mode_t st_mode;/* File mode.  */    __nlink_t st_nlink;/* Link count.  */    __uid_t st_uid;/* User ID of the file's owner.*/    __gid_t st_gid;/* Group ID of the file's group.*/    __dev_t st_rdev;/* Device number, if device.  */    unsigned short int __pad2;    __off_t st_size;/* Size of file, in bytes.  */    __blksize_t st_blksize;/* Optimal block size for I/O.  */    __blkcnt_t st_blocks;/* Number 512-byte blocks allocated. */    __time_t st_atime;/* Time of last access.  */    unsigned long int st_atimensec;/* Nscecs of last access.  */    __time_t st_mtime;/* Time of last modification.  */    unsigned long int st_mtimensec;/* Nsecs of last modification.  */    __time_t st_ctime;/* Time of last status change.  */    unsigned long int st_ctimensec;/* Nsecs of last status change.  */  };

3、成员及其相关操作函数列表成员操作函数或宏st_modeS_ISXXX系列宏
S_ISUID宏
S_ISGID宏
S_IXXXX系列常量及位运算
umask函数
chomd和fchmod函数st_uid
st_gidchown、fchown和lchown函数st_atime
st_mtime
st_ctimeutime            

4、stat结构反映的文件信息实质是与目录项和i节点相关的信息。理解下图对理解文件系统和文件目录项相关的操作函数是有帮助的。