btrfs_cli/filesystem/
df.rs1use crate::{Format, Runnable, util::human_bytes};
2use anyhow::{Context, Result};
3use btrfs_uapi::space::space_info;
4use clap::Parser;
5use std::{fs::File, os::unix::io::AsFd, path::PathBuf};
6
7#[derive(Parser, Debug)]
9pub struct FilesystemDfCommand {
10 pub path: PathBuf,
11}
12
13impl Runnable for FilesystemDfCommand {
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 entries = space_info(file.as_fd()).with_context(|| {
19 format!("failed to get space info for '{}'", self.path.display())
20 })?;
21
22 for entry in &entries {
23 println!(
24 "{}: total={}, used={}",
25 entry.flags,
26 human_bytes(entry.total_bytes),
27 human_bytes(entry.used_bytes),
28 );
29 }
30
31 Ok(())
32 }
33}