| Crates.io | blkmap |
| lib.rs | blkmap |
| version | 0.1.0 |
| created_at | 2026-01-16 05:33:00.60857+00 |
| updated_at | 2026-01-16 05:33:00.60857+00 |
| description | Query file physical extents (FIEMAP) for a given range on disk |
| homepage | |
| repository | https://github.com/SF-Zhou/blkmap |
| max_upload_size | |
| id | 2047948 |
| size | 48,645 |
Query file physical extents (FIEMAP) for a given range on disk.
This crate provides a Rust interface to the Linux FIEMAP ioctl, which allows querying the physical block mapping of files on disk. It works on both x86 and ARM Linux platforms.
Add this to your Cargo.toml:
[dependencies]
blkmap = "0.1"
Or install the CLI tool:
cargo install blkmap
use blkmap::Fiemap;
use std::fs::File;
let file = File::open("/path/to/file")?;
let extents = file.fiemap()?;
for extent in extents {
println!("Logical: {:#x}, Physical: {:#x}, Length: {:#x}",
extent.logical, extent.physical, extent.length);
println!("Flags: {:?}", extent.flags);
}
use blkmap::Fiemap;
use std::fs::File;
let file = File::open("/path/to/file")?;
// Query extents for bytes 0-4096
let extents = file.fiemap_range(0, 4096)?;
The Fiemap trait is also implemented for path types:
use blkmap::Fiemap;
use std::path::Path;
// Using a Path
let extents = Path::new("/path/to/file").fiemap()?;
// Using a PathBuf
let path = std::path::PathBuf::from("/path/to/file");
let extents = path.fiemap()?;
use blkmap::{Fiemap, ExtentFlags};
use std::fs::File;
let file = File::open("/path/to/file")?;
let extents = file.fiemap()?;
for extent in extents {
if extent.flags.is_shared() {
println!("Extent is shared (reflinked/deduplicated)");
}
if extent.flags.is_unwritten() {
println!("Extent is preallocated but not yet written");
}
if extent.is_last() {
println!("This is the last extent in the file");
}
}
# Query all extents for a file
blkmap /path/to/file
# Query extents starting from offset 1024
blkmap /path/to/file --offset 1024
# Query extents for a specific range
blkmap /path/to/file --offset 0 --length 4096
# Short options
blkmap /path/to/file -o 1024 -l 8192
Example output:
Index Logical Physical Length Flags
--------------------------------------------------------------------------------
0 0x0000000000000000 0x00000000c8a01000 0x0000000000001000 LAST
--------------------------------------------------------------------------------
Total: 1 extent(s)
The following extent flags are supported:
| Flag | Description |
|---|---|
LAST |
This is the last extent in the file |
UNKNOWN |
Extent location is not yet known |
DELALLOC |
Delayed allocation (not yet written to disk) |
ENCODED |
Data is compressed/encoded |
DATA_ENCRYPTED |
Data is encrypted |
NOT_ALIGNED |
Extent offsets not aligned to block boundary |
DATA_INLINE |
Data stored inline in metadata |
DATA_TAIL |
Data is tail-packed with other files |
UNWRITTEN |
Extent is allocated but not yet written |
MERGED |
Extent merged from multiple underlying extents |
SHARED |
Extent is shared with other files (reflink) |
This crate only works on Linux systems. It has been tested on:
Licensed under either of
at your option.
Contributions are welcome! Please feel free to submit a Pull Request.