2021-09-09 12:25:25 +00:00
|
|
|
//go:build darwin || dragonfly || freebsd || linux
|
2018-04-16 21:19:25 +00:00
|
|
|
// +build darwin dragonfly freebsd linux
|
|
|
|
|
|
|
|
package local
|
|
|
|
|
|
|
|
import (
|
2019-06-17 08:34:30 +00:00
|
|
|
"context"
|
2020-08-19 17:02:21 +00:00
|
|
|
"os"
|
2018-04-16 21:19:25 +00:00
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs"
|
2018-04-16 21:19:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// About gets quota information
|
2019-06-17 08:34:30 +00:00
|
|
|
func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
|
2018-04-16 21:19:25 +00:00
|
|
|
var s syscall.Statfs_t
|
|
|
|
err := syscall.Statfs(f.root, &s)
|
|
|
|
if err != nil {
|
2020-08-19 17:02:21 +00:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return nil, fs.ErrorDirNotFound
|
|
|
|
}
|
2018-04-16 21:19:25 +00:00
|
|
|
return nil, errors.Wrap(err, "failed to read disk usage")
|
|
|
|
}
|
2019-01-11 17:17:46 +00:00
|
|
|
bs := int64(s.Bsize) // nolint: unconvert
|
2018-04-16 21:19:25 +00:00
|
|
|
usage := &fs.Usage{
|
|
|
|
Total: fs.NewUsageValue(bs * int64(s.Blocks)), // quota of bytes that can be used
|
|
|
|
Used: fs.NewUsageValue(bs * int64(s.Blocks-s.Bfree)), // bytes in use
|
|
|
|
Free: fs.NewUsageValue(bs * int64(s.Bavail)), // bytes which can be uploaded before reaching the quota
|
|
|
|
}
|
|
|
|
return usage, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// check interface
|
|
|
|
var _ fs.Abouter = &Fs{}
|