{"record":{"id":"631dca68dddadc2e","repo":"ClementTsang/bottom","slug":"statvfs-had-an-issue-getting-info-from-path","errorCode":null,"errorMessage":"statvfs had an issue getting info from {path:?}","messagePattern":"statvfs had an issue getting info from (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/collection/disks/unix/linux/partition.rs","lineNumber":100,"sourceCode":"            .to_str()\n            .ok_or_else(|| io::Error::from(io::ErrorKind::InvalidInput))\n            .and_then(|string| {\n                CString::new(string).map_err(|_| io::Error::from(io::ErrorKind::InvalidInput))\n            })\n            .map_err(|e| anyhow::anyhow!(\"invalid path: {e:?}\"))?;\n\n        let mut vfs = mem::MaybeUninit::<libc::statvfs>::uninit();\n\n        // SAFETY: libc call, `path` is a valid C string and buf is a valid\n        // pointer to write to.\n        let result = unsafe { libc::statvfs(path.as_ptr(), vfs.as_mut_ptr()) };\n\n        if result == 0 {\n            // SAFETY: If result is 0, it succeeded, and vfs should be non-null.\n            let vfs = unsafe { vfs.assume_init() };\n            Ok(Usage::new(vfs))\n        } else {\n            Err(anyhow::anyhow!(\n                \"statvfs had an issue getting info from {path:?}\"\n            ))\n        }\n    }\n}\n\nfn fix_mount_point(s: &str) -> String {\n    const ESCAPED_BACKSLASH: &str = \"\\\\134\";\n    const ESCAPED_SPACE: &str = \"\\\\040\";\n    const ESCAPED_TAB: &str = \"\\\\011\";\n    const ESCAPED_NEWLINE: &str = \"\\\\012\";\n\n    s.replace(ESCAPED_BACKSLASH, \"\\\\\")\n        .replace(ESCAPED_SPACE, \" \")\n        .replace(ESCAPED_TAB, \"\\t\")\n        .replace(ESCAPED_NEWLINE, \"\\n\")\n}\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/ClementTsang/bottom/blob/b77d3175028849824e987c35177e8f61450d72e7/src/collection/disks/unix/linux/partition.rs#L82-L118","documentation":"Raised in the public `usage()` of a Linux disk partition when the `libc::statvfs` call returns non-zero, meaning the kernel refused to return filesystem statistics for the given mount-point path. The library has already validated the path as a CString, so the failure comes from statvfs itself — typically the path does not exist or is inaccessible (errno EACCES, ENOENT, etc.).","triggerScenarios":"`usage()` called on a mount point that was unmounted between enumeration and the statvfs call; a path the process lacks search permission for; statvfs failing for any OS reason (result != 0).","commonSituations":"Race with `umount` while iterating mounted filesystems; restricted environments (containers, sandboxed processes) where the mount point is not visible; autofs mount points that fail on access.","solutions":["Retry `usage()` — if the mount was being unmounted concurrently, re-enumerate partitions first","Check the mount point still exists and is accessible (`ls`/`stat` it) and that the process has permission to traverse it","Check `errno`/`last_os_error()` right after the failure for the precise reason (ENOENT vs EACCES)","Skip the affected partition if it is transient (e.g. automounted media)"],"exampleFix":"// before\nlet usage = partition.usage()?;\n// after\nlet usage = match partition.usage() {\n    Ok(u) => u,\n    Err(e) if e.to_string().starts_with(\"statvfs had an issue\") => {\n        eprintln!(\"partition vanished, skipping: {e}\");\n        continue;\n    },\n    Err(e) => return Err(e),\n};","handlingStrategy":"retry","validationCode":"// Verify the mount point is accessible before calling statvfs-backed usage()\nlet mp = partition.mount_point();\nif !mp.exists() {\n    eprintln!(\"mount point {mp:?} is gone; skipping\");\n} else {\n    let usage = partition.usage()?;\n}","typeGuard":null,"tryCatchPattern":"match partition.usage() {\n    Ok(u) => handle(u),\n    Err(e) if e.to_string().contains(\"statvfs had an issue\") => {\n        eprintln!(\"transient statvfs failure, re-enumerating mounts: {e}\");\n        // re-enumerate partitions and retry once\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Retry once and re-enumerate mounts before failing — mounts can disappear mid-scan","Check the mount point exists and is traversable before calling usage()","Handle autofs/removable media partitions as optional","Capture the OS errno via last_os_error() after failures to distinguish ENOENT from EACCES"],"tags":["linux","disks","filesystem","statvfs","io"],"backgroundTag":"file-not-found","analyzedSha":"b77d3175028849824e987c35177e8f61450d72e7","analyzedAt":"2026-09-07T14:53:21.246Z","contentChangedAt":"2026-09-07T14:53:21.246Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}