|
|
|
// +build windows
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2015 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package disk
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetInfo returns total and free bytes available in a directory, e.g. `C:\`.
|
|
|
|
// It returns free space available to the user (including quota limitations)
|
|
|
|
//
|
|
|
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx
|
|
|
|
func GetInfo(path string) (info Info, err error) {
|
|
|
|
dll := syscall.MustLoadDLL("kernel32.dll")
|
|
|
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx
|
|
|
|
// Retrieves information about the amount of space that is available on a disk volume,
|
|
|
|
// which is the total amount of space, the total amount of free space, and the total
|
|
|
|
// amount of free space available to the user that is associated with the calling thread.
|
|
|
|
GetDiskFreeSpaceEx := dll.MustFindProc("GetDiskFreeSpaceExW")
|
|
|
|
|
|
|
|
lpFreeBytesAvailable := int64(0)
|
|
|
|
lpTotalNumberOfBytes := int64(0)
|
|
|
|
lpTotalNumberOfFreeBytes := int64(0)
|
|
|
|
|
|
|
|
// Extract values safely
|
|
|
|
// BOOL WINAPI GetDiskFreeSpaceEx(
|
|
|
|
// _In_opt_ LPCTSTR lpDirectoryName,
|
|
|
|
// _Out_opt_ PULARGE_INTEGER lpFreeBytesAvailable,
|
|
|
|
// _Out_opt_ PULARGE_INTEGER lpTotalNumberOfBytes,
|
|
|
|
// _Out_opt_ PULARGE_INTEGER lpTotalNumberOfFreeBytes
|
|
|
|
// );
|
|
|
|
_, _, _ = GetDiskFreeSpaceEx.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))),
|
|
|
|
uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
|
|
|
|
uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
|
|
|
|
uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)))
|
|
|
|
info = Info{}
|
|
|
|
info.Total = int64(lpTotalNumberOfBytes)
|
|
|
|
info.Free = int64(lpFreeBytesAvailable)
|
|
|
|
info.FSType = getFSType(path)
|
|
|
|
return info, nil
|
|
|
|
}
|