use crate::{RunContext, Runnable, util::open_path};
use anyhow::{Context, Result};
use clap::Parser;
use std::{os::unix::io::AsFd, path::PathBuf};
#[derive(Parser, Debug)]
pub struct RootidCommand {
path: PathBuf,
}
impl Runnable for RootidCommand {
fn run(&self, _ctx: &RunContext) -> Result<()> {
let file = open_path(&self.path)?;
let fd = file.as_fd();
let rootid = btrfs_uapi::inode::lookup_path_rootid(fd).context(
"failed to look up root ID (is this a btrfs filesystem?)",
)?;
println!("{rootid}");
Ok(())
}
}