1
0
mirror of https://github.com/golang/go synced 2024-10-05 02:31:21 -06:00
go/src/pkg/syscall
Nick Craig-Wood 473441fc30 os: Improve the accuracy of os.Chtimes
I've been writing some code which involves syncing files (like
rsync) and it became apparent that under Linux I could read
modification times (os.Lstat) with nanosecond precision but
only write them with microsecond precision.  This difference
in precision is rather annoying when trying to discover
whether files need syncing or not!

I've patched syscall and os to increases the accuracy of of
os.Chtimes for Linux and Windows.  This involved exposing the
utimensat system call under Linux and a bit of extra code
under Windows.  I decided not to expose the "at" bit of the
system call as it is impossible to replicate under Windows, so
the patch adds syscall.Utimens() to all architectures along
with a ImplementsUtimens flag.

If the utimensat syscall isn't available (utimensat was added
to Linux in 2.6.22, Released, 8 July 2007) then it silently
falls back to the microsecond accuracy version it uses now.
The improved accuracy for Windows should be good for all
versions of Windows.

Unfortunately Darwin doesn't seem to have a utimensat system
call that I could find so I couldn't implement it there.  The
BSDs do, but since they share their syscall implementation
with Darwin I couldn't figure out how to define a syscall for
*BSD and not Darwin.  I've left this as a TODO in the code.

In the process I implemented the missing methods for Timespec
under Windows which I needed which just happened to round out
the Timespec API for all platforms!

------------------------------------------------------------

Test code: http://play.golang.org/p/1xnGuYOi4b

Linux Before (1000 ns precision)

$ ./utimetest.linux.before z
Setting mtime 1344937903123456789: 2012-08-14 10:51:43.123456789 +0100 BST
Reading mtime 1344937903123457000: 2012-08-14 10:51:43.123457 +0100 BST

Linux After (1 ns precision)

$ ./utimetest.linux.after z
Setting mtime 1344937903123456789: 2012-08-14 10:51:43.123456789 +0100 BST
Reading mtime 1344937903123456789: 2012-08-14 10:51:43.123456789 +0100 BST

Windows Before (1000 ns precision)

X:\>utimetest.windows.before.exe c:\Test.txt
Setting mtime 1344937903123456789: 2012-08-14 10:51:43.123456789 +0100 GMTDT
Reading mtime 1344937903123456000: 2012-08-14 10:51:43.123456 +0100 GMTDT

Windows After (100 ns precision)

X:\>utimetest.windows.after.exe c:\Test.txt
Setting mtime 1344937903123456789: 2012-08-14 10:51:43.123456789 +0100 GMTDT
Reading mtime 1344937903123456700: 2012-08-14 10:51:43.1234567 +0100 GMTDT

