github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/internal/statfs.go (about)

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