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 <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Benny Siegert <bsiegert@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Benny Siegert <bsiegert@gmail.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
diff --git a/unix/getvfsstat_test.go b/unix/getvfsstat_test.go new file mode 100644 index 0000000..30c963a --- /dev/null +++ b/unix/getvfsstat_test.go
@@ -0,0 +1,47 @@ +// Copyright 2023 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. + +//go:build netbsd + +package unix_test + +import ( + "os/exec" + "testing" + + "golang.org/x/sys/unix" +) + +func TestGetvfsstat(t *testing.T) { + n, err := unix.Getvfsstat(nil, unix.MNT_NOWAIT) + if err != nil { + t.Fatal(err) + } + + data := make([]unix.Statvfs_t, n) + n2, err := unix.Getvfsstat(data, unix.MNT_NOWAIT) + if err != nil { + t.Fatal(err) + } + if n != n2 { + t.Errorf("Getvfsstat(nil) = %d, but subsequent Getvfsstat(slice) = %d", n, n2) + } + for i, stat := range data { + if stat == (unix.Statvfs_t{}) { + t.Errorf("index %v is an empty Statvfs_t struct", i) + } + t.Logf("%s on %s", unix.ByteSliceToString(stat.Mntfromname[:]), unix.ByteSliceToString(stat.Mntonname[:])) + } + if t.Failed() { + for i, stat := range data[:n2] { + t.Logf("data[%v] = %+v", i, stat) + } + mount, err := exec.Command("mount").CombinedOutput() + if err != nil { + t.Logf("mount: %v\n%s", err, mount) + } else { + t.Logf("mount: %s", mount) + } + } +}
diff --git a/unix/syscall_netbsd.go b/unix/syscall_netbsd.go index 8816209..34a4676 100644 --- a/unix/syscall_netbsd.go +++ b/unix/syscall_netbsd.go
@@ -248,6 +248,23 @@ return Statvfs1(path, buf, ST_WAIT) } +func Getvfsstat(buf []Statvfs_t, flags int) (n int, err error) { + var ( + _p0 unsafe.Pointer + bufsize uintptr + ) + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + bufsize = unsafe.Sizeof(Statvfs_t{}) * uintptr(len(buf)) + } + r0, _, e1 := Syscall(SYS_GETVFSSTAT, uintptr(_p0), bufsize, uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = e1 + } + return +} + /* * Exposed directly */