Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get disk size for macOS and other arch #4

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions space.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !windows
// +build !windows
//go:build linux && !s390x && !netbsd
// +build linux,!s390x,!netbsd

package rotatelogs

Expand All @@ -13,7 +13,7 @@ func GetDiskSize(dir string) (total uint64, avail uint64, err error) {
if err != nil {
return 0, 0, err
}
avail = fs.Bavail * uint64(fs.Frsize)
total = fs.Blocks * uint64(fs.Frsize)
avail = uint64(fs.Bavail) * uint64(fs.Frsize)
total = uint64(fs.Blocks) * uint64(fs.Frsize)
return total, avail, nil
}
19 changes: 19 additions & 0 deletions space_bsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build darwin || dragonfly || s390x
// +build darwin dragonfly s390x

package rotatelogs

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

func GetDiskSize(dir string) (total uint64, avail uint64, err error) {
fs := unix.Statfs_t{}
err = unix.Statfs(dir, &fs)
if err != nil {
return 0, 0, err
}
avail = uint64(fs.Bavail) * uint64(fs.Bsize)
total = uint64(fs.Blocks) * uint64(fs.Bsize)
return total, avail, nil
}
17 changes: 17 additions & 0 deletions space_netbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build netbsd
// +build netbsd

package rotatelogs

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

func GetDiskSize(dir string) (total uint64, avail uint64, err error) {
fs := unix.Statvfs_t{}
err = unix.Statvfs(dir, &fs)
if err != nil {
return 0, 0, err
}
avail = fs.Bavail * fs.Frsize
total = fs.Blocks * fs.Frsize
return total, avail, nil
}
17 changes: 17 additions & 0 deletions space_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build openbsd
// +build openbsd

package rotatelogs

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

func GetDiskSize(dir string) (total uint64, avail uint64, err error) {
fs := unix.Statfs_t{}
err = unix.Statfs(dir, &fs)
if err != nil {
return 0, 0, err
}
avail = uint64(fs.F_bavail) * uint64(fs.F_bsize)
total = fs.F_blocks * uint64(fs.F_bsize)
return total, avail, nil
}
Loading