Skip to content

Commit

Permalink
Merge pull request #365 from SiaFoundation/nate/openbsd-disk
Browse files Browse the repository at this point in the history
Add OpenBSD support to diskutils
  • Loading branch information
ChrisSchinnerl authored Apr 18, 2024
2 parents bd236b2 + fcf2857 commit 28f9481
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/disk/usage_default.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !windows
//go:build !windows && !openbsd

package disk

Expand All @@ -11,6 +11,9 @@ func Usage(p string) (free, total uint64, err error) {
if err := unix.Statfs(p, &stat); err != nil {
return 0, 0, err
}
// Linux-based systems and Darwin use bfree and blocks to represent the
// number of free and total blocks in the filesystem. Multiplying by f_bsize
// converts that to the number of free and total bytes of a filesystem.
return stat.Bfree * uint64(stat.Bsize), stat.Blocks * uint64(stat.Bsize), nil
}

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

package disk

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

// Usage returns the free and total bytes on the filesystem containing the
// specified path.
func Usage(p string) (free, total uint64, err error) {
var stat unix.Statfs_t
if err := unix.Statfs(p, &stat); err != nil {
return 0, 0, err
}
// OpenBSD uses f_bfree and f_blocks to represent the number of free and
// total blocks in the filesystem. Multiplying by f_bsize converts that to
// the number of free and total bytes of a filesystem.
return stat.F_bfree * uint64(stat.F_bsize), stat.F_blocks * uint64(stat.F_bsize), nil
}

// Drives returns the paths of all drives on Windows. It is a no-op on other systems
func Drives() ([]string, error) {
return nil, nil
}

0 comments on commit 28f9481

Please sign in to comment.