Crate blkpath

Crate blkpath 

Source
Expand description

§blkpath

A Rust crate for resolving the underlying block device path from a file path or file descriptor.

§Overview

This crate provides a reliable way to determine which block device underlies a given file or directory. It uses a multi-step resolution strategy:

  1. First, it uses the stat system call to get the device ID (major:minor numbers)
  2. Then, it looks up the device path via /sys/dev/block/{major}:{minor}
  3. If that fails, it falls back to parsing /proc/self/mountinfo

§Usage

use blkpath::ResolveDevice;
use std::path::Path;

let path = Path::new("/home");
match path.resolve_device() {
    Ok(device_path) => println!("Device: {}", device_path.display()),
    Err(e) => eprintln!("Error: {}", e),
}

You can also use it with file descriptors:

use blkpath::ResolveDevice;
use std::fs::File;

let file = File::open("/home").unwrap();
match file.resolve_device() {
    Ok(device_path) => println!("Device: {}", device_path.display()),
    Err(e) => eprintln!("Error: {}", e),
}

Traits§

ResolveDevice
A trait for resolving the underlying block device of a file or path.

Functions§

resolve_device
Convenience function to resolve the device for a path.
resolve_device_from_file
Convenience function to resolve the device from a file descriptor.