Skip to main content

btrfs_cli/inspect/
subvolid_resolve.rs

1use crate::{Format, Runnable};
2use anyhow::{Context, Result};
3use clap::Parser;
4use std::{fs::File, os::unix::io::AsFd, path::PathBuf};
5
6/// Get subvolume ID and tree ID of the given path
7#[derive(Parser, Debug)]
8pub struct SubvolidResolveCommand {
9    /// Subvolume ID to resolve
10    subvolid: u64,
11
12    /// Path to a file or directory on the btrfs filesystem
13    path: PathBuf,
14}
15
16impl Runnable for SubvolidResolveCommand {
17    fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
18        let file = File::open(&self.path)
19            .with_context(|| format!("failed to open '{}'", self.path.display()))?;
20        let fd = file.as_fd();
21
22        let resolved_path = btrfs_uapi::inode::subvolid_resolve(fd, self.subvolid)
23            .context("failed to resolve subvolume ID (is this a btrfs filesystem?)")?;
24
25        println!("{}", resolved_path);
26        Ok(())
27    }
28}