thoughts_tool/mount/
types.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use std::path::PathBuf;
4use std::time::SystemTime;
5
6use crate::platform::common::MAX_MOUNT_RETRIES;
7
8/// Information about an active mount
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct MountInfo {
11    /// Target mount point
12    pub target: PathBuf,
13
14    /// Source directories being merged
15    pub sources: Vec<PathBuf>,
16
17    /// Mount status
18    pub status: MountStatus,
19
20    /// Filesystem type (e.g., "fuse.mergerfs")
21    pub fs_type: String,
22
23    /// Mount options used
24    pub options: Vec<String>,
25
26    /// When the mount was created
27    pub mounted_at: Option<SystemTime>,
28
29    /// Process ID of the mount process (if applicable)
30    pub pid: Option<u32>,
31
32    /// Additional platform-specific metadata
33    pub metadata: MountMetadata,
34}
35
36/// Mount status
37#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
38pub enum MountStatus {
39    /// Successfully mounted and accessible
40    Mounted,
41
42    /// Not currently mounted
43    Unmounted,
44
45    /// Mount exists but may have issues
46    Degraded(String),
47
48    /// Mount failed with error
49    Error(String),
50
51    /// Status cannot be determined
52    Unknown,
53}
54
55/// Platform-specific mount metadata
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub enum MountMetadata {
58    Linux {
59        mount_id: Option<u32>,
60        parent_id: Option<u32>,
61        major_minor: Option<String>,
62    },
63    MacOS {
64        volume_name: Option<String>,
65        volume_uuid: Option<String>,
66        disk_identifier: Option<String>,
67    },
68    Unknown,
69}
70
71/// Options for mount operations
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct MountOptions {
74    /// Read-only mount
75    pub read_only: bool,
76
77    /// Allow other users to access the mount
78    pub allow_other: bool,
79
80    /// Custom volume name (macOS)
81    pub volume_name: Option<String>,
82
83    /// Additional platform-specific options
84    pub extra_options: Vec<String>,
85
86    /// Timeout for mount operation
87    pub timeout: Option<std::time::Duration>,
88
89    /// Number of retries on failure
90    pub retries: u32,
91}
92
93impl Default for MountOptions {
94    fn default() -> Self {
95        Self {
96            read_only: false,
97            allow_other: false,
98            volume_name: None,
99            extra_options: Vec::new(),
100            timeout: None,
101            retries: MAX_MOUNT_RETRIES,
102        }
103    }
104}
105
106/// Mount state cache for persistence (macOS FUSE-T)
107#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct MountStateCache {
109    pub version: String,
110    pub mounts: HashMap<PathBuf, CachedMountInfo>,
111}
112
113/// Cached information about a mount
114#[derive(Debug, Clone, Serialize, Deserialize)]
115pub struct CachedMountInfo {
116    pub target: PathBuf,
117    pub sources: Vec<PathBuf>,
118    pub mount_options: MountOptions,
119    pub created_at: SystemTime,
120    pub mount_command: String,
121    pub pid: Option<u32>,
122}
123
124#[cfg(test)]
125mod tests {
126    use super::*;
127
128    #[test]
129    fn test_mount_options_default() {
130        let options = MountOptions::default();
131
132        assert!(!options.read_only);
133        assert!(!options.allow_other);
134        assert_eq!(options.retries, MAX_MOUNT_RETRIES);
135        assert_eq!(options.volume_name, None);
136    }
137
138    #[test]
139    fn test_mount_status_serialization() {
140        let status = MountStatus::Mounted;
141        let json = serde_json::to_string(&status).unwrap();
142        let deserialized: MountStatus = serde_json::from_str(&json).unwrap();
143        assert_eq!(status, deserialized);
144    }
145}