thoughts_tool/mount/
types.rs1use 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#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct MountInfo {
11 pub target: PathBuf,
13
14 pub sources: Vec<PathBuf>,
16
17 pub status: MountStatus,
19
20 pub fs_type: String,
22
23 pub options: Vec<String>,
25
26 pub mounted_at: Option<SystemTime>,
28
29 pub pid: Option<u32>,
31
32 pub metadata: MountMetadata,
34}
35
36#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
38pub enum MountStatus {
39 Mounted,
41
42 Unmounted,
44
45 Degraded(String),
47
48 Error(String),
50
51 Unknown,
53}
54
55#[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#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct MountOptions {
74 pub read_only: bool,
76
77 pub allow_other: bool,
79
80 pub volume_name: Option<String>,
82
83 pub extra_options: Vec<String>,
85
86 pub timeout: Option<std::time::Duration>,
88
89 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#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct MountStateCache {
109 pub version: String,
110 pub mounts: HashMap<PathBuf, CachedMountInfo>,
111}
112
113#[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}