Skip to content

Commit

Permalink
Add support for OpenBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Sep 25, 2020
1 parent c8cc3e9 commit e23f681
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 2 deletions.
22 changes: 22 additions & 0 deletions filesystems_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// +build openbsd

package main

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

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

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

func isSpecialFs(m Mount) bool {
return m.Fstype == "devfs"
}
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func renderTables(m []Mount, sortCol int) error {
continue
}
// skip special devices
if v.Stat.Blocks == 0 && !*all {
if v.Blocks == 0 && !*all {
continue
}
// skip zero size devices
if v.Stat.Bsize == 0 && !*all {
if v.BlockSize == 0 && !*all {
continue
}

Expand Down
2 changes: 2 additions & 0 deletions mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type Mount struct {
Inodes uint64 `json:"inodes"`
InodesFree uint64 `json:"inodes_free"`
InodesUsed uint64 `json:"inodes_used"`
Blocks uint64 `json:"blocks"`
BlockSize uint64 `json:"block_size"`
Stat unix.Statfs_t `json:"-"`
}

Expand Down
2 changes: 2 additions & 0 deletions mounts_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func mounts() ([]Mount, []string, error) {
Inodes: stat.Files,
InodesFree: stat.Ffree,
InodesUsed: stat.Files - stat.Ffree,
Blocks: uint64(stat.Blocks),
BlockSize: uint64(stat.Bsize),
}
d.DeviceType = deviceType(d)

Expand Down
2 changes: 2 additions & 0 deletions mounts_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func mounts() ([]Mount, []string, error) {
Inodes: stat.Files,
InodesFree: uint64(stat.Ffree),
InodesUsed: stat.Files - uint64(stat.Ffree),
Blocks: uint64(stat.Blocks),
BlockSize: uint64(stat.Bsize),
}
d.DeviceType = deviceType(d)

Expand Down
2 changes: 2 additions & 0 deletions mounts_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func mounts() ([]Mount, []string, error) {
Inodes: stat.Files,
InodesFree: stat.Ffree,
InodesUsed: stat.Files - stat.Ffree,
Blocks: uint64(stat.Blocks),
BlockSize: uint64(stat.Bsize),
}
d.DeviceType = deviceType(d)

Expand Down
99 changes: 99 additions & 0 deletions mounts_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// +build openbsd

package main

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

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

count, err := unix.Getfsstat(nil, unix.MNT_WAIT)
if err != nil {
return nil, nil, err
}
fs := make([]unix.Statfs_t, count)
if _, err = unix.Getfsstat(fs, unix.MNT_WAIT); err != nil {
return nil, nil, err
}

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

device := intToString(stat.F_mntfromname[:])
mountPoint := intToString(stat.F_mntonname[:])
fsType := intToString(stat.F_fstypename[:])

if len(device) == 0 {
continue
}

d := Mount{
Device: device,
Mountpoint: mountPoint,
Fstype: fsType,
Type: fsType,
Opts: opts,
Stat: stat,
Total: (uint64(stat.F_blocks) * uint64(stat.F_bsize)),
Free: (uint64(stat.F_bavail) * uint64(stat.F_bsize)),
Used: (uint64(stat.F_blocks) - uint64(stat.F_bfree)) * uint64(stat.F_bsize),
Inodes: stat.F_files,
InodesFree: uint64(stat.F_ffree),
InodesUsed: stat.F_files - uint64(stat.F_ffree),
Blocks: uint64(stat.F_blocks),
BlockSize: uint64(stat.F_bsize),
}
d.DeviceType = deviceType(d)

ret = append(ret, d)
}

return ret, warnings, nil
}

func intToString(orig []int8) string {
ret := make([]byte, len(orig))
size := -1
for i, o := range orig {
if o == 0 {
size = i
break
}
ret[i] = byte(o)
}
if size == -1 {
size = len(orig)
}

return string(ret[0:size])
}

0 comments on commit e23f681

Please sign in to comment.