@@ -75,13 +75,19 @@ impl Default for Block {
7575
7676/// A block device - a device which can read and write blocks (or
7777/// sectors). Only supports devices which are <= 2 TiB in size.
78+ #[ allow( async_fn_in_trait) ]
79+ #[ maybe_async:: maybe_async( AFIT ) ]
7880pub trait BlockDevice {
7981 /// The errors that the `BlockDevice` can return. Must be debug formattable.
8082 type Error : core:: fmt:: Debug ;
8183 /// Read one or more blocks, starting at the given block index.
82- fn read ( & self , blocks : & mut [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > ;
84+ async fn read (
85+ & self ,
86+ blocks : & mut [ Block ] ,
87+ start_block_idx : BlockIdx ,
88+ ) -> Result < ( ) , Self :: Error > ;
8389 /// Write one or more blocks, starting at the given block index.
84- fn write ( & self , blocks : & [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > ;
90+ async fn write ( & self , blocks : & [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > ;
8591 /// Determine how many blocks this device can hold.
8692 fn num_blocks ( & self ) -> Result < BlockCount , Self :: Error > ;
8793}
@@ -110,31 +116,36 @@ where
110116 }
111117
112118 /// Read a block, and return a reference to it.
113- pub fn read ( & mut self , block_idx : BlockIdx ) -> Result < & Block , D :: Error > {
119+ #[ maybe_async:: maybe_async]
120+ pub async fn read ( & mut self , block_idx : BlockIdx ) -> Result < & Block , D :: Error > {
114121 if self . block_idx != Some ( block_idx) {
115122 self . block_idx = None ;
116- self . block_device . read ( & mut self . block , block_idx) ?;
123+ self . block_device . read ( & mut self . block , block_idx) . await ?;
117124 self . block_idx = Some ( block_idx) ;
118125 }
119126 Ok ( & self . block [ 0 ] )
120127 }
121128
122129 /// Read a block, and return a reference to it.
123- pub fn read_mut ( & mut self , block_idx : BlockIdx ) -> Result < & mut Block , D :: Error > {
130+ #[ maybe_async:: maybe_async]
131+ pub async fn read_mut ( & mut self , block_idx : BlockIdx ) -> Result < & mut Block , D :: Error > {
124132 if self . block_idx != Some ( block_idx) {
125133 self . block_idx = None ;
126- self . block_device . read ( & mut self . block , block_idx) ?;
134+ self . block_device . read ( & mut self . block , block_idx) . await ?;
127135 self . block_idx = Some ( block_idx) ;
128136 }
129137 Ok ( & mut self . block [ 0 ] )
130138 }
131139
132140 /// Write back a block you read with [`Self::read_mut`] and then modified.
133- pub fn write_back ( & mut self ) -> Result < ( ) , D :: Error > {
134- self . block_device . write (
135- & self . block ,
136- self . block_idx . expect ( "write_back with no read" ) ,
137- )
141+ #[ maybe_async:: maybe_async]
142+ pub async fn write_back ( & mut self ) -> Result < ( ) , D :: Error > {
143+ self . block_device
144+ . write (
145+ & self . block ,
146+ self . block_idx . expect ( "write_back with no read" ) ,
147+ )
148+ . await
138149 }
139150
140151 /// Access a blank sector
0 commit comments