containerd/vendor/github.com/Microsoft/go-winio/pkg/fs/fs_windows.go
Daniel Canter acb2964d65 go.mod: Bump go-winio to v0.6.0
Some minor improvements, but biggest for here is ErrPipeListenerClosed
is no longer an errors.New where the string matches the text of the now
exported net.ErrClosed in the stdlib, but is just assigned to net.ErrClosed
directly. This should allow us to get rid of the string check for "use of closed
network connection" here now..

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
2022-09-28 10:30:38 -07:00

32 lines
871 B
Go

package fs
import (
"errors"
"path/filepath"
"golang.org/x/sys/windows"
)
var (
// ErrInvalidPath is returned when the location of a file path doesn't begin with a driver letter.
ErrInvalidPath = errors.New("the path provided to GetFileSystemType must start with a drive letter")
)
// GetFileSystemType obtains the type of a file system through GetVolumeInformation.
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx
func GetFileSystemType(path string) (fsType string, err error) {
drive := filepath.VolumeName(path)
if len(drive) != 2 {
return "", ErrInvalidPath
}
var (
buf = make([]uint16, 255)
size = uint32(windows.MAX_PATH + 1)
)
drive += `\`
err = windows.GetVolumeInformation(windows.StringToUTF16Ptr(drive), nil, 0, nil, nil, nil, &buf[0], size)
fsType = windows.UTF16ToString(buf)
return fsType, err
}