Skip to content

Commit

Permalink
util(disk): freebsd and netbsd support
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Jan 7, 2025
1 parent 9744374 commit 0cf4f65
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
22 changes: 22 additions & 0 deletions util/disk/disk_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build freebsd

package disk

import (
"syscall"

"github.com/pkg/errors"
)

func GetDiskStat(root string) (DiskStat, error) {
var st syscall.Statfs_t
if err := syscall.Statfs(root, &st); err != nil {
return DiskStat{}, errors.Wrapf(err, "could not stat fs at %s", root)
}

return DiskStat{
Total: int64(st.Bsize) * int64(st.Blocks),
Free: int64(st.Bsize) * int64(st.Bfree),
Available: int64(st.Bsize) * int64(st.Bavail),
}, nil
}
21 changes: 21 additions & 0 deletions util/disk/disk_netbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build netbsd

package disk

import (
"github.com/pkg/errors"
"golang.org/x/sys/unix"
)

func GetDiskStat(root string) (DiskStat, error) {
var st unix.Statvfs_t
if err := unix.Statvfs(root, &st); err != nil {
return DiskStat{}, errors.Wrapf(err, "could not stat fs at %s", root)
}

return DiskStat{
Total: int64(st.Frsize) * int64(st.Blocks),
Free: int64(st.Frsize) * int64(st.Bfree),
Available: int64(st.Frsize) * int64(st.Bavail),
}, nil
}
2 changes: 1 addition & 1 deletion util/disk/disk_unix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !windows && !openbsd
//go:build !windows && !freebsd && !netbsd && !openbsd

package disk

Expand Down

0 comments on commit 0cf4f65

Please sign in to comment.