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:
- First, it uses the
statsystem call to get the device ID (major:minor numbers) - Then, it looks up the device path via
/sys/dev/block/{major}:{minor} - 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§
- Resolve
Device - 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.