intstat(constchar *pathname, struct stat *statbuf); intfstat(int fd, struct stat *statbuf); intlstat(constchar *pathname, struct stat *statbuf);
structstat { 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 *///用户ID gid_t st_gid; /* group ID of owner *///组ID dev_t st_rdev; /* device ID (if special file) */ off_t st_size; /* total size, in bytes */ blksize_t st_blksize; /* blocksize for file system 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 */ };
目前,st_mode使用了其低19bit. 0170000 => 1+ 3*5 = 16. 其中,最低的9位(0-8)是权限,9-11是id,12-15是类型。 具体定义如下: S_IFMT 0170000 bitmask for the file type bitfields S_IFSOCK 0140000 socket S_IFLNK 0120000 symbolic link S_IFREG 0100000 regular file S_IFBLK 0060000 block device S_IFDIR 0040000 directory S_IFCHR 0020000 character device S_IFIFO 0010000 fifo S_ISUID 0004000set UID bit S_ISGID 0002000set GID bit (see below) S_ISVTX 0001000 sticky bit (see below) S_IRWXU 00700 mask for file owner permissions S_IRUSR 00400 owner has read permission S_IWUSR 00200 owner has write permission S_IXUSR 00100 owner has execute permission S_IRWXG 00070 mask for group permissions S_IRGRP 00040 group has read permission S_IWGRP 00020 group has write permission S_IXGRP 00010 group has execute permission S_IRWXO 00007 mask for permissions for others (not in group) S_IROTH 00004 others have read permission S_IWOTH 00002 others have write permisson S_IXOTH 00001 others have execute permission //使用宏快速判断文件类型 S_ISREG(m) is it a regular file?