小编典典

获取文件的纳秒精度atime,mtime,ctime字段(状态?)

linux

一些文件系统(例如ext4和JFS)提供atime /
mtime字段的纳秒分辨率。如何读取ns分辨率字段?该stat系统调用返回time_t其为第二分辨率。


阅读 438

收藏
2020-06-07

共1个答案

小编典典

第二解析时间在以下字段中:

           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 */

但是该人http://www.kernel.org/doc/man-
pages/online/pages/man2/stat.2.html的 “ NOTES”部分说:

从内核2.5.48开始,stat结构为三个文件时间戳字段支持纳秒分辨率。如果定义了_BSD_SOURCE或_SVID_SOURCE功能测试宏,则Glibc将使用st_atim.tv_nsec形式的名称来公开每个字段的纳秒分量。这些字段是在POSIX.1-2008中指定的,并且从版本2.12开始,如果_POSIX_C_SOURCE的值定义为200809L或更大,或者_XOPEN_SOURCE的值定义为700或更大,则glibc也将公开这些字段名。如果没有定义上述宏,则以st_atimensec形式的名称公开纳秒值。

因此,nsec的时间部分在同一“ struct stat”中:(/usr/include/asm/stat.h)

 unsigned long st_atime_nsec;

 unsigned int st_mtime_nsec;

 unsigned long st_ctime_nsec;

 #define STAT_HAVE_NSEC 1
2020-06-07