-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #365 from SiaFoundation/nate/openbsd-disk
Add OpenBSD support to diskutils
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |