btrfs_cli/inspect/
min_dev_size.rs1use crate::{
2 Format, Runnable,
3 util::{human_bytes, open_path},
4};
5use anyhow::{Context, Result};
6use clap::Parser;
7use std::{os::unix::io::AsFd, path::PathBuf};
8
9#[derive(Parser, Debug)]
15#[allow(clippy::doc_markdown)]
16pub struct MinDevSizeCommand {
17 #[arg(long = "id", default_value = "1")]
19 devid: u64,
20
21 path: PathBuf,
23}
24
25impl Runnable for MinDevSizeCommand {
26 fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
27 let file = open_path(&self.path)?;
28
29 let size = btrfs_uapi::device::device_min_size(
30 file.as_fd(),
31 self.devid,
32 )
33 .with_context(|| {
34 format!(
35 "failed to determine min device size for devid {} on '{}'",
36 self.devid,
37 self.path.display()
38 )
39 })?;
40
41 println!("{} bytes ({})", size, human_bytes(size));
42 Ok(())
43 }
44}