btrfs_cli/filesystem/
df.rs1use super::UnitMode;
2use crate::{
3 Format, Runnable,
4 util::{fmt_size, open_path},
5};
6use anyhow::{Context, Result};
7use btrfs_uapi::space::space_info;
8use clap::Parser;
9use std::{os::unix::io::AsFd, path::PathBuf};
10
11#[derive(Parser, Debug)]
13pub struct FilesystemDfCommand {
14 #[clap(flatten)]
15 pub units: UnitMode,
16
17 pub path: PathBuf,
18}
19
20impl Runnable for FilesystemDfCommand {
21 fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
22 let mode = self.units.resolve();
23 let file = open_path(&self.path)?;
24 let entries = space_info(file.as_fd()).with_context(|| {
25 format!("failed to get space info for '{}'", self.path.display())
26 })?;
27
28 for entry in &entries {
29 println!(
30 "{}: total={}, used={}",
31 entry.flags,
32 fmt_size(entry.total_bytes, &mode),
33 fmt_size(entry.used_bytes, &mode),
34 );
35 }
36
37 Ok(())
38 }
39}