whichdisk 0.1.0

Cross-platform disk/volume resolver — given a path, tells you which disk it's on, its mount point, and the relative path
Documentation

Cross-platform disk/volume resolver — given a path, tells you which disk it's on, its mount point, and the relative path

Installation

As a library

[dependencies]
whichdisk = "0.1"

As a CLI tool

cargo install whichdisk --features cli

CLI Usage

# Resolve the current working directory
whichdisk

# Resolve a specific path
whichdisk -p /home/user/documents

# Output as JSON
whichdisk -o json

# Output as YAML
whichdisk -o yaml

# Combine options
whichdisk -p /tmp -o json

Default output:

device="/dev/disk3s5"
mount_point="/System/Volumes/Data"
relative_path="Users/user/Develop/personal/whichdisk"

JSON output (-o json):

{
  "device": "/dev/disk3s5",
  "mount_point": "/System/Volumes/Data",
  "relative_path": "Users/user/Develop/personal/whichdisk"
}

YAML output (-o yaml):

device: /dev/disk3s5
mount_point: /System/Volumes/Data
relative_path: Users/user/Develop/personal/whichdisk

Library Example

use whichdisk::which_disk;

fn main() -> std::io::Result<()> {
    let info = which_disk("/home/user/documents/report.pdf")?;

    println!("Mount point:    {}", info.mount_point().display());
    println!("Device:         {:?}", info.device());
    println!("Relative path:  {}", info.relative_path().display());

    // On Linux, this might print:
    //   Mount point:    /home
    //   Device:         "/dev/sda2"
    //   Relative path:  user/documents/report.pdf

    // On macOS:
    //   Mount point:    /System/Volumes/Data
    //   Device:         "/dev/disk3s5"
    //   Relative path:  Users/user/documents/report.pdf

    // On Windows:
    //   Mount point:    C:\
    //   Device:         "\\?\Volume{GUID}\"
    //   Relative path:  Users\user\documents\report.pdf

    Ok(())
}

Supported Platforms

Platform Backend
macOS, iOS, watchOS, tvOS, visionOS statfs via rustix
FreeBSD, OpenBSD, DragonFlyBSD statfs via rustix
Linux /proc/self/mountinfo parsing
Windows GetVolumePathNameW / GetVolumeNameForVolumeMountPointW via windows-sys

Performance

  • Thread-local cache — repeated lookups for paths on the same device skip the underlying syscall/file read entirely
  • Small-buffer optimization — mount points and device names (typically < 56 bytes) are stored inline on the stack; longer values use reference-counted bytes::Bytes (clone is a pointer copy)
  • SIMD-accelerated scanning — uses memchr for null-terminator and newline searches in the BSD statfs buffers and Linux mountinfo parsing

MSRV

The minimum supported Rust version is 1.85.

License

whichdisk is under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE, LICENSE-MIT for details.

Copyright (c) 2026 Al Liu.