|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
//go:build openbsd
|
|
|
|
|
// +build openbsd
|
|
|
|
|
//go:build netbsd
|
|
|
|
|
// +build netbsd
|
|
|
|
|
|
|
|
|
|
package disk
|
|
|
|
|
|
|
|
|
@ -7,24 +7,37 @@ import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/binary"
|
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
|
|
"github.com/shirou/gopsutil/v3/internal/common"
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// see sys/fstypes.h and `man 5 statvfs`
|
|
|
|
|
MNT_RDONLY = 0x00000001 /* read only filesystem */
|
|
|
|
|
MNT_SYNCHRONOUS = 0x00000002 /* file system written synchronously */
|
|
|
|
|
MNT_NOEXEC = 0x00000004 /* can't exec from filesystem */
|
|
|
|
|
MNT_NOSUID = 0x00000008 /* don't honor setuid bits on fs */
|
|
|
|
|
MNT_NODEV = 0x00000010 /* don't interpret special files */
|
|
|
|
|
MNT_ASYNC = 0x00000040 /* file system written asynchronously */
|
|
|
|
|
MNT_NOATIME = 0x04000000 /* Never update access times in fs */
|
|
|
|
|
MNT_SOFTDEP = 0x80000000 /* Use soft dependencies */
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
|
|
|
|
var ret []PartitionStat
|
|
|
|
|
|
|
|
|
|
flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h
|
|
|
|
|
|
|
|
|
|
// get required buffer size
|
|
|
|
|
r, _, err = unix.Syscall6(
|
|
|
|
|
r, _, err := unix.Syscall(
|
|
|
|
|
483, // SYS___getvfsstat90 syscall
|
|
|
|
|
nil,
|
|
|
|
|
0,
|
|
|
|
|
uintptr(unsafe.Pointer(&flag)),
|
|
|
|
|
0,
|
|
|
|
|
uintptr(unsafe.Pointer(&flag)),
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if err != 0 {
|
|
|
|
|
return ret, err
|
|
|
|
|
}
|
|
|
|
|
mountedFsCount := uint64(r)
|
|
|
|
@ -34,17 +47,43 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|
|
|
|
buf := make([]Statvfs, bufSize)
|
|
|
|
|
|
|
|
|
|
// request agian to get desired mount data
|
|
|
|
|
_, _, err = unix.Syscall6(
|
|
|
|
|
_, _, err = unix.Syscall(
|
|
|
|
|
483,
|
|
|
|
|
uintptr(unsafe.Pointer(&buf[0])),
|
|
|
|
|
uintptr(unsafe.Pointer(&bufSize)),
|
|
|
|
|
uintptr(unsafe.Pointer(&flag)),
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if err != 0 {
|
|
|
|
|
return ret, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, stat := range buf {
|
|
|
|
|
opts := []string{"rw"}
|
|
|
|
|
if stat.Flag&MNT_RDONLY != 0 {
|
|
|
|
|
opts = []string{"rw"}
|
|
|
|
|
}
|
|
|
|
|
if stat.Flag&MNT_SYNCHRONOUS != 0 {
|
|
|
|
|
opts = append(opts, "sync")
|
|
|
|
|
}
|
|
|
|
|
if stat.Flag&MNT_NOEXEC != 0 {
|
|
|
|
|
opts = append(opts, "noexec")
|
|
|
|
|
}
|
|
|
|
|
if stat.Flag&MNT_NOSUID != 0 {
|
|
|
|
|
opts = append(opts, "nosuid")
|
|
|
|
|
}
|
|
|
|
|
if stat.Flag&MNT_NODEV != 0 {
|
|
|
|
|
opts = append(opts, "nodev")
|
|
|
|
|
}
|
|
|
|
|
if stat.Flag&MNT_ASYNC != 0 {
|
|
|
|
|
opts = append(opts, "async")
|
|
|
|
|
}
|
|
|
|
|
if stat.Flag&MNT_SOFTDEP != 0 {
|
|
|
|
|
opts = append(opts, "softdep")
|
|
|
|
|
}
|
|
|
|
|
if stat.Flag&MNT_NOATIME != 0 {
|
|
|
|
|
opts = append(opts, "noatime")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d := PartitionStat{
|
|
|
|
|
Device: common.ByteToString([]byte(stat.Mntfromname[:])),
|
|
|
|
|
Mountpoint: common.ByteToString([]byte(stat.Mntonname[:])),
|
|
|
|
@ -68,13 +107,13 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
|
|
|
|
flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h
|
|
|
|
|
|
|
|
|
|
// request agian to get desired mount data
|
|
|
|
|
ret, _, err = unix.Syscall6(
|
|
|
|
|
ret, _, err := unix.Syscall(
|
|
|
|
|
485, // SYS___fstatvfs190, see sys/syscall.h
|
|
|
|
|
uintptr(unsafe.Pointer(&path)),
|
|
|
|
|
uintptr(unsafe.Pointer(&stat)),
|
|
|
|
|
uintptr(unsafe.Pointer(&flag)),
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if err != 0 {
|
|
|
|
|
return ret, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|