statvfs_fallback.go 782 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //go:build !darwin && !linux && !freebsd
  2. // +build !darwin,!linux,!freebsd
  3. package vfs
  4. import (
  5. "github.com/pkg/sftp"
  6. "github.com/shirou/gopsutil/v3/disk"
  7. )
  8. const bsize = uint64(4096)
  9. func getStatFS(path string) (*sftp.StatVFS, error) {
  10. usage, err := disk.Usage(path)
  11. if err != nil {
  12. return nil, err
  13. }
  14. // we assume block size = 4096
  15. blocks := usage.Total / bsize
  16. bfree := usage.Free / bsize
  17. files := usage.InodesTotal
  18. ffree := usage.InodesFree
  19. if files == 0 {
  20. // these assumptions are wrong but still better than returning 0
  21. files = blocks / 4
  22. ffree = bfree / 4
  23. }
  24. return &sftp.StatVFS{
  25. Bsize: bsize,
  26. Frsize: bsize,
  27. Blocks: blocks,
  28. Bfree: bfree,
  29. Bavail: bfree,
  30. Files: files,
  31. Ffree: ffree,
  32. Favail: ffree,
  33. Namemax: 255,
  34. }, nil
  35. }