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