]> Cypherpunks repositories - gostls13.git/commitdiff
os: add support for long path names on solaris RemoveAll
authorTobias Klauser <tklauser@distanz.ch>
Tue, 30 Oct 2018 00:40:24 +0000 (00:40 +0000)
committerTobias Klauser <tobias.klauser@gmail.com>
Wed, 31 Oct 2018 16:52:45 +0000 (16:52 +0000)
Follow CL 146020 and enable RemoveAll based on Unlinkat and Openat on
solaris.

Updates #27029

Change-Id: I0b0e92f4422fa960a13dcd3e9adb57cd23f09ed4
Reviewed-on: https://go-review.googlesource.com/c/145839
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/internal/syscall/unix/asm_solaris.s [new file with mode: 0644]
src/internal/syscall/unix/at_solaris.go [new file with mode: 0644]
src/os/removeall_at.go
src/os/removeall_noat.go
src/os/removeall_test.go

diff --git a/src/internal/syscall/unix/asm_solaris.s b/src/internal/syscall/unix/asm_solaris.s
new file mode 100644 (file)
index 0000000..a7ad26d
--- /dev/null
@@ -0,0 +1,10 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "textflag.h"
+
+// System calls for Solaris are implemented in runtime/syscall_solaris.go
+
+TEXT ·sysvicall6(SB),NOSPLIT,$0-88
+       JMP     syscall·sysvicall6(SB)
diff --git a/src/internal/syscall/unix/at_solaris.go b/src/internal/syscall/unix/at_solaris.go
new file mode 100644 (file)
index 0000000..d63ee99
--- /dev/null
@@ -0,0 +1,75 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package unix
+
+import (
+       "syscall"
+       "unsafe"
+)
+
+// Implemented in runtime/syscall_solaris.go.
+func sysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
+
+//go:cgo_import_dynamic libc_fstatat fstatat "libc.so"
+//go:cgo_import_dynamic libc_openat openat "libc.so"
+//go:cgo_import_dynamic libc_unlinkat unlinkat "libc.so"
+
+//go:linkname procFstatat libc_fstatat
+//go:linkname procOpenat libc_openat
+//go:linkname procUnlinkat libc_unlinkat
+
+var (
+       procFstatat,
+       procOpenat,
+       procUnlinkat uintptr
+)
+
+const AT_REMOVEDIR = 0x1
+const AT_SYMLINK_NOFOLLOW = 0x1000
+
+func Unlinkat(dirfd int, path string, flags int) error {
+       var p *byte
+       p, err := syscall.BytePtrFromString(path)
+       if err != nil {
+               return err
+       }
+
+       _, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procUnlinkat)), 3, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), 0, 0, 0)
+       if errno != 0 {
+               return errno
+       }
+
+       return nil
+}
+
+func Openat(dirfd int, path string, flags int, perm uint32) (int, error) {
+       var p *byte
+       p, err := syscall.BytePtrFromString(path)
+       if err != nil {
+               return 0, err
+       }
+
+       fd, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procOpenat)), 4, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), uintptr(perm), 0, 0)
+       if errno != 0 {
+               return 0, errno
+       }
+
+       return int(fd), nil
+}
+
+func Fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error {
+       var p *byte
+       p, err := syscall.BytePtrFromString(path)
+       if err != nil {
+               return err
+       }
+
+       _, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procFstatat)), 4, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0)
+       if errno != 0 {
+               return errno
+       }
+
+       return nil
+}
index 062b81e5778a931e443f7e8c87f88449aa51e70a..b7ed2aa6d411d1b06d6674911b082a75b946349a 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build linux darwin openbsd netbsd dragonfly
+// +build linux darwin openbsd netbsd dragonfly solaris
 
 package os
 
index 1b85a6afa528f97e28c945fb84b4074464881bb3..02af047d6e03a77f1d527bd713c8e74fad914582 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build !linux,!darwin,!openbsd,!netbsd,!dragonfly
+// +build !linux,!darwin,!openbsd,!netbsd,!dragonfly,!solaris
 
 package os
 
index a1006230da8c53a1db2c5024f6a630446fc6363f..4b6f3e92565e08c446c7ba492ebb6553f83006e3 100644 (file)
@@ -153,7 +153,7 @@ func TestRemoveAllLarge(t *testing.T) {
 
 func TestRemoveAllLongPath(t *testing.T) {
        switch runtime.GOOS {
-       case "linux", "darwin", "openbsd", "netbsd", "dragonfly":
+       case "linux", "darwin", "openbsd", "netbsd", "dragonfly", "solaris":
                break
        default:
                t.Skip("skipping for not implemented platforms")
@@ -201,7 +201,7 @@ func TestRemoveAllLongPath(t *testing.T) {
 
 func TestRemoveAllDot(t *testing.T) {
        switch runtime.GOOS {
-       case "linux", "darwin", "openbsd", "netbsd", "dragonfly":
+       case "linux", "darwin", "openbsd", "netbsd", "dragonfly", "solaris":
                break
        default:
                t.Skip("skipping for not implemented platforms")