{"record":{"id":"dd873aab34af0af8","repo":"ClementTsang/bottom","slug":"statvfs-failed-to-get-the-disk-usage-for-disk-pat","errorCode":null,"errorMessage":"statvfs failed to get the disk usage for disk {path:?}","messagePattern":"statvfs failed to get the disk usage for disk (.+?)","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/collection/disks/unix/other/partition.rs","lineNumber":45,"sourceCode":"    #[inline]\n    pub fn fs_type(&self) -> &FileSystem {\n        &self.fs_type\n    }\n\n    /// Returns the usage stats for this partition.\n    pub fn usage(&self) -> anyhow::Result<Usage> {\n        let path = CString::new(self.mount_point().as_os_str().as_bytes())?;\n        let mut vfs = std::mem::MaybeUninit::<libc::statvfs>::uninit();\n\n        // SAFETY: System API call. Arguments should be correct.\n        let result = unsafe { libc::statvfs(path.as_ptr(), vfs.as_mut_ptr()) };\n\n        if result == 0 {\n            // SAFETY: We check that it succeeded (result is 0), which means vfs\n            // should be populated.\n            Ok(Usage::new(unsafe { vfs.assume_init() }))\n        } else {\n            bail!(\"statvfs failed to get the disk usage for disk {path:?}\")\n        }\n    }\n\n    /// Returns the device name.\n    #[inline]\n    pub fn get_device_name(&self) -> String {\n        self.device.clone()\n    }\n}\n\nfn partitions_iter() -> anyhow::Result<impl Iterator<Item = Partition>> {\n    let mounts = bindings::mounts()?;\n\n    unsafe fn ptr_to_cow<'a>(ptr: *const i8) -> std::borrow::Cow<'a, str> {\n        unsafe { CStr::from_ptr(ptr).to_string_lossy() }\n    }\n\n    Ok(mounts.into_iter().map(|stat| {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/ClementTsang/bottom/blob/b77d3175028849824e987c35177e8f61450d72e7/src/collection/disks/unix/other/partition.rs#L27-L63","documentation":"Partition::usage on Unix platforms (the generic 'other' implementation) calls statvfs(3) on the mount path to compute free/total space. If statvfs returns non-zero, the call failed and the path plus errno context is reported in this error.","triggerScenarios":"Calling usage() on a partition whose mount point no longer exists, is not accessible, or where statvfs fails due to EACCES, ENOENT, ELOOP, or filesystem-specific errors.","commonSituations":"Mount points that disappeared (unmounted network shares, ejected drives), restricted permissions in containers, or stale mount entries in /proc/mounts.","solutions":["Check the partition's mount point still exists before calling usage() (std::path::Path::exists)","Verify the process has read/execute permission on the mount directory","Re-read the mount table to drop stale entries for unmounted filesystems","Handle per-partition failures gracefully instead of aborting the whole disk harvest"],"exampleFix":"// before\nlet usage = partition.usage()?;\n// after\nlet usage = match partition.usage() {\n    Ok(u) => Some(u),\n    Err(e) => { log::warn!(\"statvfs failed, skipping: {e}\"); None },\n};","handlingStrategy":"validation","validationCode":"// Check the mount point exists and is accessible before calling usage\nuse std::os::unix::fs::MetadataExt;\nlet usable = path.exists() && std::fs::metadata(&path).map(|m| m.dev() != 0).unwrap_or(false);","typeGuard":null,"tryCatchPattern":"match partition.usage() {\n    Ok(u) => Some(u),\n    Err(e) if e.to_string().starts_with(\"statvfs failed\") => {\n        log::warn!(\"unmountable/stale mount: {e}\"); None\n    },\n    Err(e) => return Err(e),\n}","preventionTips":["Re-read the mount table each cycle to drop stale entries","Skip partitions whose mount point no longer exists","Watch for network mounts (NFS/SMB) that unmount frequently","Never let one partition failure abort the whole disk harvest"],"tags":["unix","statvfs","disks","syscall"],"backgroundTag":"file-read-failed","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"}