@@ -9,7 +9,7 @@ use std::{
99 path:: { Path , PathBuf } ,
1010} ;
1111
12- use crate :: { mmc, nvme, partition:: Partition , scsi, sysfs, virt, DEVFS_DIR } ;
12+ use crate :: { mmc, mock , nvme, partition:: Partition , scsi, sysfs, virt, DEVFS_DIR } ;
1313
1414/// Represents the type of disk device.
1515#[ derive( Debug ) ]
@@ -22,6 +22,8 @@ pub enum Disk {
2222 Nvme ( nvme:: Disk ) ,
2323 /// Virtual disk device
2424 Virtual ( virt:: Disk ) ,
25+ /// Mock disk for testing
26+ Mock ( mock:: MockDisk ) ,
2527}
2628
2729impl Deref for Disk {
@@ -34,26 +36,27 @@ impl Deref for Disk {
3436 Disk :: Nvme ( disk) => disk,
3537 Disk :: Scsi ( disk) => disk,
3638 Disk :: Virtual ( disk) => disk,
39+ Disk :: Mock ( disk) => disk,
3740 }
3841 }
3942}
4043
4144/// A basic disk representation containing common attributes shared by all disk types.
4245/// This serves as the base structure that specific disk implementations build upon.
43- #[ derive( Debug ) ]
46+ #[ derive( Debug , Default ) ]
4447pub struct BasicDisk {
4548 /// Device name (e.g. sda, nvme0n1)
46- name : String ,
49+ pub ( crate ) name : String ,
4750 /// Total number of sectors on the disk
48- sectors : u64 ,
51+ pub ( crate ) sectors : u64 ,
4952 /// Path to the device in /dev
50- device : PathBuf ,
53+ pub ( crate ) device : PathBuf ,
5154 /// Optional disk model name
52- model : Option < String > ,
55+ pub ( crate ) model : Option < String > ,
5356 /// Optional disk vendor name
54- vendor : Option < String > ,
57+ pub ( crate ) vendor : Option < String > ,
5558 /// Partitions
56- partitions : Vec < Partition > ,
59+ pub ( crate ) partitions : Vec < Partition > ,
5760}
5861
5962impl fmt:: Display for Disk {
@@ -93,6 +96,11 @@ impl BasicDisk {
9396 & self . partitions
9497 }
9598
99+ /// Helper for MockDisk to modify partitions
100+ pub ( crate ) fn partitions_mut ( & mut self ) -> & mut Vec < Partition > {
101+ & mut self . partitions
102+ }
103+
96104 /// Returns the path to the disk device in dev.
97105 pub fn device_path ( & self ) -> & Path {
98106 & self . device
0 commit comments