@@ -53,3 +53,30 @@ pub trait Storage: ReadStorage {
53
53
/// and might as such do RMW operations at an undesirable performance impact.
54
54
fn write ( & mut self , offset : u32 , bytes : & [ u8 ] ) -> Result < ( ) , Self :: Error > ;
55
55
}
56
+
57
+ /// The size in bytes of a single block read or written by a [`BlockDevice`].
58
+ pub const BLOCK_SIZE : usize = 512 ;
59
+
60
+ /// A single block which may be read or written by a [`BlockDevice`].
61
+ ///
62
+ /// Also referred to as a sector in some contexts.
63
+ pub type Block = [ u8 ; BLOCK_SIZE ] ;
64
+
65
+ /// A device which can read and write whole numbers of blocks.
66
+ pub trait BlockDevice {
67
+ /// The error type returned by methods on this trait.
68
+ type Error ;
69
+
70
+ /// Returns the size of the device in blocks.
71
+ fn block_count ( & self ) -> Result < usize , Self :: Error > ;
72
+
73
+ /// Reads some number of blocks from the device, starting at `first_block_index`.
74
+ ///
75
+ /// `first_block_index + blocks.len()` must not be greater than the size returned by `block_count`.
76
+ fn read ( & mut self , first_block_index : u64 , blocks : & mut [ Block ] ) -> Result < ( ) , Self :: Error > ;
77
+
78
+ /// Writes some number of blocks to the device, starting at `first_block_index`.
79
+ ///
80
+ /// `first_block_index + blocks.len()` must not be greater than the size returned by `block_count`.
81
+ fn write ( & mut self , first_block_index : u64 , blocks : & [ Block ] ) -> Result < ( ) , Self :: Error > ;
82
+ }
0 commit comments