statvfs_fallback.go 741 B

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