Commit cdad4080 authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser

os: add support for long path names on aix RemoveAll

Follow CL 146020 and enable RemoveAll based on Unlinkat and Openat on
aix.

Updates #27029

Change-Id: I78b34ed671166ee6fa651d5f2025b88548ee6c68
Reviewed-on: https://go-review.googlesource.com/c/146937
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: 's avatarClément Chigot <clement.chigot@atos.net>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 21f7f012
......@@ -6,5 +6,5 @@
// System calls for Solaris are implemented in runtime/syscall_solaris.go
TEXT ·sysvicall6(SB),NOSPLIT,$0-88
TEXT ·syscall6(SB),NOSPLIT,$0-88
JMP syscall·sysvicall6(SB)
// 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
//go:cgo_import_dynamic libc_fstatat fstatat "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_openat openat "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_unlinkat unlinkat "libc.a/shr_64.o"
const (
AT_REMOVEDIR = 0x1
AT_SYMLINK_NOFOLLOW = 0x1
)
// 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.
// +build aix solaris
package unix
import (
"syscall"
"unsafe"
)
//go:linkname procFstatat libc_fstatat
//go:linkname procOpenat libc_openat
//go:linkname procUnlinkat libc_unlinkat
var (
procFstatat,
procOpenat,
procUnlinkat uintptr
)
func Unlinkat(dirfd int, path string, flags int) error {
p, err := syscall.BytePtrFromString(path)
if err != nil {
return err
}
_, _, errno := syscall6(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) {
p, err := syscall.BytePtrFromString(path)
if err != nil {
return 0, err
}
fd, _, errno := syscall6(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 {
p, err := syscall.BytePtrFromString(path)
if err != nil {
return err
}
_, _, errno := syscall6(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
}
......@@ -4,72 +4,16 @@
package unix
import (
"syscall"
"unsafe"
)
import "syscall"
// Implemented in runtime/syscall_solaris.go.
func sysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
// Implemented as sysvicall6 in runtime/syscall_solaris.go.
func syscall6(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
AT_SYMLINK_NOFOLLOW = 0x1000
)
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
}
......@@ -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 darwin dragonfly freebsd linux netbsd openbsd solaris
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
package os
......
......@@ -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,!freebsd,!openbsd,!netbsd,!dragonfly,!solaris
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris
package os
......
......@@ -162,7 +162,7 @@ func TestRemoveAllLarge(t *testing.T) {
func TestRemoveAllLongPath(t *testing.T) {
switch runtime.GOOS {
case "linux", "darwin", "freebsd", "openbsd", "netbsd", "dragonfly", "solaris":
case "aix", "darwin", "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris":
break
default:
t.Skip("skipping for not implemented platforms")
......@@ -212,7 +212,7 @@ func TestRemoveAllLongPath(t *testing.T) {
func TestRemoveAllDot(t *testing.T) {
switch runtime.GOOS {
case "linux", "darwin", "freebsd", "openbsd", "netbsd", "dragonfly", "solaris":
case "aix", "darwin", "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris":
break
default:
t.Skip("skipping for not implemented platforms")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment