Skip to content

Commit 137f2ed

Browse files
0-wiz-0gopherbot
authored andcommitted
sys: add support for NetBSD getvfsstat
NetBSD replaced the getfsstat interface with getvfsstat in NetBSD 3.0. Add a test for it. With help from Benny Siegert and Ian Lance Taylor. Change-Id: I115ae48c287cc32181006e9e8f7c15851e7e36c0 Reviewed-on: https://go-review.googlesource.com/c/sys/+/550476 Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Benny Siegert <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Benny Siegert <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent b06ce05 commit 137f2ed

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

unix/getvfsstat_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 netbsd
6+
7+
package unix_test
8+
9+
import (
10+
"os/exec"
11+
"testing"
12+
13+
"golang.org/x/sys/unix"
14+
)
15+
16+
func TestGetvfsstat(t *testing.T) {
17+
n, err := unix.Getvfsstat(nil, unix.MNT_NOWAIT)
18+
if err != nil {
19+
t.Fatal(err)
20+
}
21+
22+
data := make([]unix.Statvfs_t, n)
23+
n2, err := unix.Getvfsstat(data, unix.MNT_NOWAIT)
24+
if err != nil {
25+
t.Fatal(err)
26+
}
27+
if n != n2 {
28+
t.Errorf("Getvfsstat(nil) = %d, but subsequent Getvfsstat(slice) = %d", n, n2)
29+
}
30+
for i, stat := range data {
31+
if stat == (unix.Statvfs_t{}) {
32+
t.Errorf("index %v is an empty Statvfs_t struct", i)
33+
}
34+
t.Logf("%s on %s", unix.ByteSliceToString(stat.Mntfromname[:]), unix.ByteSliceToString(stat.Mntonname[:]))
35+
}
36+
if t.Failed() {
37+
for i, stat := range data[:n2] {
38+
t.Logf("data[%v] = %+v", i, stat)
39+
}
40+
mount, err := exec.Command("mount").CombinedOutput()
41+
if err != nil {
42+
t.Logf("mount: %v\n%s", err, mount)
43+
} else {
44+
t.Logf("mount: %s", mount)
45+
}
46+
}
47+
}

unix/syscall_netbsd.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,23 @@ func Statvfs(path string, buf *Statvfs_t) (err error) {
248248
return Statvfs1(path, buf, ST_WAIT)
249249
}
250250

251+
func Getvfsstat(buf []Statvfs_t, flags int) (n int, err error) {
252+
var (
253+
_p0 unsafe.Pointer
254+
bufsize uintptr
255+
)
256+
if len(buf) > 0 {
257+
_p0 = unsafe.Pointer(&buf[0])
258+
bufsize = unsafe.Sizeof(Statvfs_t{}) * uintptr(len(buf))
259+
}
260+
r0, _, e1 := Syscall(SYS_GETVFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
261+
n = int(r0)
262+
if e1 != 0 {
263+
err = e1
264+
}
265+
return
266+
}
267+
251268
/*
252269
* Exposed directly
253270
*/

0 commit comments

Comments
 (0)