File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -53,3 +53,32 @@ pub trait Storage: ReadStorage {
5353 /// and might as such do RMW operations at an undesirable performance impact.
5454 fn write ( & mut self , offset : u32 , bytes : & [ u8 ] ) -> Result < ( ) , Self :: Error > ;
5555}
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
76+ /// `block_count`.
77+ fn read ( & mut self , first_block_index : u64 , blocks : & mut [ Block ] ) -> Result < ( ) , Self :: Error > ;
78+
79+ /// Writes some number of blocks to the device, starting at `first_block_index`.
80+ ///
81+ /// `first_block_index + blocks.len()` must not be greater than the size returned by
82+ /// `block_count`.
83+ fn write ( & mut self , first_block_index : u64 , blocks : & [ Block ] ) -> Result < ( ) , Self :: Error > ;
84+ }
You can’t perform that action at this time.
0 commit comments