pub fn run(overlay: PathBuf, blocks: bool, files: bool) -> Result<()>Expand description
Executes the diff command to analyze overlay modifications.
Reads the overlay metadata file (.meta) to determine which blocks have been
modified, then displays statistics about the changes. The metadata file contains
a sorted array of 64-bit block indices that were written during overlay operation.
§Arguments
overlay- Path to the overlay file (e.g.,vm-state.overlay)blocks- If true, display block-level statistics with human-readable sizesfiles- If true, display individual modified block indices (file mapping not implemented)
§Output Format
Blocks Mode:
--- Overlay Statistics ---
Modified Blocks: 5120
Total Changed Data: 20.0 MBFiles Mode:
--- Modified Files (Heuristic) ---
File resolution is not yet implemented. Use --blocks for raw stats.
Modified Block Indices:
Block 128
Block 129
Block 256
...Default Mode:
Overlay: "vm-state.overlay"
Modified Blocks: 5120
Estimated Size: 20.0 MB§File-Level Resolution (Future Enhancement)
To map block indices to files, the implementation would need to:
- Read the base image partition table (MBR/GPT)
- Identify the filesystem type (ext4, xfs, ntfs, etc.)
- Parse the filesystem metadata (superblock, inode tables)
- Map block indices to inode numbers
- Resolve inode paths from directory entries
This requires filesystem-specific parsers and is left for future work.
§Errors
Returns an error if:
- The overlay file does not exist (note: metadata file absence is not an error)
- The metadata file cannot be opened or read
- I/O errors occur while reading block indices
Note: If the metadata file does not exist, the command prints a message and returns successfully (interpreted as zero modifications).
§Examples
use std::path::PathBuf;
use hexz_cli::cmd::data::diff;
// Show summary of overlay changes
diff::run(PathBuf::from("vm-state.overlay"), false, false)?;
// Display detailed statistics
diff::run(PathBuf::from("vm-state.overlay"), true, false)?;
// List all modified block indices
diff::run(PathBuf::from("vm-state.overlay"), false, true)?;