statvfs_linux.go 1.2 KB

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