statfs.go 531 B

1234567891011121314151617181920212223
  1. package internal
  2. import (
  3. "unsafe"
  4. "github.com/cilium/ebpf/internal/unix"
  5. )
  6. func FSType(path string) (int64, error) {
  7. var statfs unix.Statfs_t
  8. if err := unix.Statfs(path, &statfs); err != nil {
  9. return 0, err
  10. }
  11. fsType := int64(statfs.Type)
  12. if unsafe.Sizeof(statfs.Type) == 4 {
  13. // We're on a 32 bit arch, where statfs.Type is int32. bpfFSType is a
  14. // negative number when interpreted as int32 so we need to cast via
  15. // uint32 to avoid sign extension.
  16. fsType = int64(uint32(statfs.Type))
  17. }
  18. return fsType, nil
  19. }