scirs2_core/resource/
storage.rs

1//! # Storage Detection and Capabilities
2//!
3//! This module provides storage device detection for I/O optimization.
4
5use crate::error::CoreResult;
6
7/// Storage device information
8#[derive(Debug, Clone)]
9pub struct StorageInfo {
10    /// Storage devices
11    pub devices: Vec<StorageDevice>,
12    /// Optimal I/O size in bytes
13    pub optimal_io_size: usize,
14    /// Queue depth
15    pub queue_depth: usize,
16    /// Total capacity
17    pub capacity: usize,
18    /// Available space
19    pub available: usize,
20}
21
22impl Default for StorageInfo {
23    fn default() -> Self {
24        Self {
25            devices: vec![StorageDevice::default()],
26            optimal_io_size: 64 * 1024, // 64KB
27            queue_depth: 32,
28            capacity: 500 * 1024 * 1024 * 1024,  // 500GB
29            available: 250 * 1024 * 1024 * 1024, // 250GB
30        }
31    }
32}
33
34impl StorageInfo {
35    /// Detect storage information
36    pub fn detect() -> CoreResult<Self> {
37        // Simplified implementation
38        Ok(Self::default())
39    }
40
41    /// Check if storage supports async I/O
42    pub fn supports_async_io(&self) -> bool {
43        self.devices.iter().any(|d| d.supports_async)
44    }
45
46    /// Check if primary storage is SSD
47    pub fn is_ssd(&self) -> bool {
48        self.devices.first().map(|d| d.is_ssd).unwrap_or(false)
49    }
50}
51
52/// Storage device information
53#[derive(Debug, Clone)]
54pub struct StorageDevice {
55    /// Device name
56    pub name: String,
57    /// Device type
58    pub device_type: StorageType,
59    /// Is SSD (vs HDD)
60    pub is_ssd: bool,
61    /// Supports async I/O
62    pub supports_async: bool,
63    /// Device capacity
64    pub capacity: usize,
65    /// Optimal I/O size
66    pub optimal_io_size: usize,
67}
68
69impl Default for StorageDevice {
70    fn default() -> Self {
71        Self {
72            name: "sda".to_string(),
73            device_type: StorageType::Ssd,
74            is_ssd: true,
75            supports_async: true,
76            capacity: 500 * 1024 * 1024 * 1024, // 500GB
77            optimal_io_size: 64 * 1024,         // 64KB
78        }
79    }
80}
81
82/// Storage device types
83#[derive(Debug, Clone, Copy, PartialEq, Eq)]
84pub enum StorageType {
85    /// Hard Disk Drive
86    Hdd,
87    /// Solid State Drive
88    Ssd,
89    /// NVMe SSD
90    Nvme,
91    /// Network attached storage
92    Network,
93    /// RAM disk
94    Ram,
95    /// Unknown
96    Unknown,
97}