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)
16 .with_context(|| format!("failed to open '{}'", self.path.display()))?;
17 let fd = file.as_fd();
18
19 let rootid = btrfs_uapi::inode::lookup_path_rootid(fd)
20 .context("failed to look up root ID (is this a btrfs filesystem?)")?;
21
22 println!("{}", rootid);
23 Ok(())
24 }
25}