Browse Source

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>
pull/49/head
Tobias Klauser Tobias Klauser 1 month ago
parent
commit
ce4227a45e
12 changed files with 288 additions and 0 deletions
  1. +5
    -0
      unix/mkpost.go
  2. +10
    -0
      unix/syscall_netbsd.go
  3. +33
    -0
      unix/syscall_netbsd_test.go
  4. +10
    -0
      unix/types_netbsd.go
  5. +25
    -0
      unix/zsyscall_netbsd_386.go
  6. +25
    -0
      unix/zsyscall_netbsd_amd64.go
  7. +25
    -0
      unix/zsyscall_netbsd_arm.go
  8. +25
    -0
      unix/zsyscall_netbsd_arm64.go
  9. +32
    -0
      unix/ztypes_netbsd_386.go
  10. +33
    -0
      unix/ztypes_netbsd_amd64.go
  11. +32
    -0
      unix/ztypes_netbsd_arm.go
  12. +33
    -0
      unix/ztypes_netbsd_arm64.go

+ 5
- 0
unix/mkpost.go View File

@@ -76,6 +76,11 @@ func main() {
convertUtsnameRegex := regexp.MustCompile(`((Sys|Node|Domain)name|Release|Version|Machine)(\s+)\[(\d+)\]u?int8`)
b = convertUtsnameRegex.ReplaceAll(b, []byte("$1$3[$4]byte"))

// Convert [n]int8 to [n]byte in Statvfs_t members to simplify
// conversion to string.
convertStatvfsRegex := regexp.MustCompile(`((Fstype|Mnton|Mntfrom)name)(\s+)\[(\d+)\]int8`)
b = convertStatvfsRegex.ReplaceAll(b, []byte("$1$3[$4]byte"))

// Convert [1024]int8 to [1024]byte in Ptmget members
convertPtmget := regexp.MustCompile(`([SC]n)(\s+)\[(\d+)\]u?int8`)
b = convertPtmget.ReplaceAll(b, []byte("$1[$3]byte"))


+ 10
- 0
unix/syscall_netbsd.go View File

@@ -249,6 +249,14 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
return sendfile(outfd, infd, offset, count)
}

func Fstatvfs(fd int, buf *Statvfs_t) (err error) {
return Fstatvfs1(fd, buf, ST_WAIT)
}

func Statvfs(path string, buf *Statvfs_t) (err error) {
return Statvfs1(path, buf, ST_WAIT)
}

/*
* Exposed directly
*/
@@ -287,6 +295,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
//sys Fpathconf(fd int, name int) (val int, err error)
//sys Fstat(fd int, stat *Stat_t) (err error)
//sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
//sys Fstatvfs1(fd int, buf *Statvfs_t) (err error) = SYS_FSTATVFS1
//sys Fsync(fd int) (err error)
//sys Ftruncate(fd int, length int64) (err error)
//sysnb Getegid() (egid int)
@@ -343,6 +352,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
//sysnb Settimeofday(tp *Timeval) (err error)
//sysnb Setuid(uid int) (err error)
//sys Stat(path string, stat *Stat_t) (err error)
//sys Statvfs1(path string, buf *Statvfs_t) (err error) = SYS_STATVFS1
//sys Symlink(path string, link string) (err error)
//sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error)
//sys Sync() (err error)


+ 33
- 0
unix/syscall_netbsd_test.go 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)
}
}

+ 10
- 0
unix/types_netbsd.go View File

@@ -33,6 +33,7 @@ package unix
#include <sys/signal.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/uio.h>
@@ -106,6 +107,8 @@ type Stat_t C.struct_stat

type Statfs_t C.struct_statfs

type Statvfs_t C.struct_statvfs

type Flock_t C.struct_flock

type Dirent C.struct_dirent
@@ -118,6 +121,13 @@ const (
PathMax = C.PATH_MAX
)

// Fstatvfs/Statvfs flags

