使用stat (/usr/include/sys/stat.h)系统调用,接口如下:
stat (__const char *__path, struct stat *__statbuf)
得到的信息在stat结构体中:
struct stat
{
__dev_t st_dev; /* Device. */
#if __WORDSIZE == 32
unsigned short int __pad1;
#endif
#if __WORDSIZE == 64 || !defined __USE_FILE_OFFSET64
__ino_t st_ino; /* File serial number. */
#else
__ino_t __st_ino; /* 32bit file serial number. */
#endif
#if __WORDSIZE == 32
__mode_t st_mode; /* File mode. */
__nlink_t st_nlink; /* Link count. */
#else
__nlink_t st_nlink; /* Link count. */
__mode_t st_mode; /* File mode. */
#endif
__uid_t st_uid; /* User ID of the file's owner. */
__gid_t st_gid; /* Group ID of the file's group.*/
#if __WORDSIZE == 64
int pad0;
#endif
__dev_t st_rdev; /* Device number, if device.