R=golang-dev, alex.brainman, rsc, bradfitz
CC=golang-dev
https://golang.org/cl/6905057
2012-12-13 13:02:39 -08:00
..
asm_darwin_386.s
asm_darwin_amd64.s
asm_freebsd_386.s
asm_freebsd_amd64.s syscall, net: sendfile for FreeBSD 2012-06-25 20:26:19 -04:00
asm_freebsd_arm.s syscall: FreeBSD/ARM support 2012-10-12 16:26:42 +08:00
asm_linux_386.s
asm_linux_amd64.s runtime: add vdso support for linux/amd64. Fixes issue 1933. 2012-08-31 18:07:04 -04:00
asm_linux_arm.s
asm_netbsd_386.s syscall: Changes to the syscall package to support NetBSD. 2011-12-20 03:57:58 +11:00
asm_netbsd_amd64.s syscall: Changes to the syscall package to support NetBSD. 2011-12-20 03:57:58 +11:00
asm_openbsd_386.s
asm_openbsd_amd64.s
asm_plan9_386.s syscall: cleanly exit all Go procs on Plan 9 2012-04-19 16:31:26 -07:00
asm_plan9_amd64.s src: Add support for 64-bit version of Plan 9 2012-08-31 13:21:13 -04:00
asm_windows_386.s syscall: extract an ExampleLoadLibrary from comment 2012-08-29 21:44:46 +08:00
asm_windows_amd64.s syscall: extract an ExampleLoadLibrary from comment 2012-08-29 21:44:46 +08:00
bpf_bsd.go syscall: Changes to the syscall package to support NetBSD. 2011-12-20 03:57:58 +11:00
creds_test.go syscall: fix creds_test to reliably close os.File 2012-10-26 10:31:03 -07:00
dir_plan9.go os: move Plan 9 directory marshaling code to syscall 2012-11-26 15:26:46 -08:00
dll_windows.go syscall: fix data races in LazyDLL/LazyProc 2012-11-16 12:06:48 +04:00
env_plan9.go syscall: cache environment variables on Plan 9. 2012-01-31 18:14:02 -08:00
env_unix.go syscall: make Environ return original order 2012-01-09 16:51:20 -08:00
env_windows.go syscall: return EINVAL when string arguments have NUL characters 2012-08-05 17:24:32 -04:00
exec_bsd.go os,syscall: fix windows build 2012-02-11 08:47:19 +11:00
exec_linux.go syscall/exec_linux: enable changing controlling tty 2012-10-30 17:36:18 -07:00
exec_plan9.go os: move Plan 9 directory marshaling code to syscall 2012-11-26 15:26:46 -08:00
exec_unix.go race: syscall changes 2012-10-09 20:51:58 +04:00
exec_windows.go syscall: return EINVAL when string arguments have NUL characters 2012-08-05 17:24:32 -04:00
lsf_linux.go
mkall.sh syscall: let mkall.sh work on multiarch systems (like Precise) 2012-12-11 12:03:18 -05:00
mkerrors_windows.sh
mkerrors.sh syscall: implement nametomib() on netbsd 2012-05-23 01:33:48 +10:00
mksyscall_windows.pl syscall: do not use int to test network syscall results (on windows) 2012-09-25 17:06:39 +10:00
mksyscall.pl pkg/syscall: Plan 9, 64-bit: Update error checks from sys calls. 2012-09-28 09:56:44 +10:00
mksysctl_openbsd.pl
mksysnum_darwin.pl
mksysnum_freebsd.pl
mksysnum_linux.pl fix build for Linux/ARM. 2012-02-13 20:16:57 -05:00
mksysnum_netbsd.pl syscall: Changes to the syscall package to support NetBSD. 2011-12-20 03:57:58 +11:00
mksysnum_openbsd.pl
mksysnum_plan9.sh
netlink_linux.go syscall, net: use native endianness for Linux netlink messages 2012-04-04 17:41:36 -07:00
passfd_test.go syscall: add a test for passing an fd over a unix socket 2012-04-30 15:31:14 +10:00
race0.go race: syscall changes 2012-10-09 20:51:58 +04:00
race.go race: syscall changes 2012-10-09 20:51:58 +04:00
route_bsd.go net, syscall: interface address and mask 2011-12-21 21:39:00 +09:00
route_darwin.go
route_freebsd.go
route_netbsd.go syscall: Changes to the syscall package to support NetBSD. 2011-12-20 03:57:58 +11:00
route_openbsd.go
security_windows.go syscall: return EINVAL when string arguments have NUL characters 2012-08-05 17:24:32 -04:00
sockcmsg_linux.go
sockcmsg_unix.go syscall: Changes to the syscall package to support NetBSD. 2011-12-20 03:57:58 +11:00
str.go
syscall_bsd.go os: Improve the accuracy of os.Chtimes 2012-12-13 13:02:39 -08:00
syscall_darwin_386.go
syscall_darwin_amd64.go
syscall_darwin.go syscalls: annotate Sendfile() for race detector 2012-10-29 23:15:06 +04:00
syscall_freebsd_386.go syscalls: annotate Sendfile() for race detector 2012-10-29 23:15:06 +04:00
syscall_freebsd_amd64.go syscalls: annotate Sendfile() for race detector 2012-10-29 23:15:06 +04:00
syscall_freebsd_arm.go syscalls: annotate Sendfile() for race detector 2012-10-29 23:15:06 +04:00
syscall_freebsd.go race: syscall changes 2012-10-09 20:51:58 +04:00
syscall_linux_386.go syscalls: annotate Sendfile() for race detector 2012-10-29 23:15:06 +04:00
syscall_linux_amd64.go syscalls: annotate Sendfile() for race detector 2012-10-29 23:15:06 +04:00
syscall_linux_arm.go syscalls: annotate Sendfile() for race detector 2012-10-29 23:15:06 +04:00
syscall_linux.go os: Improve the accuracy of os.Chtimes 2012-12-13 13:02:39 -08:00
syscall_netbsd_386.go os/syscall: correct netbsd types/names 2012-05-15 12:00:13 +10:00
syscall_netbsd_amd64.go os/syscall: correct netbsd types/names 2012-05-15 12:00:13 +10:00
syscall_netbsd.go syscalls: annotate Sendfile() for race detector 2012-10-29 23:15:06 +04:00
syscall_openbsd_386.go
syscall_openbsd_amd64.go
syscall_openbsd.go syscalls: annotate Sendfile() for race detector 2012-10-29 23:15:06 +04:00
syscall_plan9_386.go src: Add support for 64-bit version of Plan 9 2012-08-31 13:21:13 -04:00
syscall_plan9_amd64.go src: Add support for 64-bit version of Plan 9 2012-08-31 13:21:13 -04:00
syscall_plan9.go gofmt: apply gofmt -w src misc 2012-10-30 13:38:01 -07:00
syscall_unix.go syscalls: annotate Sendfile() for race detector 2012-10-29 23:15:06 +04:00
syscall_windows_386.go
syscall_windows_amd64.go
syscall_windows_test.go syscall: extract an ExampleLoadLibrary from comment 2012-08-29 21:44:46 +08:00
syscall_windows.go os: Improve the accuracy of os.Chtimes 2012-12-13 13:02:39 -08:00
syscall.go syscall: return EINVAL when string arguments have NUL characters 2012-08-05 17:24:32 -04:00
types_darwin.go syscall: add ipv4 ancillary data for darwin 2012-09-29 12:43:05 +09:00
types_freebsd.go syscall: fix // +build comments in types_*.go 2012-02-02 19:42:02 -05:00
types_linux.go os: Improve the accuracy of os.Chtimes 2012-12-13 13:02:39 -08:00
types_netbsd.go syscall: implement nametomib() on netbsd 2012-05-23 01:33:48 +10:00
types_openbsd.go syscall: fix // +build comments in types_*.go 2012-02-02 19:42:02 -05:00
types_plan9.c syscall: ignore godefs input when building on Plan 9 2012-01-09 15:09:40 -08:00
zerrors_darwin_386.go syscall: add Termios support on darwin 2012-05-03 17:33:19 -04:00
zerrors_darwin_amd64.go syscall: add Termios support on darwin 2012-05-03 17:33:19 -04:00
zerrors_freebsd_386.go runtime, syscall: fix freebsd-386 build 2012-02-14 10:04:59 +11:00
zerrors_freebsd_amd64.go runtime, syscall: fix freebsd build 2012-02-14 09:29:51 +11:00
zerrors_freebsd_arm.go syscall: FreeBSD/ARM support 2012-10-12 16:26:42 +08:00
zerrors_linux_386.go os/signal: selective signal handling 2012-02-13 13:52:37 -05:00
zerrors_linux_amd64.go os/signal: selective signal handling 2012-02-13 13:52:37 -05:00
zerrors_linux_arm.go syscall: fix mkall.sh, mksyscall_linux.pl, and regen for Linux/ARM 2012-03-06 03:12:11 +08:00
zerrors_netbsd_386.go syscall: regenerate/update netbsd z-files 2012-09-07 02:13:14 +10:00
zerrors_netbsd_amd64.go syscall: regenerate/update netbsd z-files 2012-09-07 02:13:14 +10:00
zerrors_openbsd_386.go syscall: regenerate z-files for openbsd/386 2012-11-14 19:06:12 +11:00
zerrors_openbsd_amd64.go syscall: regenerate z-files for openbsd/amd64 2012-11-14 03:19:34 +11:00
zerrors_plan9_386.go syscall: remove the Signal type on Plan 9 2012-05-04 03:44:41 -07:00
zerrors_plan9_amd64.go src: Add support for 64-bit version of Plan 9 2012-08-31 13:21:13 -04:00
zerrors_windows_386.go
zerrors_windows_amd64.go
zerrors_windows.go
zsyscall_darwin_386.go race: syscall changes 2012-10-09 20:51:58 +04:00
zsyscall_darwin_amd64.go race: syscall changes 2012-10-09 20:51:58 +04:00
zsyscall_freebsd_386.go race: syscall changes 2012-10-09 20:51:58 +04:00
zsyscall_freebsd_amd64.go race: syscall changes 2012-10-09 20:51:58 +04:00
zsyscall_freebsd_arm.go syscall: FreeBSD/ARM support 2012-10-12 16:26:42 +08:00
zsyscall_linux_386.go os: Improve the accuracy of os.Chtimes 2012-12-13 13:02:39 -08:00
zsyscall_linux_amd64.go os: Improve the accuracy of os.Chtimes 2012-12-13 13:02:39 -08:00
zsyscall_linux_arm.go os: Improve the accuracy of os.Chtimes 2012-12-13 13:02:39 -08:00
zsyscall_netbsd_386.go race: syscall changes 2012-10-09 20:51:58 +04:00
zsyscall_netbsd_amd64.go race: syscall changes 2012-10-09 20:51:58 +04:00
zsyscall_openbsd_386.go race: syscall changes 2012-10-09 20:51:58 +04:00
zsyscall_openbsd_amd64.go race: syscall changes 2012-10-09 20:51:58 +04:00
zsyscall_plan9_386.go syscall: return EINVAL when string arguments have NUL characters 2012-08-05 17:24:32 -04:00
zsyscall_plan9_amd64.go pkg/syscall: Plan 9, 64-bit: Update error checks from sys calls. 2012-09-28 09:56:44 +10:00
zsyscall_windows_386.go net: implement IPv6 support for windows 2012-11-07 16:58:20 +11:00
zsyscall_windows_amd64.go net: implement IPv6 support for windows 2012-11-07 16:58:20 +11:00
zsysctl_openbsd.go syscall: regenerate z-files for openbsd/amd64 2012-11-14 03:19:34 +11:00
zsysnum_darwin_386.go
zsysnum_darwin_amd64.go
zsysnum_freebsd_386.go gofmt: apply gofmt -w src misc 2012-10-30 13:38:01 -07:00
zsysnum_freebsd_amd64.go gofmt: apply gofmt -w src misc 2012-10-30 13:38:01 -07:00
zsysnum_freebsd_arm.go gofmt: apply gofmt -w src misc 2012-10-30 13:38:01 -07:00
zsysnum_linux_386.go os/signal: selective signal handling 2012-02-13 13:52:37 -05:00
zsysnum_linux_amd64.go os/signal: selective signal handling 2012-02-13 13:52:37 -05:00
zsysnum_linux_arm.go gofmt: apply gofmt -w src misc 2012-10-30 13:38:01 -07:00
zsysnum_netbsd_386.go gofmt: apply gofmt -w src misc 2012-10-30 13:38:01 -07:00
zsysnum_netbsd_amd64.go gofmt: apply gofmt -w src misc 2012-10-30 13:38:01 -07:00
zsysnum_openbsd_386.go syscall: regenerate z-files for openbsd/386 2012-11-14 19:06:12 +11:00
zsysnum_openbsd_amd64.go syscall: regenerate z-files for openbsd/amd64 2012-11-14 03:19:34 +11:00
zsysnum_plan9_386.go
zsysnum_plan9_amd64.go src: Add support for 64-bit version of Plan 9 2012-08-31 13:21:13 -04:00
zsysnum_windows_386.go
zsysnum_windows_amd64.go
ztypes_darwin_386.go syscall: add ipv4 ancillary data for darwin 2012-09-29 12:43:05 +09:00
ztypes_darwin_amd64.go syscall: add ipv4 ancillary data for darwin 2012-09-29 12:43:05 +09:00
ztypes_freebsd_386.go
ztypes_freebsd_amd64.go
ztypes_freebsd_arm.go syscall: FreeBSD/ARM support 2012-10-12 16:26:42 +08:00
ztypes_linux_386.go os: Improve the accuracy of os.Chtimes 2012-12-13 13:02:39 -08:00
ztypes_linux_amd64.go os: Improve the accuracy of os.Chtimes 2012-12-13 13:02:39 -08:00
ztypes_linux_arm.go os: Improve the accuracy of os.Chtimes 2012-12-13 13:02:39 -08:00
ztypes_netbsd_386.go syscall: implement nametomib() on netbsd 2012-05-23 01:33:48 +10:00
ztypes_netbsd_amd64.go syscall: implement nametomib() on netbsd 2012-05-23 01:33:48 +10:00
ztypes_openbsd_386.go syscall: regenerate z-files for openbsd/386 2012-11-14 19:06:12 +11:00
ztypes_openbsd_amd64.go syscall: regenerate z-files for openbsd/amd64 2012-11-14 03:19:34 +11:00
ztypes_plan9_386.go
ztypes_plan9_amd64.go src: Add support for 64-bit version of Plan 9 2012-08-31 13:21:13 -04:00
ztypes_windows_386.go
ztypes_windows_amd64.go
ztypes_windows.go net: implement IPv6 support for windows 2012-11-07 16:58:20 +11:00