Use Getstatfs from golang.org/x/sys/unix for 64-bit inode support on FreeBSD 12

Use unix.Getstatfs and its associated Statfs_t type instead of
implementing them locally in this package. This allows to use 64-bit
inode fields on FreeBSD 12 while still keeping backwards compatibility
for old FreeBSD versions, as unix.Getfsstat will use the correct syscall
number and data structure version and convert its result
correspondingly.

Also see https://golang.org/cl/136816 for details.
pull/810/head
Tobias Klauser 5 years ago
parent c0410b92ca
commit 6aae71ca26

@ -8,7 +8,6 @@ import (
"encoding/binary" "encoding/binary"
"path" "path"
"strconv" "strconv"
"unsafe"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -28,8 +27,8 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
return ret, err return ret, err
} }
fs := make([]Statfs, count) fs := make([]unix.Statfs_t, count)
if _, err = Getfsstat(fs, unix.MNT_WAIT); err != nil { if _, err = unix.Getfsstat(fs, unix.MNT_WAIT); err != nil {
return ret, err return ret, err
} }
@ -158,27 +157,6 @@ func (b Bintime) Compute() float64 {
// BT2LD(time) ((long double)(time).sec + (time).frac * BINTIME_SCALE) // BT2LD(time) ((long double)(time).sec + (time).frac * BINTIME_SCALE)
// Getfsstat is borrowed from pkg/syscall/syscall_freebsd.go
// change Statfs_t to Statfs in order to get more information
func Getfsstat(buf []Statfs, flags int) (n int, err error) {
return GetfsstatWithContext(context.Background(), buf, flags)
}
func GetfsstatWithContext(ctx context.Context, buf []Statfs, flags int) (n int, err error) {
var _p0 unsafe.Pointer
var bufsize uintptr
if len(buf) > 0 {
_p0 = unsafe.Pointer(&buf[0])
bufsize = unsafe.Sizeof(Statfs{}) * uintptr(len(buf))
}
r0, _, e1 := unix.Syscall(unix.SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
n = int(r0)
if e1 != 0 {
err = e1
}
return
}
func parseDevstat(buf []byte) (Devstat, error) { func parseDevstat(buf []byte) (Devstat, error) {
var ds Devstat var ds Devstat
br := bytes.NewReader(buf) br := bytes.NewReader(buf)

@ -29,34 +29,6 @@ type (
_C_long_double int64 _C_long_double int64
) )
type Statfs struct {
Version uint32
Type uint32
Flags uint64
Bsize uint64
Iosize uint64
Blocks uint64
Bfree uint64
Bavail int64
Files uint64
Ffree int64
Syncwrites uint64
Asyncwrites uint64
Syncreads uint64
Asyncreads uint64
Spare [10]uint64
Namemax uint32
Owner uint32
Fsid Fsid
Charspare [80]int8
Fstypename [16]int8
Mntfromname [88]int8
Mntonname [88]int8
}
type Fsid struct {
Val [2]int32
}
type Devstat struct { type Devstat struct {
Sequence0 uint32 Sequence0 uint32
Allocated int32 Allocated int32

@ -29,34 +29,6 @@ type (
_C_long_double int64 _C_long_double int64
) )
type Statfs struct {
Version uint32
Type uint32
Flags uint64
Bsize uint64
Iosize uint64
Blocks uint64
Bfree uint64
Bavail int64
Files uint64
Ffree int64
Syncwrites uint64
Asyncwrites uint64
Syncreads uint64
Asyncreads uint64
Spare [10]uint64
Namemax uint32
Owner uint32
Fsid Fsid
Charspare [80]int8
Fstypename [16]int8
Mntfromname [88]int8
Mntonname [88]int8
}
type Fsid struct {
Val [2]int32
}
type Devstat struct { type Devstat struct {
Sequence0 uint32 Sequence0 uint32
Allocated int32 Allocated int32

@ -29,34 +29,6 @@ type (
_C_long_double int64 _C_long_double int64
) )
type Statfs struct {
Version uint32
Type uint32
Flags uint64
Bsize uint64
Iosize uint64
Blocks uint64
Bfree uint64
Bavail int64
Files uint64
Ffree int64
Syncwrites uint64
Asyncwrites uint64
Syncreads uint64
Asyncreads uint64
Spare [10]uint64
Namemax uint32
Owner uint32
Fsid Fsid
Charspare [80]int8
Fstypename [16]int8
Mntfromname [88]int8
Mntonname [88]int8
}
type Fsid struct {
Val [2]int32
}
type Devstat struct { type Devstat struct {
Sequence0 uint32 Sequence0 uint32
Allocated int32 Allocated int32

@ -31,34 +31,6 @@ type (
_C_long_double int64 _C_long_double int64
) )
type Statfs struct {
Version uint32
Type uint32
Flags uint64
Bsize uint64
Iosize uint64
Blocks uint64
Bfree uint64
Bavail int64
Files uint64
Ffree int64
Syncwrites uint64
Asyncwrites uint64
Syncreads uint64
Asyncreads uint64
Spare [10]uint64
Namemax uint32
Owner uint32
Fsid Fsid
Charspare [80]uint8
Fstypename [16]int8
Mntfromname [1024]int8
Mntonname [1024]int8
}
type Fsid struct {
Val [2]int32
}
type Devstat struct { type Devstat struct {
Sequence0 uint32 Sequence0 uint32
Allocated int32 Allocated int32

@ -58,8 +58,5 @@ type (
_C_long_double C.longlong _C_long_double C.longlong
) )
type Statfs C.struct_statfs
type Fsid C.struct_fsid
type Devstat C.struct_devstat type Devstat C.struct_devstat
type Bintime C.struct_bintime type Bintime C.struct_bintime

Loading…
Cancel
Save