github.com/crowdsecurity/crowdsec@v1.6.1/pkg/types/getfstype_windows.go (about) 1 package types 2 3 import ( 4 "path/filepath" 5 "syscall" 6 "unsafe" 7 ) 8 9 func GetFSType(path string) (string, error) { 10 kernel32, err := syscall.LoadLibrary("kernel32.dll") 11 if err != nil { 12 return "", err 13 } 14 defer syscall.FreeLibrary(kernel32) 15 16 getVolumeInformation, err := syscall.GetProcAddress(kernel32, "GetVolumeInformationW") 17 if err != nil { 18 return "", err 19 } 20 21 // Convert relative path to absolute path 22 absPath, err := filepath.Abs(path) 23 if err != nil { 24 return "", err 25 } 26 27 // Get the root path of the volume 28 volumeRoot := filepath.VolumeName(absPath) + "\\" 29 30 volumeRootPtr, _ := syscall.UTF16PtrFromString(volumeRoot) 31 32 var ( 33 fileSystemNameBuffer = make([]uint16, 260) 34 nFileSystemNameSize = uint32(len(fileSystemNameBuffer)) 35 ) 36 37 ret, _, err := syscall.SyscallN(getVolumeInformation, 38 uintptr(unsafe.Pointer(volumeRootPtr)), 39 0, 40 0, 41 0, 42 0, 43 0, 44 uintptr(unsafe.Pointer(&fileSystemNameBuffer[0])), 45 uintptr(nFileSystemNameSize), 46 0) 47 48 if ret == 0 { 49 return "", err 50 } 51 52 return syscall.UTF16ToString(fileSystemNameBuffer), nil 53 }