Skip to main content

btrfs_cli/
rescue.rs

1use crate::{Format, Runnable};
2use anyhow::Result;
3use clap::Parser;
4
5mod chunk_recover;
6mod clear_ino_cache;
7mod clear_space_cache;
8mod clear_uuid_tree;
9mod create_control_device;
10mod fix_data_checksum;
11mod fix_device_size;
12mod super_recover;
13mod zero_log;
14
15pub use self::{
16    chunk_recover::*, clear_ino_cache::*, clear_space_cache::*,
17    clear_uuid_tree::*, create_control_device::*, fix_data_checksum::*,
18    fix_device_size::*, super_recover::*, zero_log::*,
19};
20
21/// Toolbox for specific rescue operations.
22///
23/// Provide emergency recovery tools for damaged or unrecoverable filesystems.
24/// These operations are potentially dangerous and should only be used when
25/// the filesystem cannot be mounted or accessed through normal means.
26/// Most rescue operations require CAP_SYS_ADMIN and an unmounted filesystem.
27#[derive(Parser, Debug)]
28pub struct RescueCommand {
29    #[clap(subcommand)]
30    pub subcommand: RescueSubcommand,
31}
32
33impl Runnable for RescueCommand {
34    fn run(&self, format: Format, dry_run: bool) -> Result<()> {
35        match &self.subcommand {
36            RescueSubcommand::ChunkRecover(cmd) => cmd.run(format, dry_run),
37            RescueSubcommand::SuperRecover(cmd) => cmd.run(format, dry_run),
38            RescueSubcommand::ZeroLog(cmd) => cmd.run(format, dry_run),
39            RescueSubcommand::FixDeviceSize(cmd) => cmd.run(format, dry_run),
40            RescueSubcommand::FixDataChecksum(cmd) => cmd.run(format, dry_run),
41            RescueSubcommand::CreateControlDevice(cmd) => {
42                cmd.run(format, dry_run)
43            }
44            RescueSubcommand::ClearInoCache(cmd) => cmd.run(format, dry_run),
45            RescueSubcommand::ClearSpaceCache(cmd) => cmd.run(format, dry_run),
46            RescueSubcommand::ClearUuidTree(cmd) => cmd.run(format, dry_run),
47        }
48    }
49}
50
51#[derive(Parser, Debug)]
52pub enum RescueSubcommand {
53    ChunkRecover(RescueChunkRecoverCommand),
54    SuperRecover(RescueSuperRecoverCommand),
55    ZeroLog(RescueZeroLogCommand),
56    FixDeviceSize(RescueFixDeviceSizeCommand),
57    FixDataChecksum(RescueFixDataChecksumCommand),
58    CreateControlDevice(RescueCreateControlDeviceCommand),
59    ClearInoCache(RescueClearInoCacheCommand),
60    ClearSpaceCache(RescueClearSpaceCacheCommand),
61    ClearUuidTree(RescueClearUuidTreeCommand),
62}