ClementTsang/bottom · error

Could not get volume name for mount point

Error message

Could not get volume name for mount point: {err:?}

What it means

volume_name_from_mount calls GetVolumeNameForVolumeMountPointW to translate a mount point (e.g. C:\mount) into its \\?\Volume{guid}\ name, and bails if the API returns Err. The library cannot proceed to disk-usage collection without the canonical volume name. Failure means the mount point does not map to a resolvable volume.

Solutions

  1. Ensure the mount point string ends with a trailing backslash (e.g. "C:\\" not "C:")
  2. Verify the path is actually a mount point of a local volume via 'mountvol' before calling
  3. Skip paths that fail resolution (network shares, dangling junctions) in get_disk_usage
  4. Check the wrapped err's Win32 code — ERROR_ACCESS_DENIED vs ERROR_INVALID_NAME indicates privilege vs path-format problems

Example fix

// before
let result = unsafe {
    GetVolumeNameForVolumeMountPointW(windows::core::PCWSTR(mount.as_ptr()), &mut buffer)
};
// after
let mut mount = mount; // ensure trailing backslash
if !mount.ends_with('\\') {
    mount.push('\\');
}
let result = unsafe {
    GetVolumeNameForVolumeMountPointW(windows::core::PCWSTR(mount.as_ptr()), &mut buffer)
};
Defensive patterns

Strategy: validation

Validate before calling

// ensure mount point ends with a backslash and looks like a local mount
fn valid_mount_point(p: &str) -> bool {
    p.ends_with('\\') && !p.starts_with("\\\\")
}

Try / catch

match volume_name_from_mount(mp) {
    Ok(name) => name,
    Err(e) => { log::debug!("skipping mount {mp}: {e:?}"); continue; }
}

Prevention

When it happens

Trigger: GetVolumeNameForVolumeMountPointW fails — the mount point path is malformed (missing trailing backslash), the path is not a mounted volume/junction, the volume is offline, or access is denied.

Common situations: Passing a plain drive letter without a trailing backslash ("C:" instead of "C:\"); dangling junctions or mount points pointing at removed volumes; enumerating disk usage on network drives that have no volume GUID name.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of ClementTsang/bottom@b77d317502 (2026-09-07). Data as JSON: /api/errors/6f4e7d5756db134e. Report an issue: GitHub.

Appendix: source

Thrown at src/collection/disks/windows/bindings.rs:176

    let mount = {
        let mount_path = Path::new(mount);
        let mut wide_path = mount_path.as_os_str().encode_wide().collect::<Vec<_>>();

        // Always push on a \0 character, without this it will occasionally
        // break.
        wide_path.push(0x0000);

        wide_path
    };
    let mut buffer = [0_u16; VOLUME_MAX_LEN];

    // SAFETY: API call, we must check the result for validating safety.
    let result = unsafe {
        GetVolumeNameForVolumeMountPointW(windows::core::PCWSTR(mount.as_ptr()), &mut buffer)
    };

    if let Err(err) = result {
        bail!("Could not get volume name for mount point: {err:?}");
    } else {
        Ok(current_volume(&buffer).to_string_lossy().to_string())
    }
}

View on GitHub (pinned to b77d317502)