mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-05 00:27:17 -04:00
unix: add Illumos statvfs(2) syscall
Reference: https://www.illumos.org/man/2/statvfs Change-Id: If7af43da35b3204f5069a48eb08426a145544008 Reviewed-on: https://go-review.googlesource.com/43490 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
f845067cf7
commit
1e99a4f9d2
@@ -583,6 +583,7 @@ func IoctlGetTermio(fd int, req int) (*Termio, error) {
|
|||||||
//sys Fdatasync(fd int) (err error)
|
//sys Fdatasync(fd int) (err error)
|
||||||
//sys Fpathconf(fd int, name int) (val int, err error)
|
//sys Fpathconf(fd int, name int) (val int, err error)
|
||||||
//sys Fstat(fd int, stat *Stat_t) (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)
|
//sys Getdents(fd int, buf []byte, basep *uintptr) (n int, err error)
|
||||||
//sysnb Getgid() (gid int)
|
//sysnb Getgid() (gid int)
|
||||||
//sysnb Getpid() (pid int)
|
//sysnb Getpid() (pid int)
|
||||||
@@ -639,6 +640,7 @@ func IoctlGetTermio(fd int, req int) (*Termio, error) {
|
|||||||
//sysnb Setuid(uid int) (err error)
|
//sysnb Setuid(uid int) (err error)
|
||||||
//sys Shutdown(s int, how int) (err error) = libsocket.shutdown
|
//sys Shutdown(s int, how int) (err error) = libsocket.shutdown
|
||||||
//sys Stat(path string, stat *Stat_t) (err error)
|
//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 Symlink(path string, link string) (err error)
|
||||||
//sys Sync() (err error)
|
//sys Sync() (err error)
|
||||||
//sysnb Times(tms *Tms) (ticks uintptr, err error)
|
//sysnb Times(tms *Tms) (ticks uintptr, err error)
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// 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/signal.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/statvfs.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/times.h>
|
#include <sys/times.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -139,6 +140,12 @@ type Flock_t C.struct_flock
|
|||||||
|
|
||||||
type Dirent C.struct_dirent
|
type Dirent C.struct_dirent
|
||||||
|
|
||||||
|
// Filesystems
|
||||||
|
|
||||||
|
type _Fsblkcnt_t C.fsblkcnt_t
|
||||||
|
|
||||||
|
type Statvfs_t C.struct_statvfs
|
||||||
|
|
||||||
// Sockets
|
// Sockets
|
||||||
|
|
||||||
type RawSockaddrInet4 C.struct_sockaddr_in
|
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_fdatasync fdatasync "libc.so"
|
||||||
//go:cgo_import_dynamic libc_fpathconf fpathconf "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_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_getdents getdents "libc.so"
|
||||||
//go:cgo_import_dynamic libc_getgid getgid "libc.so"
|
//go:cgo_import_dynamic libc_getgid getgid "libc.so"
|
||||||
//go:cgo_import_dynamic libc_getpid getpid "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_setuid setuid "libc.so"
|
||||||
//go:cgo_import_dynamic libc_shutdown shutdown "libsocket.so"
|
//go:cgo_import_dynamic libc_shutdown shutdown "libsocket.so"
|
||||||
//go:cgo_import_dynamic libc_stat stat "libc.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_symlink symlink "libc.so"
|
||||||
//go:cgo_import_dynamic libc_sync sync "libc.so"
|
//go:cgo_import_dynamic libc_sync sync "libc.so"
|
||||||
//go:cgo_import_dynamic libc_times times "libc.so"
|
//go:cgo_import_dynamic libc_times times "libc.so"
|
||||||
@@ -163,6 +165,7 @@ import (
|
|||||||
//go:linkname procFdatasync libc_fdatasync
|
//go:linkname procFdatasync libc_fdatasync
|
||||||
//go:linkname procFpathconf libc_fpathconf
|
//go:linkname procFpathconf libc_fpathconf
|
||||||
//go:linkname procFstat libc_fstat
|
//go:linkname procFstat libc_fstat
|
||||||
|
//go:linkname procFstatvfs libc_fstatvfs
|
||||||
//go:linkname procGetdents libc_getdents
|
//go:linkname procGetdents libc_getdents
|
||||||
//go:linkname procGetgid libc_getgid
|
//go:linkname procGetgid libc_getgid
|
||||||
//go:linkname procGetpid libc_getpid
|
//go:linkname procGetpid libc_getpid
|
||||||
@@ -219,6 +222,7 @@ import (
|
|||||||
//go:linkname procSetuid libc_setuid
|
//go:linkname procSetuid libc_setuid
|
||||||
//go:linkname procshutdown libc_shutdown
|
//go:linkname procshutdown libc_shutdown
|
||||||
//go:linkname procStat libc_stat
|
//go:linkname procStat libc_stat
|
||||||
|
//go:linkname procStatvfs libc_statvfs
|
||||||
//go:linkname procSymlink libc_symlink
|
//go:linkname procSymlink libc_symlink
|
||||||
//go:linkname procSync libc_sync
|
//go:linkname procSync libc_sync
|
||||||
//go:linkname procTimes libc_times
|
//go:linkname procTimes libc_times
|
||||||
@@ -282,6 +286,7 @@ var (
|
|||||||
procFdatasync,
|
procFdatasync,
|
||||||
procFpathconf,
|
procFpathconf,
|
||||||
procFstat,
|
procFstat,
|
||||||
|
procFstatvfs,
|
||||||
procGetdents,
|
procGetdents,
|
||||||
procGetgid,
|
procGetgid,
|
||||||
procGetpid,
|
procGetpid,
|
||||||
@@ -338,6 +343,7 @@ var (
|
|||||||
procSetuid,
|
procSetuid,
|
||||||
procshutdown,
|
procshutdown,
|
||||||
procStat,
|
procStat,
|
||||||
|
procStatvfs,
|
||||||
procSymlink,
|
procSymlink,
|
||||||
procSync,
|
procSync,
|
||||||
procTimes,
|
procTimes,
|
||||||
@@ -713,6 +719,14 @@ func Fstat(fd int, stat *Stat_t) (err error) {
|
|||||||
return
|
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) {
|
func Getdents(fd int, buf []byte, basep *uintptr) (n int, err error) {
|
||||||
var _p0 *byte
|
var _p0 *byte
|
||||||
if len(buf) > 0 {
|
if len(buf) > 0 {
|
||||||
@@ -1302,6 +1316,19 @@ func Stat(path string, stat *Stat_t) (err error) {
|
|||||||
return
|
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) {
|
func Symlink(path string, link string) (err error) {
|
||||||
var _p0 *byte
|
var _p0 *byte
|
||||||
_p0, err = BytePtrFromString(path)
|
_p0, err = BytePtrFromString(path)
|
||||||
|
|||||||
@@ -129,6 +129,24 @@ type Dirent struct {
|
|||||||
Pad_cgo_0 [5]byte
|
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 {
|
type RawSockaddrInet4 struct {
|
||||||
Family uint16
|
Family uint16
|
||||||
Port uint16
|
Port uint16
|
||||||
|
|||||||
Reference in New Issue
Block a user