From 27559d6636f794c5bc50aa62485d455cddaaee7a Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 27 Aug 2024 12:41:53 +0200 Subject: [PATCH] implement GetFSType on openbsd with the correct statfs struct member (#3191) --- pkg/types/getfstype.go | 2 +- pkg/types/getfstype_openbsd.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 pkg/types/getfstype_openbsd.go diff --git a/pkg/types/getfstype.go b/pkg/types/getfstype.go index c16eea5cf98..728e986bed0 100644 --- a/pkg/types/getfstype.go +++ b/pkg/types/getfstype.go @@ -1,4 +1,4 @@ -//go:build !windows && !freebsd +//go:build !windows && !freebsd && !openbsd package types diff --git a/pkg/types/getfstype_openbsd.go b/pkg/types/getfstype_openbsd.go new file mode 100644 index 00000000000..9ec254b7bec --- /dev/null +++ b/pkg/types/getfstype_openbsd.go @@ -0,0 +1,25 @@ +//go:build openbsd + +package types + +import ( + "fmt" + "syscall" +) + +func GetFSType(path string) (string, error) { + var fsStat syscall.Statfs_t + + if err := syscall.Statfs(path, &fsStat); err != nil { + return "", fmt.Errorf("failed to get filesystem type: %w", err) + } + + bs := fsStat.F_fstypename + + b := make([]byte, len(bs)) + for i, v := range bs { + b[i] = byte(v) + } + + return string(b), nil +}