获取文件的纳秒级 atime、mtime、ctime 字段(stat?) [英] Get a nanosecond-precise atime, mtime, ctime fields for file (stat?)

查看:25
本文介绍了获取文件的纳秒级 atime、mtime、ctime 字段(stat?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些文件系统(例如 ext4 和 JFS)提供 atime/mtime 字段的纳秒分辨率.如何读取 ns 分辨率字段?stat 系统调用 返回 time_t 这是第二个分辨率.

Some filesystems (e.g. ext4 and JFS) offer nanosecond resolution of atime/mtime fields. How can I read ns-resolution fields? The stat syscall returns time_t which is a second-resolution.

推荐答案

第二次解析时间在字段中:

The second-resolution times are in the fields:

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

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

But "NOTES" section of the man http://www.kernel.org/doc/man-pages/online/pages/man2/stat.2.html says:

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

Since kernel 2.5.48, the stat structure supports nanosecond resolution for the three file timestamp fields. Glibc exposes the nanosecond component of each field using names of the form st_atim.tv_nsec if the _BSD_SOURCE or _SVID_SOURCE feature test macro is defined. These fields are specified in POSIX.1-2008, and, starting with version 2.12, glibc also exposes these field names if _POSIX_C_SOURCE is defined with the value 200809L or greater, or _XOPEN_SOURCE is defined with the value 700 or greater. If none of the aforementioned macros are defined, then the nanosecond values are exposed with names of the form st_atimensec.

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

So, nsec parts of times are in the same "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

这篇关于获取文件的纳秒级 atime、mtime、ctime 字段(stat?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