statvfs_unix.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2019 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 freebsd || darwin
  15. package vfs
  16. import (
  17. "github.com/pkg/sftp"
  18. "golang.org/x/sys/unix"
  19. )
  20. func getStatFS(path string) (*sftp.StatVFS, error) {
  21. stat := unix.Statfs_t{}
  22. err := unix.Statfs(path, &stat)
  23. if err != nil {
  24. return nil, err
  25. }
  26. return &sftp.StatVFS{
  27. Bsize: uint64(stat.Bsize),
  28. Frsize: uint64(stat.Bsize),
  29. Blocks: stat.Blocks,
  30. Bfree: stat.Bfree,
  31. Bavail: uint64(stat.Bavail),
  32. Files: stat.Files,
  33. Ffree: uint64(stat.Ffree),
  34. Favail: uint64(stat.Ffree), // not sure how to calculate Favail
  35. Flag: uint64(stat.Flags),
  36. Namemax: 255, // we use a conservative value here
  37. }, nil
  38. }