containerd/vendor/github.com/Microsoft/go-winio/pkg/fs/fs_windows.go
Kirtana Ashok 56d80f81a2 Update hcsshim tag to v0.10.0-rc.9
Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
2023-07-17 10:28:47 -07:00

33 lines
899 B
Go

package fs
import (
"errors"
"path/filepath"
"golang.org/x/sys/windows"
"github.com/Microsoft/go-winio/internal/stringbuffer"
)
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://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationw
func GetFileSystemType(path string) (fsType string, err error) {
drive := filepath.VolumeName(path)
if len(drive) != 2 {
return "", ErrInvalidPath
}
buf := stringbuffer.NewWString()
defer buf.Free()
drive += `\`
err = windows.GetVolumeInformation(windows.StringToUTF16Ptr(drive), nil, 0, nil, nil, nil, buf.Pointer(), buf.Cap())
return buf.String(), err
}