mirror of
https://github.com/rclone/rclone.git
synced 2024-12-24 16:09:01 +01:00
1ac6dacf0f
* Implement about for: * local, crypt, cache, drive, swift, hubic, onedrive, pcloud, dropbox * Implement `--json` and `---full` flag for `rclone about` * change About interface to return a Usage structure * Remove operations.About as it is too thin an interface * Implement Integration test Relates to #1138 and #1564
37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
// +build windows
|
|
|
|
package local
|
|
|
|
import (
|
|
"syscall"
|
|
"unsafe"
|
|
|
|
"github.com/ncw/rclone/fs"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
var getFreeDiskSpace = syscall.NewLazyDLL("kernel32.dll").NewProc("GetDiskFreeSpaceExW")
|
|
|
|
// About gets quota information
|
|
func (f *Fs) About() (*fs.Usage, error) {
|
|
var available, total, free int64
|
|
_, _, e1 := getFreeDiskSpace.Call(
|
|
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(f.root))),
|
|
uintptr(unsafe.Pointer(&available)), // lpFreeBytesAvailable - for this user
|
|
uintptr(unsafe.Pointer(&total)), // lpTotalNumberOfBytes
|
|
uintptr(unsafe.Pointer(&free)), // lpTotalNumberOfFreeBytes
|
|
)
|
|
if e1 != syscall.Errno(0) {
|
|
return nil, errors.Wrap(e1, "failed to read disk usage")
|
|
}
|
|
usage := &fs.Usage{
|
|
Total: fs.NewUsageValue(total), // quota of bytes that can be used
|
|
Used: fs.NewUsageValue(total - free), // bytes in use
|
|
Free: fs.NewUsageValue(available), // bytes which can be uploaded before reaching the quota
|
|
}
|
|
return usage, nil
|
|
}
|
|
|
|
// check interface
|
|
var _ fs.Abouter = &Fs{}
|