Skip to content

Commit cdad408

Browse files
committed
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 <[email protected]> Reviewed-by: Clément Chigot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 21f7f01 commit cdad408

File tree

7 files changed

+89
-67
lines changed

7 files changed

+89
-67
lines changed

src/internal/syscall/unix/asm_solaris.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
// System calls for Solaris are implemented in runtime/syscall_solaris.go
88

9-
TEXT ·sysvicall6(SB),NOSPLIT,$0-88
9+
TEXT ·syscall6(SB),NOSPLIT,$0-88
1010
JMP syscall·sysvicall6(SB)

src/internal/syscall/unix/at_aix.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2018 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package unix
6+
7+
//go:cgo_import_dynamic libc_fstatat fstatat "libc.a/shr_64.o"
8+
//go:cgo_import_dynamic libc_openat openat "libc.a/shr_64.o"
9+
//go:cgo_import_dynamic libc_unlinkat unlinkat "libc.a/shr_64.o"
10+
11+
const (
12+
AT_REMOVEDIR = 0x1
13+
AT_SYMLINK_NOFOLLOW = 0x1
14+
)

src/internal/syscall/unix/at_libc.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2018 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build aix solaris
6+
7+
package unix
8+
9+
import (
10+
"syscall"
11+
"unsafe"
12+
)
13+
14+
//go:linkname procFstatat libc_fstatat
15+
//go:linkname procOpenat libc_openat
16+
//go:linkname procUnlinkat libc_unlinkat
17+
18+
var (
19+
procFstatat,
20+
procOpenat,
21+
procUnlinkat uintptr
22+
)
23+
24+
func Unlinkat(dirfd int, path string, flags int) error {
25+
p, err := syscall.BytePtrFromString(path)
26+
if err != nil {
27+
return err
28+
}
29+
30+
_, _, errno := syscall6(uintptr(unsafe.Pointer(&procUnlinkat)), 3, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), 0, 0, 0)
31+
if errno != 0 {
32+
return errno
33+
}
34+
35+
return nil
36+
}
37+
38+
func Openat(dirfd int, path string, flags int, perm uint32) (int, error) {
39+
p, err := syscall.BytePtrFromString(path)
40+
if err != nil {
41+
return 0, err
42+
}
43+
44+
fd, _, errno := syscall6(uintptr(unsafe.Pointer(&procOpenat)), 4, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), uintptr(perm), 0, 0)
45+
if errno != 0 {
46+
return 0, errno
47+
}
48+
49+
return int(fd), nil
50+
}
51+
52+
func Fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error {
53+
p, err := syscall.BytePtrFromString(path)
54+
if err != nil {
55+
return err
56+
}
57+
58+
_, _, errno := syscall6(uintptr(unsafe.Pointer(&procFstatat)), 4, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0)
59+
if errno != 0 {
60+
return errno
61+
}
62+
63+
return nil
64+
}

src/internal/syscall/unix/at_solaris.go

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,16 @@
44

55
package unix
66

7-
import (
8-
"syscall"
9-
"unsafe"
10-
)
7+
import "syscall"
118

12-
// Implemented in runtime/syscall_solaris.go.
13-
func sysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
9+
// Implemented as sysvicall6 in runtime/syscall_solaris.go.
10+
func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
1411

1512
//go:cgo_import_dynamic libc_fstatat fstatat "libc.so"
1613
//go:cgo_import_dynamic libc_openat openat "libc.so"
1714
//go:cgo_import_dynamic libc_unlinkat unlinkat "libc.so"
1815

19-
//go:linkname procFstatat libc_fstatat
20-
//go:linkname procOpenat libc_openat
21-
//go:linkname procUnlinkat libc_unlinkat
22-
23-
var (
24-
procFstatat,
25-
procOpenat,
26-
procUnlinkat uintptr
16+
const (
17+
AT_REMOVEDIR = 0x1
18+
AT_SYMLINK_NOFOLLOW = 0x1000
2719
)
28-
29-
const AT_REMOVEDIR = 0x1
30-
const AT_SYMLINK_NOFOLLOW = 0x1000
31-
32-
func Unlinkat(dirfd int, path string, flags int) error {
33-
var p *byte
34-
p, err := syscall.BytePtrFromString(path)
35-
if err != nil {
36-
return err
37-
}
38-
39-
_, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procUnlinkat)), 3, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), 0, 0, 0)
40-
if errno != 0 {
41-
return errno
42-
}
43-
44-
return nil
45-
}
46-
47-
func Openat(dirfd int, path string, flags int, perm uint32) (int, error) {
48-
var p *byte
49-
p, err := syscall.BytePtrFromString(path)
50-
if err != nil {
51-
return 0, err
52-
}
53-
54-
fd, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procOpenat)), 4, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), uintptr(perm), 0, 0)
55-
if errno != 0 {
56-
return 0, errno
57-
}
58-
59-
return int(fd), nil
60-
}
61-
62-
func Fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error {
63-
var p *byte
64-
p, err := syscall.BytePtrFromString(path)
65-
if err != nil {
66-
return err
67-
}
68-
69-
_, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procFstatat)), 4, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0)
70-
if errno != 0 {
71-
return errno
72-
}
73-
74-
return nil
75-
}

src/os/removeall_at.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
5+
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
66

77
package os
88

src/os/removeall_noat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build !linux,!darwin,!freebsd,!openbsd,!netbsd,!dragonfly,!solaris
5+
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris
66

77
package os
88

src/os/removeall_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func TestRemoveAllLarge(t *testing.T) {
162162

163163
func TestRemoveAllLongPath(t *testing.T) {
164164
switch runtime.GOOS {
165-
case "linux", "darwin", "freebsd", "openbsd", "netbsd", "dragonfly", "solaris":
165+
case "aix", "darwin", "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris":
166166
break
167167
default:
168168
t.Skip("skipping for not implemented platforms")
@@ -212,7 +212,7 @@ func TestRemoveAllLongPath(t *testing.T) {
212212

213213
func TestRemoveAllDot(t *testing.T) {
214214
switch runtime.GOOS {
215-
case "linux", "darwin", "freebsd", "openbsd", "netbsd", "dragonfly", "solaris":
215+
case "aix", "darwin", "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris":
216216
break
217217
default:
218218
t.Skip("skipping for not implemented platforms")

0 commit comments

Comments
 (0)