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)]
28#[allow(clippy::doc_markdown)]
29pub struct RescueCommand {
30    #[clap(subcommand)]
31    pub subcommand: RescueSubcommand,
32}
33
34impl Runnable for RescueCommand {
35    fn run(&self, format: Format, dry_run: bool) -> Result<()> {
36        match &self.subcommand {
37            RescueSubcommand::ChunkRecover(cmd) => cmd.run(format, dry_run),
38            RescueSubcommand::SuperRecover(cmd) => cmd.run(format, dry_run),
39            RescueSubcommand::ZeroLog(cmd) => cmd.run(format, dry_run),
40            RescueSubcommand::FixDeviceSize(cmd) => cmd.run(format, dry_run),
41            RescueSubcommand::FixDataChecksum(cmd) => cmd.run(format, dry_run),
42            RescueSubcommand::CreateControlDevice(cmd) => {
43                cmd.run(format, dry_run)
44            }
45            RescueSubcommand::ClearInoCache(cmd) => cmd.run(format, dry_run),
46            RescueSubcommand::ClearSpaceCache(cmd) => cmd.run(format, dry_run),
47            RescueSubcommand::ClearUuidTree(cmd) => cmd.run(format, dry_run),
48        }
49    }
50}
51
52#[derive(Parser, Debug)]
53pub enum RescueSubcommand {
54    ChunkRecover(RescueChunkRecoverCommand),
55    SuperRecover(RescueSuperRecoverCommand),
56    ZeroLog(RescueZeroLogCommand),
57    FixDeviceSize(RescueFixDeviceSizeCommand),
58    FixDataChecksum(RescueFixDataChecksumCommand),
59    CreateControlDevice(RescueCreateControlDeviceCommand),
60    ClearInoCache(RescueClearInoCacheCommand),
61    ClearSpaceCache(RescueClearSpaceCacheCommand),
62    ClearUuidTree(RescueClearUuidTreeCommand),
63}