Skip to main content

btrfs_cli/
filesystem.rs

1use crate::{Format, Runnable};
2use anyhow::Result;
3use clap::{Args, Parser};
4
5mod commit_stats;
6mod defrag;
7mod df;
8mod du;
9mod label;
10mod mkswapfile;
11mod resize;
12mod show;
13mod sync;
14mod usage;
15
16use commit_stats::FilesystemCommitStatsCommand;
17use defrag::FilesystemDefragCommand;
18use df::FilesystemDfCommand;
19use du::FilesystemDuCommand;
20use label::FilesystemLabelCommand;
21use mkswapfile::FilesystemMkswapfileCommand;
22use resize::FilesystemResizeCommand;
23use show::FilesystemShowCommand;
24use sync::FilesystemSyncCommand;
25use usage::FilesystemUsageCommand;
26
27/// Overall filesystem tasks and information.
28///
29/// Perform filesystem-level operations including checking available space,
30/// disk usage analysis, defragmentation, resizing, labeling, and
31/// synchronization. These commands provide views into filesystem state and
32/// allow configuration of filesystem-wide settings.
33#[derive(Parser, Debug)]
34pub struct FilesystemCommand {
35    #[clap(subcommand)]
36    pub subcommand: FilesystemSubcommand,
37}
38
39impl Runnable for FilesystemCommand {
40    fn run(&self, format: Format, dry_run: bool) -> Result<()> {
41        match &self.subcommand {
42            FilesystemSubcommand::Df(cmd) => cmd.run(format, dry_run),
43            FilesystemSubcommand::Du(cmd) => cmd.run(format, dry_run),
44            FilesystemSubcommand::Show(cmd) => cmd.run(format, dry_run),
45            FilesystemSubcommand::Sync(cmd) => cmd.run(format, dry_run),
46            FilesystemSubcommand::Defragment(cmd) => cmd.run(format, dry_run),
47            FilesystemSubcommand::Resize(cmd) => cmd.run(format, dry_run),
48            FilesystemSubcommand::Label(cmd) => cmd.run(format, dry_run),
49            FilesystemSubcommand::Usage(cmd) => cmd.run(format, dry_run),
50            FilesystemSubcommand::Mkswapfile(cmd) => cmd.run(format, dry_run),
51            FilesystemSubcommand::CommitStats(cmd) => cmd.run(format, dry_run),
52        }
53    }
54}
55
56#[derive(Parser, Debug)]
57pub enum FilesystemSubcommand {
58    Df(FilesystemDfCommand),
59    Du(FilesystemDuCommand),
60    Show(FilesystemShowCommand),
61    Sync(FilesystemSyncCommand),
62    #[clap(alias = "defrag")]
63    Defragment(FilesystemDefragCommand),
64    Resize(FilesystemResizeCommand),
65    Label(FilesystemLabelCommand),
66    Usage(FilesystemUsageCommand),
67    Mkswapfile(FilesystemMkswapfileCommand),
68    CommitStats(FilesystemCommitStatsCommand),
69}
70
71/// Unit display mode flags, shared by subcommands that output sizes.
72///
73/// Control how sizes are displayed in output. By default, human-readable
74/// format with base 1024 (KiB, MiB, GiB, TiB) is used. You can specify
75/// exact units or enable base 1000 (kB, MB, GB, TB) with --si.
76#[derive(Args, Debug)]
77pub struct UnitMode {
78    /// Show raw numbers in bytes
79    #[clap(long, overrides_with_all = ["human_readable", "iec", "si", "kbytes", "mbytes", "gbytes", "tbytes"])]
80    pub raw: bool,
81
82    /// Show human-friendly numbers using base 1024 (default)
83    #[clap(long, overrides_with_all = ["raw", "iec", "si", "kbytes", "mbytes", "gbytes", "tbytes"])]
84    pub human_readable: bool,
85
86    /// Use 1024 as a base (KiB, MiB, GiB, TiB)
87    #[clap(long, overrides_with_all = ["raw", "human_readable", "si", "kbytes", "mbytes", "gbytes", "tbytes"])]
88    pub iec: bool,
89
90    /// Use 1000 as a base (kB, MB, GB, TB)
91    #[clap(long, overrides_with_all = ["raw", "human_readable", "iec", "kbytes", "mbytes", "gbytes", "tbytes"])]
92    pub si: bool,
93
94    /// Show sizes in KiB, or kB with --si
95    #[clap(long, overrides_with_all = ["raw", "human_readable", "iec", "si", "mbytes", "gbytes", "tbytes"])]
96    pub kbytes: bool,
97
98    /// Show sizes in MiB, or MB with --si
99    #[clap(long, overrides_with_all = ["raw", "human_readable", "iec", "si", "kbytes", "gbytes", "tbytes"])]
100    pub mbytes: bool,
101
102    /// Show sizes in GiB, or GB with --si
103    #[clap(long, overrides_with_all = ["raw", "human_readable", "iec", "si", "kbytes", "mbytes", "tbytes"])]
104    pub gbytes: bool,
105
106    /// Show sizes in TiB, or TB with --si
107    #[clap(long, overrides_with_all = ["raw", "human_readable", "iec", "si", "kbytes", "mbytes", "gbytes"])]
108    pub tbytes: bool,
109}