Initial commit on Forgejo
Fresh repository history for elektrine/magpie hosted at https://git.elektrine.com/elektrine/magpie.
This commit is contained in:
commit
ddbd19f153
23 changed files with 5636 additions and 0 deletions
21
disk_unix.go
Normal file
21
disk_unix.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
//go:build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func (s *FileStore) DiskStatus() (DiskStatus, error) {
|
||||
var stat syscall.Statfs_t
|
||||
if err := syscall.Statfs(s.root, &stat); err != nil {
|
||||
return DiskStatus{}, err
|
||||
}
|
||||
if stat.Bsize <= 0 {
|
||||
return DiskStatus{}, fmt.Errorf("invalid filesystem block size")
|
||||
}
|
||||
total := stat.Blocks * uint64(stat.Bsize)
|
||||
free := stat.Bavail * uint64(stat.Bsize)
|
||||
return DiskStatus{TotalBytes: total, FreeBytes: free, UsedBytes: total - free}, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue