Skip to content

Commit ed1cf6a

Browse files
tklausergopherbot
authored andcommitted
cmd/link/internal/ld, internal/syscall/unix: use posix_fallocate on freebsd
The posix_fallocate system call is available since FreeBSD 9.0, see https://man.freebsd.org/cgi/man.cgi?query=posix_fallocate Change-Id: Ie65e0a44341909707617d3b0d9a4f1710c45b935 Reviewed-on: https://go-review.googlesource.com/c/go/+/478035 TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Tobias Klauser <[email protected]> Run-TryBot: Tobias Klauser <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent bf9d9b7 commit ed1cf6a

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

src/cmd/dist/buildtool.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ var bootstrapDirs = []string{
6868
"internal/goroot",
6969
"internal/goversion",
7070
"internal/pkgbits",
71+
"internal/platform",
7172
"internal/profile",
7273
"internal/race",
7374
"internal/saferio",
74-
"internal/platform",
75+
"internal/syscall/unix",
7576
"internal/types/errors",
7677
"internal/unsafeheader",
7778
"internal/xcoff",

src/cmd/link/internal/ld/fallocate_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +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-
//go:build darwin || linux
6-
// +build darwin linux
5+
//go:build darwin || (freebsd && go1.21) || linux
76

87
package ld
98

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2023 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+
//go:build freebsd && go1.21
6+
7+
package ld
8+
9+
import "internal/syscall/unix"
10+
11+
func (out *OutBuf) fallocate(size uint64) error {
12+
return unix.PosixFallocate(int(out.f.Fd()), 0, int64(size))
13+
}

src/cmd/link/internal/ld/outbuf_nofallocate.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-
//go:build !darwin && !linux
5+
//go:build !darwin && !(freebsd && go1.21) && !linux
66

77
package ld
88

src/cmd/link/internal/ld/outbuf_notdarwin.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build !darwin
6-
// +build !darwin
76

87
package ld
98

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2023 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+
import "syscall"
8+
9+
// FreeBSD posix_fallocate system call number.
10+
const posixFallocateTrap uintptr = 530
11+
12+
func PosixFallocate(fd int, off int64, size int64) error {
13+
_, _, errno := syscall.Syscall(posixFallocateTrap, uintptr(fd), uintptr(off), uintptr(size))
14+
if errno != 0 {
15+
return errno
16+
}
17+
return nil
18+
}

0 commit comments

Comments
 (0)