2021-09-09 12:25:25 +00:00
|
|
|
//go:build windows
|
2018-04-16 21:19:25 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package local
|
|
|
|
|
|
|
|
import (
|
2019-06-17 08:34:30 +00:00
|
|
|
"context"
|
2021-11-04 10:12:57 +00:00
|
|
|
"fmt"
|
2018-04-16 21:19:25 +00:00
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs"
|
2018-04-16 21:19:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var getFreeDiskSpace = syscall.NewLazyDLL("kernel32.dll").NewProc("GetDiskFreeSpaceExW")
|
|
|
|
|
|
|
|
// 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 available, total, free int64
|
2022-06-08 20:25:17 +00:00
|
|
|
root, e := syscall.UTF16PtrFromString(f.root)
|
|
|
|
if e != nil {
|
|
|
|
return nil, fmt.Errorf("failed to read disk usage: %w", e)
|
|
|
|
}
|
2018-04-16 21:19:25 +00:00
|
|
|
_, _, e1 := getFreeDiskSpace.Call(
|
2022-06-08 20:25:17 +00:00
|
|
|
uintptr(unsafe.Pointer(root)),
|
2018-04-16 21:19:25 +00:00
|
|
|
uintptr(unsafe.Pointer(&available)), // lpFreeBytesAvailable - for this user
|
|
|
|
uintptr(unsafe.Pointer(&total)), // lpTotalNumberOfBytes
|
|
|
|
uintptr(unsafe.Pointer(&free)), // lpTotalNumberOfFreeBytes
|
|
|
|
)
|
|
|
|
if e1 != syscall.Errno(0) {
|
2021-11-04 10:12:57 +00:00
|
|
|
return nil, fmt.Errorf("failed to read disk usage: %w", e1)
|
2018-04-16 21:19:25 +00:00
|
|
|
}
|
|
|
|
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{}
|