use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum PartitionScheme {
Mbr,
Gpt,
None,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum FileSystem {
Ntfs,
Fat,
Ext2,
Ext3,
Ext4,
Xfs,
Btrfs,
LinuxSwap,
Lvm2,
Unknown,
}
impl FileSystem {
pub fn is_linux(&self) -> bool {
matches!(
self,
FileSystem::Ext2
| FileSystem::Ext3
| FileSystem::Ext4
| FileSystem::Xfs
| FileSystem::Btrfs
| FileSystem::LinuxSwap
| FileSystem::Lvm2
)
}
pub fn name(&self) -> &'static str {
match self {
FileSystem::Ntfs => "NTFS",
FileSystem::Fat => "FAT",
FileSystem::Ext2 => "ext2",
FileSystem::Ext3 => "ext3",
FileSystem::Ext4 => "ext4",
FileSystem::Xfs => "XFS",
FileSystem::Btrfs => "Btrfs",
FileSystem::LinuxSwap => "Linux swap",
FileSystem::Lvm2 => "LVM2 PV",
FileSystem::Unknown => "unknown",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OperatingSystem {
Windows,
Linux,
Unknown,
}
impl OperatingSystem {
pub fn icon(&self) -> &'static str {
match self {
OperatingSystem::Windows => "🪟",
OperatingSystem::Linux => "🐧",
OperatingSystem::Unknown => "❓",
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Partition {
pub index: usize,
pub start: u64,
pub size: u64,
pub kind: String,
pub file_system: FileSystem,
pub label: Option<String>,
}
impl Partition {
pub fn is_ntfs(&self) -> bool {
matches!(self.file_system, FileSystem::Ntfs)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_file_system() {
assert!(FileSystem::Ext4.is_linux());
assert!(!FileSystem::Ntfs.is_linux());
assert_eq!(FileSystem::Ntfs.name(), "NTFS");
}
}