From 5e83d40904f35fab8a0e302833ee1fb7ad104cfd Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Wed, 9 Feb 2011 14:54:54 +1100 Subject: [PATCH] syscall: implement windows version of Fsync R=golang-dev, rsc CC=golang-dev https://golang.org/cl/4158043 --- src/pkg/syscall/syscall_windows.go | 11 ++++++++--- src/pkg/syscall/zsyscall_windows_386.go | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/pkg/syscall/syscall_windows.go b/src/pkg/syscall/syscall_windows.go index f0b71dd91d3..93e1115123d 100644 --- a/src/pkg/syscall/syscall_windows.go +++ b/src/pkg/syscall/syscall_windows.go @@ -158,6 +158,7 @@ func NewCallback(fn interface{}) uintptr //sys CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, errno int) [failretval==nil] = shell32.CommandLineToArgvW //sys LocalFree(hmem uint32) (handle uint32, errno int) [failretval!=0] //sys SetHandleInformation(handle int32, mask uint32, flags uint32) (ok bool, errno int) +//sys FlushFileBuffers(handle int32) (ok bool, errno int) // syscall interface implementation for other packages @@ -478,6 +479,13 @@ func Utimes(path string, tv []Timeval) (errno int) { return 0 } +func Fsync(fd int) (errno int) { + if ok, e := FlushFileBuffers(int32(fd)); !ok { + return e + } + return 0 +} + // net api calls //sys WSAStartup(verreq uint32, data *WSAData) (sockerrno int) = wsock32.WSAStartup @@ -732,9 +740,6 @@ func Chown(path string, uid int, gid int) (errno int) { return EWINDOWS } func Lchown(path string, uid int, gid int) (errno int) { return EWINDOWS } func Fchown(fd int, uid int, gid int) (errno int) { return EWINDOWS } -// TODO(brainman): use FlushFileBuffers Windows api to implement Fsync. -func Fsync(fd int) (errno int) { return EWINDOWS } - func Getuid() (uid int) { return -1 } func Geteuid() (euid int) { return -1 } func Getgid() (gid int) { return -1 } diff --git a/src/pkg/syscall/zsyscall_windows_386.go b/src/pkg/syscall/zsyscall_windows_386.go index 96c6098ddb2..608a8ba39d2 100644 --- a/src/pkg/syscall/zsyscall_windows_386.go +++ b/src/pkg/syscall/zsyscall_windows_386.go @@ -67,6 +67,7 @@ var ( procCommandLineToArgvW = getSysProcAddr(modshell32, "CommandLineToArgvW") procLocalFree = getSysProcAddr(modkernel32, "LocalFree") procSetHandleInformation = getSysProcAddr(modkernel32, "SetHandleInformation") + procFlushFileBuffers = getSysProcAddr(modkernel32, "FlushFileBuffers") procWSAStartup = getSysProcAddr(modwsock32, "WSAStartup") procWSACleanup = getSysProcAddr(modwsock32, "WSACleanup") procsocket = getSysProcAddr(modwsock32, "socket") @@ -883,6 +884,21 @@ func SetHandleInformation(handle int32, mask uint32, flags uint32) (ok bool, err return } +func FlushFileBuffers(handle int32) (ok bool, errno int) { + r0, _, e1 := Syscall(procFlushFileBuffers, 1, uintptr(handle), 0, 0) + ok = bool(r0 != 0) + if !ok { + if e1 != 0 { + errno = int(e1) + } else { + errno = EINVAL + } + } else { + errno = 0 + } + return +} + func WSAStartup(verreq uint32, data *WSAData) (sockerrno int) { r0, _, _ := Syscall(procWSAStartup, 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0) sockerrno = int(r0)