Skip to main content

btrfs_cli/
check.rs

1use crate::{Format, Runnable};
2use anyhow::Result;
3use clap::Parser;
4use std::path::PathBuf;
5
6/// Check mode for filesystem verification
7#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
8pub enum CheckMode {
9    Original,
10    Lowmem,
11}
12
13/// Check structural integrity of a filesystem (unmounted).
14///
15/// Verify the integrity of a btrfs filesystem by checking internal structures,
16/// extent trees, and data checksums. The filesystem must be unmounted before
17/// running this command. This is a potentially slow operation that requires
18/// CAP_SYS_ADMIN. Use --readonly to perform checks without attempting repairs.
19#[derive(Parser, Debug)]
20pub struct CheckCommand {
21    /// Path to the device containing the btrfs filesystem
22    device: PathBuf,
23
24    /// Use this superblock copy
25    #[clap(short = 's', long = "super")]
26    superblock: Option<u64>,
27
28    /// Use the first valid backup root copy
29    #[clap(short = 'b', long)]
30    backup: bool,
31
32    /// Use the given bytenr for the tree root
33    #[clap(short = 'r', long)]
34    tree_root: Option<u64>,
35
36    /// Use the given bytenr for the chunk tree root
37    #[clap(long)]
38    chunk_root: Option<u64>,
39
40    /// Run in read-only mode (default)
41    #[clap(long)]
42    readonly: bool,
43
44    /// Try to repair the filesystem (dangerous)
45    #[clap(long)]
46    repair: bool,
47
48    /// Skip mount checks
49    #[clap(long)]
50    force: bool,
51
52    /// Checker operating mode
53    #[clap(long)]
54    mode: Option<CheckMode>,
55
56    /// Create a new CRC tree
57    #[clap(long)]
58    init_csum_tree: bool,
59
60    /// Create a new extent tree
61    #[clap(long)]
62    init_extent_tree: bool,
63
64    /// Verify checksums of data blocks
65    #[clap(long)]
66    check_data_csum: bool,
67
68    /// Print a report on qgroup consistency
69    #[clap(short = 'Q', long)]
70    qgroup_report: bool,
71
72    /// Print subvolume extents and sharing state for the given subvolume ID
73    #[clap(short = 'E', long)]
74    subvol_extents: Option<u64>,
75
76    /// Indicate progress
77    #[clap(short = 'p', long)]
78    progress: bool,
79}
80
81impl Runnable for CheckCommand {
82    fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
83        todo!("implement check")
84    }
85}