btrfs_cli/inspect/
inode_resolve.rs1use crate::{Format, Runnable};
2use anyhow::{Context, Result};
3use clap::Parser;
4use std::{fs::File, os::unix::io::AsFd, path::PathBuf};
5
6#[derive(Parser, Debug)]
8pub struct InodeResolveCommand {
9 inode: u64,
11
12 path: PathBuf,
14}
15
16impl Runnable for InodeResolveCommand {
17 fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
18 let file = File::open(&self.path).with_context(|| {
19 format!("failed to open '{}'", self.path.display())
20 })?;
21 let fd = file.as_fd();
22
23 let paths = btrfs_uapi::inode::ino_paths(fd, self.inode).context(
24 "failed to look up inode paths (is this a btrfs filesystem?)",
25 )?;
26
27 if paths.is_empty() {
28 eprintln!("no paths found for inode {}", self.inode);
29 } else {
30 for path in paths {
31 println!("{}", path);
32 }
33 }
34
35 Ok(())
36 }
37}