Inconsistency between calls to "os.Chtimes()" and "stat.Sys().(syscall.Stat_t).Mtimespec"

179 views
Skip to first unread message

Carter Peel

unread,
Oct 14, 2021, 8:31:02 AM10/14/21
to golang-nuts
Hello,

I'm developing a library that does full-filesystem change tracking. Ideally, one would just compare the current ModTime to the previously cached ModTime.

Unfortunately, I've found that nanosecond accuracy is nonexistent, and even the truncated results (code shown below) seem to skew occasionally.

Thoughts anyone?
timespec_inaccuracy.png

Kurtis Rader

unread,
Oct 14, 2021, 1:22:05 PM10/14/21
to carte...@gmail.com, golang-nuts
Please don't send screen captures. They're hard to read and people can't copy/paste the code. Ideally you would send a https://play.golang.org/ link but simply copy/pasting your code into the email is fine too.

Note that file timestamp resolution depends on the system: both hardware and OS. Even when using the same OS (e.g., Linux) on the same hardware the resolution might be different due to how the OS kernel was built. I'm not aware of any system that provides nanosecond resolution.

You also wrote "seem to skew occasionally" without providing any details, including the non-rounded (raw) value. So it's going to be hard for someone to provide an explanation since you didn't really explain what the problem is.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/71304102-dec9-4d8b-958f-88a6fd1d2610n%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Uli Kunitz

unread,
Oct 14, 2021, 2:24:28 PM10/14/21
to golang-nuts

Marvin Renich

unread,
Oct 15, 2021, 8:03:59 AM10/15/21
to golan...@googlegroups.com
* Kurtis Rader <kra...@skepticism.us> [211014 13:22]:
> Note that file timestamp resolution depends on the system: both hardware
> and OS. Even when using the same OS (e.g., Linux) on the same hardware the
> resolution might be different due to how the OS kernel was built. I'm not
> aware of any system that provides nanosecond resolution.

Also note that different filesystems on the same running host can have
different resolutions. FAT filesystems (e.g. USB memory sticks) have
only 2-second resolution, while ext2 is, I think, 1 millisecond, and
ext4 is 1 nanosecond.

...Marvin

Marvin Renich

unread,
Oct 15, 2021, 8:16:59 AM10/15/21
to golan...@googlegroups.com
* Marvin Renich <mr...@renich.org> [211015 08:04]:
> Also note that different filesystems on the same running host can have
> different resolutions. FAT filesystems (e.g. USB memory sticks) have
> only 2-second resolution, while ext2 is, I think, 1 millisecond, and
> ext4 is 1 nanosecond.

According to [1], it appears ext2 and ext3 have only 1 sec resolution.

...Marvin

[1] http://softpanorama.org/Internals/Unix_filesystems/linux_ext2_ext3.shtml

Reply all
Reply to author
Forward
0 new messages