Commit 1e99a4f9 authored by Sean Chittenden's avatar Sean Chittenden Committed by Brad Fitzpatrick

unix: add Illumos statvfs(2) syscall

Reference: https://www.illumos.org/man/2/statvfs

Change-Id: If7af43da35b3204f5069a48eb08426a145544008
Reviewed-on: https://go-review.googlesource.com/43490Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent f845067c
......@@ -583,6 +583,7 @@ func IoctlGetTermio(fd int, req int) (*Termio, error) {
//sys Fdatasync(fd int) (err error)
//sys Fpathconf(fd int, name int) (val int, err error)
//sys Fstat(fd int, stat *Stat_t) (err error)
//sys Fstatvfs(fd int, vfsstat *Statvfs_t) (err error)
//sys Getdents(fd int, buf []byte, basep *uintptr) (n int, err error)
//sysnb Getgid() (gid int)
//sysnb Getpid() (pid int)
......@@ -639,6 +640,7 @@ func IoctlGetTermio(fd int, req int) (*Termio, error) {
//sysnb Setuid(uid int) (err error)
//sys Shutdown(s int, how int) (err error) = libsocket.shutdown
//sys Stat(path string, stat *Stat_t) (err error)
//sys Statvfs(path string, vfsstat *Statvfs_t) (err error)
//sys Symlink(path string, link string) (err error)
//sys Sync() (err error)
//sysnb Times(tms *Tms) (ticks uintptr, err error)
......
// Copyright 2017 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.
// +build solaris
package unix_test
import (
"os/exec"
"testing"
"golang.org/x/sys/unix"
)
func TestStatvfs(t *testing.T) {
if err := unix.Statvfs("", nil); err == nil {
t.Fatal(`Statvfs("") expected failure`)
}
statvfs := unix.Statvfs_t{}
if err := unix.Statvfs("/", &statvfs); err != nil {
t.Errorf(`Statvfs("/") failed: %v`, err)
}
if t.Failed() {
mount, err := exec.Command("mount").CombinedOutput()
if err != nil {
t.Logf("mount: %v\n%s", err, mount)
} else {
t.Logf("mount: %s", mount)
}
}
}
......@@ -37,6 +37,7 @@ package unix
#include <sys/signal.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
......@@ -139,6 +140,12 @@ type Flock_t C.struct_flock
type Dirent C.struct_dirent
// Filesystems
type _Fsblkcnt_t C.fsblkcnt_t
type Statvfs_t C.struct_statvfs
// Sockets
type RawSockaddrInet4 C.struct_sockaddr_in
......
......@@ -45,6 +45,7 @@ import (
//go:cgo_import_dynamic libc_fdatasync fdatasync "libc.so"
//go:cgo_import_dynamic libc_fpathconf fpathconf "libc.so"
//go:cgo_import_dynamic libc_fstat fstat "libc.so"
//go:cgo_import_dynamic libc_fstatvfs fstatvfs "libc.so"
//go:cgo_import_dynamic libc_getdents getdents "libc.so"
//go:cgo_import_dynamic libc_getgid getgid "libc.so"
//go:cgo_import_dynamic libc_getpid getpid "libc.so"
......@@ -101,6 +102,7 @@ import (
//go:cgo_import_dynamic libc_setuid setuid "libc.so"
//go:cgo_import_dynamic libc_shutdown shutdown "libsocket.so"
//go:cgo_import_dynamic libc_stat stat "libc.so"
//go:cgo_import_dynamic libc_statvfs statvfs "libc.so"
//go:cgo_import_dynamic libc_symlink symlink "libc.so"
//go:cgo_import_dynamic libc_sync sync "libc.so"
//go:cgo_import_dynamic libc_times times "libc.so"
......@@ -163,6 +165,7 @@ import (
//go:linkname procFdatasync libc_fdatasync
//go:linkname procFpathconf libc_fpathconf
//go:linkname procFstat libc_fstat
//go:linkname procFstatvfs libc_fstatvfs
//go:linkname procGetdents libc_getdents
//go:linkname procGetgid libc_getgid
//go:linkname procGetpid libc_getpid
......@@ -219,6 +222,7 @@ import (
//go:linkname procSetuid libc_setuid
//go:linkname procshutdown libc_shutdown
//go:linkname procStat libc_stat
//go:linkname procStatvfs libc_statvfs
//go:linkname procSymlink libc_symlink
//go:linkname procSync libc_sync
//go:linkname procTimes libc_times
......@@ -282,6 +286,7 @@ var (
procFdatasync,
procFpathconf,
procFstat,
procFstatvfs,
procGetdents,
procGetgid,
procGetpid,
......@@ -338,6 +343,7 @@ var (
procSetuid,
procshutdown,
procStat,
procStatvfs,
procSymlink,
procSync,
procTimes,
......@@ -713,6 +719,14 @@ func Fstat(fd int, stat *Stat_t) (err error) {
return
}
func Fstatvfs(fd int, vfsstat *Statvfs_t) (err error) {
_, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procFstatvfs)), 2, uintptr(fd), uintptr(unsafe.Pointer(vfsstat)), 0, 0, 0, 0)
if e1 != 0 {
err = e1
}
return
}
func Getdents(fd int, buf []byte, basep *uintptr) (n int, err error) {
var _p0 *byte
if len(buf) > 0 {
......@@ -1302,6 +1316,19 @@ func Stat(path string, stat *Stat_t) (err error) {
return
}
func Statvfs(path string, vfsstat *Statvfs_t) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
if err != nil {
return
}
_, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procStatvfs)), 2, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(vfsstat)), 0, 0, 0, 0)
if e1 != 0 {
err = e1
}
return
}
func Symlink(path string, link string) (err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
......
......@@ -129,6 +129,24 @@ type Dirent struct {
Pad_cgo_0 [5]byte
}
type _Fsblkcnt_t uint64
type Statvfs_t struct {
Bsize uint64
Frsize uint64
Blocks uint64
Bfree uint64
Bavail uint64
Files uint64
Ffree uint64
Favail uint64
Fsid uint64
Basetype [16]int8
Flag uint64
Namemax uint64
Fstr [32]int8
}
type RawSockaddrInet4 struct {
Family uint16
Port uint16
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment