linux - 获取文件的纳秒精度 atime、mtime、ctime 字段(stat?)

标签 linux filesystems linux-kernel stat

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

最佳答案

秒分辨率时间在字段中:

           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说:

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 )

 unsigned long st_atime_nsec;

 unsigned int st_mtime_nsec;

 unsigned long st_ctime_nsec;

 #define STAT_HAVE_NSEC 1

关于linux - 获取文件的纳秒精度 atime、mtime、ctime 字段(stat?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7206014/

相关文章:

linux - 从 PDF 中删除图像(带透明度/alpha channel )

linux - 在 Windows 中从 Linux Samba CVSROOT check out CVS

c++ - 凯特安装问题

c++ - 在 ofstream 写入期间检测到空间不足,stream.fail() 无法工作

google-app-engine - App Engine - 上传文件时出现 tmp/文件系统错误

linux - nvm:在Shell脚本中引用 "default"Node 版本路径

c# - 重复的 GetAccessRules、FileSystemAccessRule 条目

linux - 从/proc/$PID/smaps 读取很慢

linux - 中断处理程序使用哪个堆栈 - Linux

c - 为什么导出的由另一个驱动程序修改的常量值未在原始驱动程序中更新