Skip to main content

btrfs_cli/inspect/
rootid.rs

1use crate::{RunContext, Runnable, util::open_path};
2use anyhow::{Context, Result};
3use clap::Parser;
4use std::{os::unix::io::AsFd, path::PathBuf};
5
6/// Get tree ID of the containing subvolume of path
7#[derive(Parser, Debug)]
8pub struct RootidCommand {
9    /// Path to a file or directory on the btrfs filesystem
10    path: PathBuf,
11}
12
13impl Runnable for RootidCommand {
14    fn run(&self, _ctx: &RunContext) -> Result<()> {
15        let file = open_path(&self.path)?;
16        let fd = file.as_fd();
17
18        let rootid = btrfs_uapi::inode::lookup_path_rootid(fd).context(
19            "failed to look up root ID (is this a btrfs filesystem?)",
20        )?;
21
22        println!("{rootid}");
23        Ok(())
24    }
25}