scirs2_core/resource/
storage.rs1use crate::error::CoreResult;
6
7#[derive(Debug, Clone)]
9pub struct StorageInfo {
10 pub devices: Vec<StorageDevice>,
12 pub optimal_io_size: usize,
14 pub queue_depth: usize,
16 pub capacity: usize,
18 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, queue_depth: 32,
28 capacity: 500 * 1024 * 1024 * 1024, available: 250 * 1024 * 1024 * 1024, }
31 }
32}
33
34impl StorageInfo {
35 pub fn detect() -> CoreResult<Self> {
37 Ok(Self::default())
39 }
40
41 pub fn supports_async_io(&self) -> bool {
43 self.devices.iter().any(|d| d.supports_async)
44 }
45
46 pub fn is_ssd(&self) -> bool {
48 self.devices.first().map(|d| d.is_ssd).unwrap_or(false)
49 }
50}
51
52#[derive(Debug, Clone)]
54pub struct StorageDevice {
55 pub name: String,
57 pub device_type: StorageType,
59 pub is_ssd: bool,
61 pub supports_async: bool,
63 pub capacity: usize,
65 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, optimal_io_size: 64 * 1024, }
79 }
80}
81
82#[derive(Debug, Clone, Copy, PartialEq, Eq)]
84pub enum StorageType {
85 Hdd,
87 Ssd,
89 Nvme,
91 Network,
93 Ram,
95 Unknown,
97}