Skip to main content

disk_core/
fsck.rs

1//! Shared filesystem check (fsck) and repair types.
2//!
3//! These types are filesystem-agnostic. Each filesystem's fsck module
4//! (e.g. `hfs_fsck`) produces results using these shared types so the
5//! GUI and trait layer don't need filesystem-specific knowledge.
6//!
7//! All types carry `serde::Serialize` derives so `rb-cli fsck --format
8//! json|yaml` (and any future structured GUI / API export) can emit the
9//! result envelope without per-call shim types.
10
11use serde::Serialize;
12
13/// Result of a filesystem integrity check.
14#[derive(Debug, Serialize)]
15pub struct FsckResult {
16    /// Errors that indicate data corruption or inconsistency.
17    pub errors: Vec<FsckIssue>,
18    /// Non-critical issues that don't prevent normal operation.
19    pub warnings: Vec<FsckIssue>,
20    /// Aggregate statistics from the check.
21    pub stats: FsckStats,
22    /// True when at least one error can be automatically repaired.
23    pub repairable: bool,
24    /// Files and directories whose parent directory is missing from the catalog.
25    /// These represent unrepairable structural corruption.
26    pub orphaned_entries: Vec<OrphanedEntry>,
27}
28
29impl FsckResult {
30    /// Returns true if no errors were found (warnings are tolerated).
31    pub fn is_clean(&self) -> bool {
32        self.errors.is_empty()
33    }
34}
35
36/// A single issue found during the check.
37#[derive(Debug, Serialize)]
38pub struct FsckIssue {
39    /// Short identifier for the issue type (e.g. "BadSignature", "MissingParent").
40    pub code: String,
41    /// Human-readable description of the issue.
42    pub message: String,
43    /// Whether this issue can be automatically repaired.
44    pub repairable: bool,
45    /// Debug-level issue: only shown when debug output is enabled.
46    /// These are cosmetic/harmless findings (e.g. tiny wasted space).
47    pub debug: bool,
48}
49
50/// Aggregate statistics from a filesystem check.
51#[derive(Debug, Serialize)]
52pub struct FsckStats {
53    pub files_checked: u32,
54    pub directories_checked: u32,
55    /// Filesystem-specific extra statistics (label, value).
56    pub extra: Vec<(String, String)>,
57}
58
59/// A file or directory whose parent directory is missing.
60#[derive(Debug, Serialize)]
61pub struct OrphanedEntry {
62    /// Filesystem ID of the orphaned entry (e.g. CNID for HFS, inode for ext).
63    pub id: u64,
64    /// Name of the entry (decoded to UTF-8).
65    pub name: String,
66    /// Whether this is a directory (true) or file (false).
67    pub is_directory: bool,
68    /// The missing parent's filesystem ID.
69    pub missing_parent_id: u64,
70}
71
72/// Report from a repair operation.
73#[derive(Debug, Serialize)]
74pub struct RepairReport {
75    /// Descriptions of successfully applied fixes.
76    pub fixes_applied: Vec<String>,
77    /// Descriptions of fixes that were attempted but failed.
78    pub fixes_failed: Vec<String>,
79    /// Number of errors that cannot be repaired (e.g. missing parent directories).
80    pub unrepairable_count: usize,
81}