statvfs_fallback.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2019-2023 Nicola Murino
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Affero General Public License as published
  5. // by the Free Software Foundation, version 3.
  6. //
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU Affero General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU Affero General Public License
  13. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. //go:build !darwin && !linux && !freebsd
  15. // +build !darwin,!linux,!freebsd
  16. package vfs
  17. import (
  18. "github.com/pkg/sftp"
  19. "github.com/shirou/gopsutil/v3/disk"
  20. )
  21. const bsize = uint64(4096)
  22. func getStatFS(path string) (*sftp.StatVFS, error) {
  23. usage, err := disk.Usage(path)
  24. if err != nil {
  25. return nil, err
  26. }
  27. // we assume block size = 4096
  28. blocks := usage.Total / bsize
  29. bfree := usage.Free / bsize
  30. files := usage.InodesTotal
  31. ffree := usage.InodesFree
  32. if files == 0 {
  33. // these assumptions are wrong but still better than returning 0
  34. files = blocks / 4
  35. ffree = bfree / 4
  36. }
  37. return &sftp.StatVFS{
  38. Bsize: bsize,
  39. Frsize: bsize,
  40. Blocks: blocks,
  41. Bfree: bfree,
  42. Bavail: bfree,
  43. Files: files,
  44. Ffree: ffree,
  45. Favail: ffree,
  46. Namemax: 255,
  47. }, nil
  48. }