unix: add Statvfs and Fstatvfs on NetBSD

NetBSD replaced statfs with statvfs in NetBSD 3.0. statfs is derived
from BSD4.4, while NetBSD (and Solaris) implement statvfs from POSIX
instead.

Generated and tested on NetBSD 8.0 (amd64). Also tested on NetBSD 7.0 (amd64).

Change-Id: I53738b77815d04c7774a6455b4a31cd4e9571f7b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/209637
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
This commit is contained in:
Tobias Klauser
2019-12-04 07:23:24 +00:00
committed by Tobias Klauser
parent 85b82a3add
commit ce4227a45e
12 changed files with 288 additions and 0 deletions
+33
View File
@@ -6,6 +6,7 @@ package unix_test
import (
"bytes"
"os"
"testing"
"golang.org/x/sys/unix"
@@ -49,3 +50,35 @@ func TestIoctlPtmget(t *testing.T) {
t.Logf("sfd = %v, ptsname = %v", ptm.Sfd, string(ptm.Sn[:bytes.IndexByte(ptm.Sn[:], 0)]))
}
func TestStatvfs(t *testing.T) {
defer chtmpdir(t)()
touch(t, "file1")
var statvfs1, statvfs2 unix.Statvfs_t
err := unix.Statvfs("file1", &statvfs1)
if err != nil {
t.Fatalf("Statvfs: %v", err)
}
f, err := os.Open("file1")
if err != nil {
t.Fatal(err)
}
defer f.Close()
err = unix.Fstatvfs(int(f.Fd()), &statvfs2)
if err != nil {
t.Fatalf("Fstatvfs: %v", err)
}
if statvfs2.Fsid != statvfs1.Fsid {
t.Errorf("Fstatvfs: got fsid %v, expected %v", statvfs2.Fsid, statvfs1.Fsid)
}
if statvfs2.Owner != statvfs1.Owner {
t.Errorf("Fstatvfs: got owner %v, expected %v", statvfs2.Owner, statvfs1.Owner)
}
if statvfs2.Fstypename != statvfs1.Fstypename {
t.Errorf("Fstatvfs: got fstypename %s, expected %s", statvfs2.Fstypename, statvfs1.Fstypename)
}
}