Get a nanosecond-precise atime, mtime, ctime fields for file (stat?)

前端 未结 1 968
[愿得一人]
[愿得一人] 2020-12-31 10:16

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 whi

相关标签:
1条回答
  • 2020-12-31 10:58

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

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

    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.

    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
    
    0 讨论(0)
提交回复
热议问题