statvfs_unix.go 655 B

1234567891011121314151617181920212223242526272829
  1. //go:build freebsd || darwin
  2. // +build freebsd darwin
  3. package vfs
  4. import (
  5. "github.com/pkg/sftp"
  6. "golang.org/x/sys/unix"
  7. )
  8. func getStatFS(path string) (*sftp.StatVFS, error) {
  9. stat := unix.Statfs_t{}
  10. err := unix.Statfs(path, &stat)
  11. if err != nil {
  12. return nil, err
  13. }
  14. return &sftp.StatVFS{
  15. Bsize: uint64(stat.Bsize),
  16. Frsize: uint64(stat.Bsize),
  17. Blocks: stat.Blocks,
  18. Bfree: stat.Bfree,
  19. Bavail: uint64(stat.Bavail),
  20. Files: stat.Files,
  21. Ffree: uint64(stat.Ffree),
  22. Favail: uint64(stat.Ffree), // not sure how to calculate Favail
  23. Flag: uint64(stat.Flags),
  24. Namemax: 255, // we use a conservative value here
  25. }, nil
  26. }