Skip to main content

btrfs_cli/
subvolume.rs

1use crate::{Format, Runnable};
2use anyhow::Result;
3use clap::Parser;
4
5mod create;
6mod delete;
7mod find_new;
8mod flags;
9mod get_default;
10mod list;
11mod set_default;
12mod show;
13mod snapshot;
14mod sync;
15
16pub use self::{
17    create::*, delete::*, find_new::*, flags::*, get_default::*, list::*,
18    set_default::*, show::*, snapshot::*, sync::*,
19};
20
21/// Create, delete, list, and manage btrfs subvolumes and snapshots.
22///
23/// Subvolumes are independent filesystem trees within a btrfs filesystem,
24/// allowing flexible storage organization, snapshots, and quota management.
25/// Snapshots are read-only or read-write copies of subvolumes at a point in time.
26/// Most operations require CAP_SYS_ADMIN.
27#[derive(Parser, Debug)]
28pub struct SubvolumeCommand {
29    #[clap(subcommand)]
30    pub subcommand: SubvolumeSubcommand,
31}
32
33impl Runnable for SubvolumeCommand {
34    fn run(&self, format: Format, dry_run: bool) -> Result<()> {
35        match &self.subcommand {
36            SubvolumeSubcommand::Create(cmd) => cmd.run(format, dry_run),
37            SubvolumeSubcommand::Delete(cmd) => cmd.run(format, dry_run),
38            SubvolumeSubcommand::Snapshot(cmd) => cmd.run(format, dry_run),
39            SubvolumeSubcommand::Show(cmd) => cmd.run(format, dry_run),
40            SubvolumeSubcommand::List(cmd) => cmd.run(format, dry_run),
41            SubvolumeSubcommand::GetDefault(cmd) => cmd.run(format, dry_run),
42            SubvolumeSubcommand::SetDefault(cmd) => cmd.run(format, dry_run),
43            SubvolumeSubcommand::GetFlags(cmd) => cmd.run(format, dry_run),
44            SubvolumeSubcommand::SetFlags(cmd) => cmd.run(format, dry_run),
45            SubvolumeSubcommand::FindNew(cmd) => cmd.run(format, dry_run),
46            SubvolumeSubcommand::Sync(cmd) => cmd.run(format, dry_run),
47        }
48    }
49}
50
51#[derive(Parser, Debug)]
52pub enum SubvolumeSubcommand {
53    Create(SubvolumeCreateCommand),
54    #[clap(alias = "del")]
55    Delete(SubvolumeDeleteCommand),
56    Snapshot(SubvolumeSnapshotCommand),
57    Show(SubvolumeShowCommand),
58    List(SubvolumeListCommand),
59    GetDefault(SubvolumeGetDefaultCommand),
60    SetDefault(SubvolumeSetDefaultCommand),
61    GetFlags(SubvolumeGetFlagsCommand),
62    SetFlags(SubvolumeSetFlagsCommand),
63    FindNew(SubvolumeFindNewCommand),
64    Sync(SubvolumeSyncCommand),
65}