...

Source file src/github.com/Microsoft/go-winio/pkg/fs/fs_windows.go

Documentation: github.com/Microsoft/go-winio/pkg/fs

     1  package fs
     2  
     3  import (
     4  	"errors"
     5  	"path/filepath"
     6  
     7  	"golang.org/x/sys/windows"
     8  
     9  	"github.com/Microsoft/go-winio/internal/stringbuffer"
    10  )
    11  
    12  var (
    13  	// ErrInvalidPath is returned when the location of a file path doesn't begin with a driver letter.
    14  	ErrInvalidPath = errors.New("the path provided to GetFileSystemType must start with a drive letter")
    15  )
    16  
    17  // GetFileSystemType obtains the type of a file system through GetVolumeInformation.
    18  //
    19  // https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationw
    20  func GetFileSystemType(path string) (fsType string, err error) {
    21  	drive := filepath.VolumeName(path)
    22  	if len(drive) != 2 {
    23  		return "", ErrInvalidPath
    24  	}
    25  
    26  	buf := stringbuffer.NewWString()
    27  	defer buf.Free()
    28  
    29  	drive += `\`
    30  	err = windows.GetVolumeInformation(windows.StringToUTF16Ptr(drive), nil, 0, nil, nil, nil, buf.Pointer(), buf.Cap())
    31  	return buf.String(), err
    32  }
    33  

View as plain text