crowdsecurity/crowdsec · error
failed to get filesystem type: %w
Error message
failed to get filesystem type: %w
What it means
The FreeBSD build of GetFSType calls unix.Statfs on the path; any syscall failure (ENOENT, EACCES, ELOOP...) is wrapped as 'failed to get filesystem type'. The function never inspects the cause itself — the underlying error is preserved for the caller.
Source
Thrown at pkg/fsutil/getfstype_freebsd.go:15
//go:build freebsd
package fsutil
import (
"fmt"
"golang.org/x/sys/unix"
)
func GetFSType(path string) (string, error) {
var fsStat unix.Statfs_t
if err := unix.Statfs(path, &fsStat); err != nil {
return "", fmt.Errorf("failed to get filesystem type: %w", err)
}
return unix.ByteSliceToString(fsStat.Fstypename[:]), nil
}
View on GitHub (pinned to 909b515798)
Solutions
- Check the path exists (os.Stat) before calling GetFSType
- Read the wrapped errno after the colon to identify the syscall failure (ENOENT vs EACCES etc.)
- Verify the process has permission to stat the target path
- Re-run after fixing path/permissions; on FreeBSD no extra privileges are normally needed for statfs
Example fix
// before: unguarded call
fsType, err := fsutil.GetFSType(logPath)
// after: guard existence first
if _, err := os.Stat(logPath); err != nil {
return fmt.Errorf("path gone: %w", err)
}
fsType, err := fsutil.GetFSType(logPath) Defensive patterns
Strategy: try-catch
Validate before calling
if _, err := os.Stat(path); err != nil {
return fmt.Errorf("cannot stat %s: %w", path, err)
} Try / catch
fsType, err := fsutil.GetFSType(path)
if err != nil {
var perr *os.PathError
if errors.As(err, &perr) && errors.Is(perr.Err, syscall.ENOENT) {
return "", nil // file vanished (rotation); skip
}
return "", err
} Prevention
- Re-stat the path if files may be rotated/deleted concurrently
- Check path existence and permissions before probing mount types
- Unwrap the wrapped errno to distinguish ENOENT vs EACCES handling
- On FreeBSD, no elevated privileges are needed for statfs — investigate other causes first
When it happens
Trigger: Calling GetFSType(path) on FreeBSD where unix.Statfs fails: path doesn't exist, no permission on a parent directory, path too long, or filesystem unavailable.
Common situations: Checking mount types of log files that were deleted/rotated between listing and stat; probing paths on read-only or restricted mount points; running with insufficient privileges.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- unknown fstype %d
- unable to close %s : %s
- could not access CRL file: %w
- could not read CRL file: %w
- plugin at %s does not exist: %w
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/1da7d848243c7a38.
Report an issue: GitHub.