]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: fix fsync for read-only files on aix
authorClément Chigot <chigot.c@gmail.com>
Mon, 14 Sep 2020 11:06:40 +0000 (13:06 +0200)
committerIan Lance Taylor <iant@golang.org>
Mon, 14 Sep 2020 17:07:47 +0000 (17:07 +0000)
AIX fsync syscall doesn't work on read-only files. Using fsync_range
instead allows syscall.Fsync to work on any files.

Fixes #41372

Change-Id: I66d33e847875496af53da60828c1bddf6c2b76b7
Reviewed-on: https://go-review.googlesource.com/c/go/+/254657
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/syscall/syscall_aix.go
src/syscall/zsyscall_aix_ppc64.go

index 8bb5fa9eade46d12d50176bb67f3aff2c39e7acc..8837dd5a7f33aba5e1abd61bc83fe3abfbad181d 100644 (file)
@@ -214,6 +214,11 @@ func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int,
        return
 }
 
+//sys  fsyncRange(fd int, how int, start int64, length int64) (err error) = fsync_range
+func Fsync(fd int) error {
+       return fsyncRange(fd, O_SYNC, 0, 0)
+}
+
 /*
  * Socket
  */
@@ -600,7 +605,6 @@ func PtraceDetach(pid int) (err error) { return ptrace64(PT_DETACH, int64(pid),
 //sys  Fstat(fd int, stat *Stat_t) (err error)
 //sys  Fstatfs(fd int, buf *Statfs_t) (err error)
 //sys  Ftruncate(fd int, length int64) (err error)
-//sys  Fsync(fd int) (err error)
 //sysnb        Getgid() (gid int)
 //sysnb        Getpid() (pid int)
 //sys  Geteuid() (euid int)
index 384fead4d263a9473f37efa0f80218c14022fb36..20625c1a3e01a33792b594d081ed92ff0dd8a702 100644 (file)
@@ -19,6 +19,7 @@ import "unsafe"
 //go:cgo_import_dynamic libc_setgroups setgroups "libc.a/shr_64.o"
 //go:cgo_import_dynamic libc_getdirent getdirent "libc.a/shr_64.o"
 //go:cgo_import_dynamic libc_wait4 wait4 "libc.a/shr_64.o"
+//go:cgo_import_dynamic libc_fsync_range fsync_range "libc.a/shr_64.o"
 //go:cgo_import_dynamic libc_bind bind "libc.a/shr_64.o"
 //go:cgo_import_dynamic libc_connect connect "libc.a/shr_64.o"
 //go:cgo_import_dynamic libc_Getkerninfo getkerninfo "libc.a/shr_64.o"
@@ -54,7 +55,6 @@ import "unsafe"
 //go:cgo_import_dynamic libc_Fstat fstat "libc.a/shr_64.o"
 //go:cgo_import_dynamic libc_Fstatfs fstatfs "libc.a/shr_64.o"
 //go:cgo_import_dynamic libc_Ftruncate ftruncate "libc.a/shr_64.o"
-//go:cgo_import_dynamic libc_Fsync fsync "libc.a/shr_64.o"
 //go:cgo_import_dynamic libc_Getgid getgid "libc.a/shr_64.o"
 //go:cgo_import_dynamic libc_Getpid getpid "libc.a/shr_64.o"
 //go:cgo_import_dynamic libc_Geteuid geteuid "libc.a/shr_64.o"
@@ -111,6 +111,7 @@ import "unsafe"
 //go:linkname libc_setgroups libc_setgroups
 //go:linkname libc_getdirent libc_getdirent
 //go:linkname libc_wait4 libc_wait4
+//go:linkname libc_fsync_range libc_fsync_range
 //go:linkname libc_bind libc_bind
 //go:linkname libc_connect libc_connect
 //go:linkname libc_Getkerninfo libc_Getkerninfo
@@ -146,7 +147,6 @@ import "unsafe"
 //go:linkname libc_Fstat libc_Fstat
 //go:linkname libc_Fstatfs libc_Fstatfs
 //go:linkname libc_Ftruncate libc_Ftruncate
-//go:linkname libc_Fsync libc_Fsync
 //go:linkname libc_Getgid libc_Getgid
 //go:linkname libc_Getpid libc_Getpid
 //go:linkname libc_Geteuid libc_Geteuid
@@ -206,6 +206,7 @@ var (
        libc_setgroups,
        libc_getdirent,
        libc_wait4,
+       libc_fsync_range,
        libc_bind,
        libc_connect,
        libc_Getkerninfo,
@@ -241,7 +242,6 @@ var (
        libc_Fstat,
        libc_Fstatfs,
        libc_Ftruncate,
-       libc_Fsync,
        libc_Getgid,
        libc_Getpid,
        libc_Geteuid,
@@ -442,6 +442,16 @@ func wait4(pid _Pid_t, status *_C_int, options int, rusage *Rusage) (wpid _Pid_t
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
+func fsyncRange(fd int, how int, start int64, length int64) (err error) {
+       _, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_fsync_range)), 4, uintptr(fd), uintptr(how), uintptr(start), uintptr(length), 0, 0)
+       if e1 != 0 {
+               err = errnoErr(e1)
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
 func bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) {
        _, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_bind)), 3, uintptr(s), uintptr(addr), uintptr(addrlen), 0, 0, 0)
        if e1 != 0 {
@@ -854,16 +864,6 @@ func Ftruncate(fd int, length int64) (err error) {
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func Fsync(fd int) (err error) {
-       _, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_Fsync)), 1, uintptr(fd), 0, 0, 0, 0, 0)
-       if e1 != 0 {
-               err = errnoErr(e1)
-       }
-       return
-}
-
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
 func Getgid() (gid int) {
        r0, _, _ := rawSyscall6(uintptr(unsafe.Pointer(&libc_Getgid)), 0, 0, 0, 0, 0, 0, 0)
        gid = int(r0)