forked from lestrrat-go/file-rotatelogs
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #4 from taosdata/fix/xftan/spcae
fix: get disk size for macOS and other arch
- Loading branch information
Showing
4 changed files
with
57 additions
and
4 deletions.
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,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 | ||
} |
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,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 | ||
} |
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,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 | ||
} |