mirror of
https://github.com/moby/moby.git
synced 2026-08-05 07:30:57 +00:00
daemon/graphdriver/windows: use go-winio.GetFileSystemType()
go-winio now defines this function, so we can consume that. Note that there's a difference between the old implementation and the original one (added in1cb9e9b44e). The old implementation had special handling for win32 error codes, which was removed in the go-winio implementation in0966e1ad56As `go-winio.GetFileSystemType()` calls `filepath.VolumeName(path)` internally, this patch also removes the `string(home[0])`, which is redundant, and could potentially panic if an empty string would be passed. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
31
vendor/github.com/Microsoft/go-winio/pkg/fs/fs_windows.go
generated
vendored
Normal file
31
vendor/github.com/Microsoft/go-winio/pkg/fs/fs_windows.go
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user