Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions filesystems_netbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//go:build netbsd
// +build netbsd

package main

func isFuseFs(m Mount) bool {
//FIXME: implement
return false
}

func isNetworkFs(m Mount) bool {
fs := []string{"nfs", "smbfs"}

for _, v := range fs {
if m.Fstype == v {
return true
}
}

return false
}

func isSpecialFs(m Mount) bool {
fs := []string{"devfs", "kernfs", "procfs", "ptyfs", "tmpfs"}

for _, v := range fs {
if m.Fstype == v {
return true
}
}

return false
}

func isHiddenFs(m Mount) bool {
return false
}
108 changes: 108 additions & 0 deletions mounts_netbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//go:build netbsd
// +build netbsd

package main

import (
"unsafe"
"golang.org/x/sys/unix"
)

func (m *Mount) Stat() unix.Statfs_t {
return m.Metadata.(unix.Statfs_t)
}

// Use unix.Getvfsstat when CL 550476 is merged
// https://go-review.googlesource.com/c/sys/+/550476
func Getvfsstat(buf []unix.Statvfs_t, flags int) (n int, err error) {
var (
_p0 unsafe.Pointer
bufsize uintptr
)
if len(buf) > 0 {
_p0 = unsafe.Pointer(&buf[0])
bufsize = unsafe.Sizeof(unix.Statvfs_t{}) * uintptr(len(buf))
}
r0, _, e1 := unix.Syscall(unix.SYS_GETVFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
n = int(r0)
if e1 != 0 {
err = e1
}
return
}

func mounts() ([]Mount, []string, error) {
var ret []Mount
var warnings []string

count, err := Getvfsstat(nil, unix.ST_WAIT)
if err != nil {
return nil, nil, err
}

fs := make([]unix.Statvfs_t, count)
if _, err := Getvfsstat(fs, unix.ST_WAIT); err != nil {
return nil, nil, err
}

for _, stat := range fs {
opts := "rw"
if stat.Flag&unix.MNT_RDONLY != 0 {
opts = "ro"
}
if stat.Flag&unix.MNT_SYNCHRONOUS != 0 {
opts += ",sync"
}
if stat.Flag&unix.MNT_NOEXEC != 0 {
opts += ",noexec"
}
if stat.Flag&unix.MNT_NOSUID != 0 {
opts += ",nosuid"
}
if stat.Flag&unix.MNT_NODEV != 0 {
opts += ",nodev"
}
if stat.Flag&unix.MNT_ASYNC != 0 {
opts += ",async"
}
if stat.Flag&unix.MNT_SOFTDEP != 0 {
opts += ",softdep"
}
if stat.Flag&unix.MNT_LOG != 0 {
opts += ",log"
}
if stat.Flag&unix.MNT_NOATIME != 0 {
opts += ",noatime"
}

device := byteToString(stat.Mntfromname[:])
mountPoint := byteToString(stat.Mntonname[:])
fsType := byteToString(stat.Fstypename[:])

if len(device) == 0 {
continue
}

d := Mount{
Device: device,
Mountpoint: mountPoint,
Fstype: fsType,
Type: fsType,
Opts: opts,
Metadata: stat,
Total: (uint64(stat.Blocks) * uint64(stat.Frsize)),
Free: (uint64(stat.Bavail) * uint64(stat.Frsize)),
Used: (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(stat.Frsize),
Inodes: stat.Files,
InodesFree: uint64(stat.Ffree),
InodesUsed: stat.Files - uint64(stat.Ffree),
Blocks: uint64(stat.Blocks),
BlockSize: uint64(stat.Frsize),
}
d.DeviceType = deviceType(d)

ret = append(ret, d)
}

return ret, warnings, nil
}