Skip to content

Commit

Permalink
Merge pull request #4 from taosdata/fix/xftan/spcae
Browse files Browse the repository at this point in the history
fix: get disk size for macOS and other arch
  • Loading branch information
huskar-t authored Sep 2, 2024
2 parents 81b15b4 + 3e13ddf commit 4d2fc56
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
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
}

0 comments on commit 4d2fc56

Please sign in to comment.