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