const (
ST_WAIT = C.ST_WAIT
ST_NOWAIT = C.ST_NOWAIT
)

// Advice to Fadvise

const (


+ 25
- 0
unix/zsyscall_netbsd_386.go View File

@@ -926,6 +926,16 @@ func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fstatvfs1(fd int, buf *Statvfs_t, flags int) (err error) {
_, _, e1 := Syscall(SYS_FSTATVFS1, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(flags))
if e1 != 0 {
err = errnoErr(e1)
}
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fsync(fd int) (err error) {
_, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0)
if e1 != 0 {
@@ -1635,6 +1645,21 @@ func Stat(path string, stat *Stat_t) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Statvfs1(path string, buf *Statvfs_t, flags int) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
if err != nil {
return
}
_, _, e1 := Syscall(SYS_STATVFS1, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(buf)), uintptr(flags))
if e1 != 0 {
err = errnoErr(e1)
}
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Symlink(path string, link string) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)


+ 25
- 0
unix/zsyscall_netbsd_amd64.go View File

@@ -926,6 +926,16 @@ func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fstatvfs1(fd int, buf *Statvfs_t, flags int) (err error) {
_, _, e1 := Syscall(SYS_FSTATVFS1, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(flags))
if e1 != 0 {
err = errnoErr(e1)
}
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fsync(fd int) (err error) {
_, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0)
if e1 != 0 {
@@ -1635,6 +1645,21 @@ func Stat(path string, stat *Stat_t) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Statvfs1(path string, buf *Statvfs_t, flags int) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
if err != nil {
return
}
_, _, e1 := Syscall(SYS_STATVFS1, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(buf)), uintptr(flags))
if e1 != 0 {
err = errnoErr(e1)
}
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Symlink(path string, link string) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)


+ 25
- 0
unix/zsyscall_netbsd_arm.go View File

@@ -926,6 +926,16 @@ func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fstatvfs1(fd int, buf *Statvfs_t, flags int) (err error) {
_, _, e1 := Syscall(SYS_FSTATVFS1, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(flags))
if e1 != 0 {
err = errnoErr(e1)
}
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fsync(fd int) (err error) {
_, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0)
if e1 != 0 {
@@ -1635,6 +1645,21 @@ func Stat(path string, stat *Stat_t) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Statvfs1(path string, buf *Statvfs_t, flags int) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
if err != nil {
return
}
_, _, e1 := Syscall(SYS_STATVFS1, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(buf)), uintptr(flags))
if e1 != 0 {
err = errnoErr(e1)
}
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Symlink(path string, link string) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)


+ 25
- 0
unix/zsyscall_netbsd_arm64.go View File

@@ -926,6 +926,16 @@ func Fstatat(fd int, path string, stat *Stat_t, flags int) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fstatvfs1(fd int, buf *Statvfs_t, flags int) (err error) {
_, _, e1 := Syscall(SYS_FSTATVFS1, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(flags))
if e1 != 0 {
err = errnoErr(e1)
}
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Fsync(fd int) (err error) {
_, _, e1 := Syscall(SYS_FSYNC, uintptr(fd), 0, 0)
if e1 != 0 {
@@ -1635,6 +1645,21 @@ func Stat(path string, stat *Stat_t) (err error) {

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Statvfs1(path string, buf *Statvfs_t, flags int) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
if err != nil {
return
}
_, _, e1 := Syscall(SYS_STATVFS1, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(buf)), uintptr(flags))
if e1 != 0 {
err = errnoErr(e1)
}
return
}

// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT

func Symlink(path string, link string) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)


+ 32
- 0
unix/ztypes_netbsd_386.go View File

@@ -78,6 +78,33 @@ type Stat_t struct {

type Statfs_t [0]byte

type Statvfs_t struct {
Flag uint32
Bsize uint32
Frsize uint32
Iosize uint32
Blocks uint64
Bfree uint64
Bavail uint64
Bresvd uint64
Files uint64
Ffree uint64
Favail uint64
Fresvd uint64
Syncreads uint64
Syncwrites uint64
Asyncreads uint64
Asyncwrites uint64
Fsidx Fsid
Fsid uint32
Namemax uint32
Owner uint32
Spare [4]uint32
Fstypename [32]byte
Mntonname [1024]byte
Mntfromname [1024]byte
}

type Flock_t struct {
Start int64
Len int64
@@ -103,6 +130,11 @@ const (
PathMax = 0x400
)

const (
ST_WAIT = 0x1
ST_NOWAIT = 0x2
)

const (
FADV_NORMAL = 0x0
FADV_RANDOM = 0x1


+ 33
- 0
unix/ztypes_netbsd_amd64.go View File

@@ -82,6 +82,34 @@ type Stat_t struct {

type Statfs_t [0]byte

type Statvfs_t struct {
Flag uint64
Bsize uint64
Frsize uint64
Iosize uint64
Blocks uint64
Bfree uint64
Bavail uint64
Bresvd uint64
Files uint64
Ffree uint64
Favail uint64
Fresvd uint64
Syncreads uint64
Syncwrites uint64
Asyncreads uint64
Asyncwrites uint64
Fsidx Fsid
Fsid uint64
Namemax uint64
Owner uint32
Spare [4]uint32
Fstypename [32]byte
Mntonname [1024]byte
Mntfromname [1024]byte
_ [4]byte
}

type Flock_t struct {
Start int64
Len int64
@@ -107,6 +135,11 @@ const (
PathMax = 0x400
)

const (
ST_WAIT = 0x1
ST_NOWAIT = 0x2
)

const (
FADV_NORMAL = 0x0
FADV_RANDOM = 0x1


+ 32
- 0
unix/ztypes_netbsd_arm.go View File

@@ -83,6 +83,33 @@ type Stat_t struct {

type Statfs_t [0]byte

type Statvfs_t struct {
Flag uint32
Bsize uint32
Frsize uint32
Iosize uint32
Blocks uint64
Bfree uint64
Bavail uint64
Bresvd uint64
Files uint64
Ffree uint64
Favail uint64
Fresvd uint64
Syncreads uint64
Syncwrites uint64
Asyncreads uint64
Asyncwrites uint64
Fsidx Fsid
Fsid uint32
Namemax uint32
Owner uint32
Spare [4]uint32
Fstypename [32]byte
Mntonname [1024]byte
Mntfromname [1024]byte
}

type Flock_t struct {
Start int64
Len int64
@@ -108,6 +135,11 @@ const (
PathMax = 0x400
)

const (
ST_WAIT = 0x1
ST_NOWAIT = 0x2
)

const (
FADV_NORMAL = 0x0
FADV_RANDOM = 0x1


+ 33
- 0
unix/ztypes_netbsd_arm64.go View File

@@ -82,6 +82,34 @@ type Stat_t struct {

type Statfs_t [0]byte

type Statvfs_t struct {
Flag uint64
Bsize uint64
Frsize uint64
Iosize uint64
Blocks uint64
Bfree uint64
Bavail uint64
Bresvd uint64
Files uint64
Ffree uint64
Favail uint64
Fresvd uint64
Syncreads uint64
Syncwrites uint64
Asyncreads uint64
Asyncwrites uint64
Fsidx Fsid
Fsid uint64
Namemax uint64
Owner uint32
Spare [4]uint32
Fstypename [32]byte
Mntonname [1024]byte
Mntfromname [1024]byte
_ [4]byte
}

type Flock_t struct {
Start int64
Len int64
@@ -107,6 +135,11 @@ const (
PathMax = 0x400
)

const (
ST_WAIT = 0x1
ST_NOWAIT = 0x2
)

const (
FADV_NORMAL = 0x0
FADV_RANDOM = 0x1


Loading…
Cancel
Save