2018-04-16 23:19:25 +02:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package local
|
|
|
|
|
|
|
|
import (
|
2019-06-17 10:34:30 +02:00
|
|
|
"context"
|
2018-04-16 23:19:25 +02:00
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"github.com/ncw/rclone/fs"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var getFreeDiskSpace = syscall.NewLazyDLL("kernel32.dll").NewProc("GetDiskFreeSpaceExW")
|
|
|
|
|
|
|
|
// 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 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{}
|