#include <sys/stat.h>
int stat(const char *restrict pathname, struct stat * restrict buf);
int fstat(int fd, struct stat *buf);
int lstat(const char *restrict pathname, struct stat *restrict buf);
int fstat(int fd, const char *restrict pathname, struct stat *restrict buf, int flag);
一旦给出pathname,stat函数将返回与此命名文件有关的信息结构。
fstat函数获得已在描述符fd上打开文件的有关信息。
lstat函数类似于stat,但是当命名文件是一个符号链接时,lstat返回该符号链接的有关信息,而不是由该符号链接引用的文件的信息。
fstatat函数为一个相对于当前打开目录(由fd参数指向)的路径名返回文件统计信息。
struct stat{
mode_t st_mode; //file type & mode(permissions)
ino_t st_ino; //i-node number (serialnumber)
dev_t st_dev; //device number (file system)
dev_t st_rdev; //device number for special files
nlink_t st_nlink; //numbser of links
uid_t st_uid; //user ID of owner
git_t st_gid; //group ID of owner
off_t st_size; //size in bytes, for regular files
struct timespec st_atime; //time of last access
struct timespec st_mtime; //time of last modification
struct timespec st_ctime; //time of last file status change
blksize_t st_blksize; //best I/O block size
blkcnt_t st_blocks; //number of disk blocks allocated
};