【问题标题】:Get a nanosecond-precise atime, mtime, ctime fields for file (stat?)获取文件的纳秒精度 atime、mtime、ctime 字段(stat?)
【发布时间】:2011-08-26 14:15:46
【问题描述】:

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

【问题讨论】:

    标签: linux filesystems linux-kernel stat


    【解决方案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 的“注释”部分说:

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

    【讨论】:

    • 那么,如果我希望我的程序是可移植的,我应该使用哪一个:st_atim.tv_nsecst_atimensec
    • 如何使其与 NetBSD 和 OSX 特定实现兼容(支持纳秒但具有不同类型的广告名称)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-10
    • 2023-03-17
    • 2014-09-08
    • 2015-08-24
    • 2015-08-23
    • 1970-01-01
    相关资源
    最近更新 更多