github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/backend/local/about_unix.go (about)

     1  // +build darwin dragonfly freebsd linux
     2  
     3  package local
     4  
     5  import (
     6  	"context"
     7  	"syscall"
     8  
     9  	"github.com/pkg/errors"
    10  	"github.com/rclone/rclone/fs"
    11  )
    12  
    13  // About gets quota information
    14  func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
    15  	var s syscall.Statfs_t
    16  	err := syscall.Statfs(f.root, &s)
    17  	if err != nil {
    18  		return nil, errors.Wrap(err, "failed to read disk usage")
    19  	}
    20  	bs := int64(s.Bsize) // nolint: unconvert
    21  	usage := &fs.Usage{
    22  		Total: fs.NewUsageValue(bs * int64(s.Blocks)),         // quota of bytes that can be used
    23  		Used:  fs.NewUsageValue(bs * int64(s.Blocks-s.Bfree)), // bytes in use
    24  		Free:  fs.NewUsageValue(bs * int64(s.Bavail)),         // bytes which can be uploaded before reaching the quota
    25  	}
    26  	return usage, nil
    27  }
    28  
    29  // check interface
    30  var _ fs.Abouter = &Fs{}