mirror of
https://github.com/rclone/rclone.git
synced 2024-11-26 18:34:41 +01:00
e43b5ce5e5
This is possible now that we no longer support go1.12 and brings rclone into line with standard practices in the Go world. This also removes errors.New and errors.Errorf from lib/errors and prefers the stdlib errors package over lib/errors.
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
//go:build windows
|
|
// +build windows
|
|
|
|
package local
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"syscall"
|
|
"unsafe"
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
)
|
|
|
|
var getFreeDiskSpace = syscall.NewLazyDLL("kernel32.dll").NewProc("GetDiskFreeSpaceExW")
|
|
|
|
// About gets quota information
|
|
func (f *Fs) About(ctx context.Context) (*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, fmt.Errorf("failed to read disk usage: %w", e1)
|
|
}
|
|
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{}
|