mirror of
https://github.com/minio/minio.git
synced 2024-12-26 15:15:55 -05:00
a8a935f5fd
``` StatFS { Total int64 Free int64 FSType string } ``` Provides more information in a cross platform way.
59 lines
2.2 KiB
Go
59 lines
2.2 KiB
Go
// +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"
|
|
)
|
|
|
|
// Stat 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 Stat(path string) (statfs StatFS, 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)))
|
|
statfs = StatFS{}
|
|
statfs.Total = int64(lpTotalNumberOfBytes)
|
|
statfs.Free = int64(lpFreeBytesAvailable)
|
|
statfs.FSType = getFSType(path)
|
|
return statfs, nil
|
|
}
|