github.com/bigcommerce/nomad@v0.9.3-bc/client/fingerprint/storage_windows.go (about) 1 package fingerprint 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "syscall" 7 ) 8 9 //go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zstorage_windows.go storage_windows.go 10 11 //sys getDiskFreeSpaceEx(dirName *uint16, availableFreeBytes *uint64, totalBytes *uint64, totalFreeBytes *uint64) (err error) = kernel32.GetDiskFreeSpaceExW 12 13 // diskFree inspects the filesystem for path and returns the volume name and 14 // the total and free bytes available on the file system. 15 func (f *StorageFingerprint) diskFree(path string) (volume string, total, free uint64, err error) { 16 absPath, err := filepath.Abs(path) 17 if err != nil { 18 return "", 0, 0, fmt.Errorf("failed to determine absolute path for %s", path) 19 } 20 21 volume = filepath.VolumeName(absPath) 22 23 absPathp, err := syscall.UTF16PtrFromString(absPath) 24 if err != nil { 25 return "", 0, 0, fmt.Errorf("failed to convert \"%s\" to UTF16: %v", absPath, err) 26 } 27 28 if err := getDiskFreeSpaceEx(absPathp, nil, &total, &free); err != nil { 29 return "", 0, 0, fmt.Errorf("failed to get free disk space for %s: %v", absPath, err) 30 } 31 32 return volume, total, free, nil 33 }