diff --git a/mountinfo/mountinfo_bsd.go b/mountinfo/mountinfo_bsd.go index d1ea82ac..5e0db3c3 100644 --- a/mountinfo/mountinfo_bsd.go +++ b/mountinfo/mountinfo_bsd.go @@ -3,24 +3,15 @@ package mountinfo -import ( - "reflect" - "syscall" -) +import "syscall" -func getInfo(r reflect.Value, a string, b string) string { - if r.FieldByName(a) != (reflect.Value{}) { - r = r.FieldByName(a) - } else { - r = r.FieldByName(b) - } +func getInfo(is []int8) string { var bs []byte - for i := 0; i < r.Len(); i++ { - i8 := r.Index(i).Int() - if i8 == 0 { + for _, i := range is { + if i == 0 { break } - bs = append(bs, byte(i8)) + bs = append(bs, byte(i)) } return string(bs) } @@ -40,12 +31,8 @@ func parseMountTable(filter FilterFunc) ([]*Info, error) { var out []*Info for _, entry := range entries { - var mountinfo Info var skip, stop bool - r := reflect.ValueOf(entry) - mountinfo.Mountpoint = getInfo(r, "Mntonname", "F_mntonname" /* OpenBSD */) - mountinfo.FSType = getInfo(r, "Fstypename", "F_fstypename" /* OpenBSD */) - mountinfo.Source = getInfo(r, "Mntfromname", "F_mntfromname" /* OpenBSD */) + mountinfo := getMountinfo(entry) if filter != nil { // filter out entries we're not interested in diff --git a/mountinfo/mountinfo_freebsd.go b/mountinfo/mountinfo_freebsd.go new file mode 100644 index 00000000..0f72c27c --- /dev/null +++ b/mountinfo/mountinfo_freebsd.go @@ -0,0 +1,13 @@ +//go:build freebsd || darwin +// +build freebsd darwin + +package mountinfo + +import "syscall" + +func getMountinfo(entry syscall.Statfs_t) (mountinfo Info) { + mountinfo.Mountpoint = getInfo(entry.Mntonname[:]) + mountinfo.FSType = getInfo(entry.Fstypename[:]) + mountinfo.Source = getInfo(entry.Mntfromname[:]) + return +} diff --git a/mountinfo/mountinfo_openbsd.go b/mountinfo/mountinfo_openbsd.go new file mode 100644 index 00000000..5451b486 --- /dev/null +++ b/mountinfo/mountinfo_openbsd.go @@ -0,0 +1,13 @@ +//go:build openbsd +// +build openbsd + +package mountinfo + +import "syscall" + +func getMountinfo(entry syscall.Statfs_t) (mountinfo Info) { + mountinfo.Mountpoint = getInfo(entry.F_mntonname[:]) + mountinfo.FSType = getInfo(entry.F_fstypename[:]) + mountinfo.Source = getInfo(entry.F_mntfromname[:]) + return +}