btrfs_cli/inspect/
rootid.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 RootidCommand {
9 path: PathBuf,
11}
12
13impl Runnable for RootidCommand {
14 fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
15 let file = File::open(&self.path).with_context(|| {
16 format!("failed to open '{}'", self.path.display())
17 })?;
18 let fd = file.as_fd();
19
20 let rootid = btrfs_uapi::inode::lookup_path_rootid(fd).context(
21 "failed to look up root ID (is this a btrfs filesystem?)",
22 )?;
23
24 println!("{}", rootid);
25 Ok(())
26 }
27}