{"record":{"id":"1da7d848243c7a38","repo":"crowdsecurity/crowdsec","slug":"failed-to-get-filesystem-type-w","errorCode":null,"errorMessage":"failed to get filesystem type: %w","messagePattern":"failed to get filesystem type: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/fsutil/getfstype_freebsd.go","lineNumber":15,"sourceCode":"//go:build freebsd\n\npackage fsutil\n\nimport (\n\t\"fmt\"\n\n\t\"golang.org/x/sys/unix\"\n)\n\nfunc GetFSType(path string) (string, error) {\n\tvar fsStat unix.Statfs_t\n\n\tif err := unix.Statfs(path, &fsStat); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get filesystem type: %w\", err)\n\t}\n\n\treturn unix.ByteSliceToString(fsStat.Fstypename[:]), nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/fsutil/getfstype_freebsd.go#L1-L20","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: unguarded call\nfsType, err := fsutil.GetFSType(logPath)\n// after: guard existence first\nif _, err := os.Stat(logPath); err != nil {\n    return fmt.Errorf(\"path gone: %w\", err)\n}\nfsType, err := fsutil.GetFSType(logPath)","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(path); err != nil {\n    return fmt.Errorf(\"cannot stat %s: %w\", path, err)\n}","typeGuard":null,"tryCatchPattern":"fsType, err := fsutil.GetFSType(path)\nif err != nil {\n    var perr *os.PathError\n    if errors.As(err, &perr) && errors.Is(perr.Err, syscall.ENOENT) {\n        return \"\", nil // file vanished (rotation); skip\n    }\n    return \"\", err\n}","preventionTips":["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"],"tags":["go","freebsd","filesystem","statfs"],"backgroundTag":"file-not-found","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}